diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-12-07 13:17:30 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2016-12-07 15:05:08 +0300 |
commit | 4858b8fd322a228cba2efab35488085ec407efc9 (patch) | |
tree | 04dba8c91925c2ed77e1d3d24e064f1fa8bd76cf | |
parent | 49b1843146a76f8509f505be445d593eabf3f000 (diff) |
Check if update should be run based on updater server response1.0.3
* see #53
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
-rw-r--r-- | Changelog.md | 5 | ||||
-rw-r--r-- | index.php | 6 | ||||
-rw-r--r-- | lib/UpdateCommand.php | 20 | ||||
-rw-r--r-- | lib/Updater.php | 6 | ||||
-rw-r--r-- | tests/features/bootstrap/FeatureContext.php | 13 | ||||
-rw-r--r-- | tests/features/cli.feature | 8 |
6 files changed, 47 insertions, 11 deletions
diff --git a/Changelog.md b/Changelog.md index b12907f..f12113f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,8 @@ +# 1.0.3 - 2016-12-07 + +- general: send PHP version to get compatible updates +- CLI: check if update should be run based on updater server response + # 1.0.2 - 2016-11-28 - CLI: verify that owner of config.php and updater process user are the same @@ -236,6 +236,12 @@ class Updater { $updateText = 'No update available.'; } + if ($this->updateAvailable && isset($response['autoupdater']) && !($response['autoupdater'] === 1 || $response['autoupdater'] === '1')) { + $this->updateAvailable = false; + + $updateText .= '<br />The updater is disabled for this update - please update manually.' . $response['autoupdater']; + } + $this->silentLog('[info] end of checkForUpdate() ' . $updateText); return $updateText; } diff --git a/lib/UpdateCommand.php b/lib/UpdateCommand.php index 572d1e9..8bc4f74 100644 --- a/lib/UpdateCommand.php +++ b/lib/UpdateCommand.php @@ -139,20 +139,22 @@ class UpdateCommand extends Command { // needs to be called that early because otherwise updateAvailable() returns false $updateString = $this->updater->checkForUpdate(); - if(!$this->updater->updateAvailable() && $stepNumber === 0) { - $output->writeln('Everything is up to date.'); - return 0; - } - $output->writeln(''); - $indexOfBreak = strpos($updateString, '<br'); - $output->writeln('<info>' . substr($updateString, 0, $indexOfBreak) . '</info>'); - // strip HTML - $output->writeln(preg_replace('/<[^>]*>/', '', substr($updateString, $indexOfBreak))); + $lines = explode('<br />', $updateString); + + foreach ($lines as $line) { + // strip HTML + $output->writeln('<info>' . preg_replace('/<[^>]*>/', '', $line) . '</info>'); + } $output->writeln(''); + if(!$this->updater->updateAvailable() && $stepNumber === 0) { + $output->writeln('Nothing to do.'); + return 0; + } + $questionText = 'Start update'; if ($stepNumber > 0) { $questionText = 'Continue update'; diff --git a/lib/Updater.php b/lib/Updater.php index 14b9d3f..5cfa34a 100644 --- a/lib/Updater.php +++ b/lib/Updater.php @@ -121,6 +121,12 @@ class Updater { $updateText = 'No update available.'; } + if ($this->updateAvailable && isset($response['autoupdater']) && !($response['autoupdater'] === 1 || $response['autoupdater'] === '1')) { + $this->updateAvailable = false; + + $updateText .= '<br />The updater is disabled for this update - please update manually.' . $response['autoupdater']; + } + $this->silentLog('[info] end of checkForUpdate() ' . $updateText); return $updateText; } diff --git a/tests/features/bootstrap/FeatureContext.php b/tests/features/bootstrap/FeatureContext.php index 7d69c1a..0f05432 100644 --- a/tests/features/bootstrap/FeatureContext.php +++ b/tests/features/bootstrap/FeatureContext.php @@ -21,6 +21,8 @@ class FeatureContext implements Context protected $CLIOutput; /** @var integer */ protected $CLIReturnCode; + /** @var string */ + protected $autoupdater = '1'; public function __construct() { @@ -131,7 +133,14 @@ class FeatureContext implements Context $content = ''; file_put_contents($this->updateServerDir . 'index.php', $content); - } + } + + /** + * @Given the autoupdater is disabled + */ + public function theAutoupdaterIsDisabled() { + $this->autoupdater = '0'; + } /** * @When the CLI updater is run successfully @@ -178,7 +187,7 @@ class FeatureContext implements Context <versionstring>Nextcloud ' . $version . '</versionstring> <url>https://download.nextcloud.com/server/releases/nextcloud-' . $version . '.zip</url> <web>https://docs.nextcloud.org/server/10/admin_manual/maintenance/manual_upgrade.html</web> - <autoupdater>1</autoupdater> + <autoupdater>' . $this->autoupdater . '</autoupdater> </nextcloud> '; file_put_contents($this->updateServerDir . 'index.php', $content); diff --git a/tests/features/cli.feature b/tests/features/cli.feature index 491352f..0750a84 100644 --- a/tests/features/cli.feature +++ b/tests/features/cli.feature @@ -34,3 +34,11 @@ Feature: CLI updater #And maintenance mode should be off And upgrade is not required + Scenario: Update is available but autoupdate is disabled - 10.0.0 to 10.0.1 + Given the current installed version is 10.0.0 + And the autoupdater is disabled + And there is an update to version 10.0.1 available + When the CLI updater is run + Then the installed version should be 10.0.0 + And maintenance mode should be off + And upgrade is not required |