Check if update should be run based on updater server response

* see #53

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2016-12-07 11:17:30 +01:00
parent 49b1843146
commit 4858b8fd32
No known key found for this signature in database
GPG Key ID: 9CE5ED29E7FCD38A
6 changed files with 47 additions and 11 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -139,19 +139,21 @@ 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('');
$lines = explode('<br />', $updateString);
foreach ($lines as $line) {
// strip HTML
$output->writeln('<info>' . preg_replace('/<[^>]*>/', '', $line) . '</info>');
}
$output->writeln('');
$indexOfBreak = strpos($updateString, '<br');
$output->writeln('<info>' . substr($updateString, 0, $indexOfBreak) . '</info>');
// strip HTML
$output->writeln(preg_replace('/<[^>]*>/', '', substr($updateString, $indexOfBreak)));
$output->writeln('');
if(!$this->updater->updateAvailable() && $stepNumber === 0) {
$output->writeln('Nothing to do.');
return 0;
}
$questionText = 'Start update';
if ($stepNumber > 0) {

View File

@ -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;
}

View File

@ -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);

View File

@ -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