Skip to content

Commit

Permalink
Check if update should be run based on updater server response
Browse files Browse the repository at this point in the history
* see #53

Signed-off-by: Morris Jobke <[email protected]>
  • Loading branch information
MorrisJobke committed Dec 7, 2016
1 parent 49b1843 commit 4858b8f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ public function checkForUpdate() {
$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;
}
Expand Down
20 changes: 11 additions & 9 deletions lib/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,22 @@ protected function execute(InputInterface $input, OutputInterface $output) {
// 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';
Expand Down
6 changes: 6 additions & 0 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public function checkForUpdate() {
$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;
}
Expand Down
13 changes: 11 additions & 2 deletions tests/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class FeatureContext implements Context
protected $CLIOutput;
/** @var integer */
protected $CLIReturnCode;
/** @var string */
protected $autoupdater = '1';

public function __construct()
{
Expand Down Expand Up @@ -131,7 +133,14 @@ public function thereIsNoUpdateAvailable()

$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
Expand Down Expand Up @@ -178,7 +187,7 @@ public function thereIsAnUpdateToVersionAvailable($version)
<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);
Expand Down
8 changes: 8 additions & 0 deletions tests/features/cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4858b8f

Please sign in to comment.