diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-06-23 10:03:27 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-07-06 10:41:16 +0200 |
commit | b94657a554ab25cf38c2306bcc95d02fc03e2e7c (patch) | |
tree | 1c10cc87120de4e8b8e66fa9e5ee1087042e18e0 | |
parent | e0bf1e4f6e1ab1cfb8e91eccfebd854d1e38d410 (diff) | |
download | nextcloud-server-b94657a554ab25cf38c2306bcc95d02fc03e2e7c.tar.gz nextcloud-server-b94657a554ab25cf38c2306bcc95d02fc03e2e7c.zip |
[updater] propagate error case properly
* add $success to the updateEnd hook
* add new return code for a update failure
* add exception class to failure hook message
-rw-r--r-- | core/command/upgrade.php | 17 | ||||
-rw-r--r-- | lib/private/updater.php | 8 |
2 files changed, 18 insertions, 7 deletions
diff --git a/core/command/upgrade.php b/core/command/upgrade.php index a4a5be21096..09413865952 100644 --- a/core/command/upgrade.php +++ b/core/command/upgrade.php @@ -22,8 +22,7 @@ class Upgrade extends Command { const ERROR_MAINTENANCE_MODE = 2; const ERROR_UP_TO_DATE = 3; const ERROR_INVALID_ARGUMENTS = 4; - - public $upgradeFailed = false; + const ERROR_FAILURE = 5; /** * @var IConfig @@ -105,10 +104,13 @@ class Upgrade extends Command { $output->writeln('<info>Turned on maintenance mode</info>'); }); $updater->listen('\OC\Updater', 'maintenanceEnd', - function () use($output, $updateStepEnabled, $self) { + function () use($output) { $output->writeln('<info>Turned off maintenance mode</info>'); + }); + $updater->listen('\OC\Updater', 'updateEnd', + function ($success) use($output, $updateStepEnabled, $self) { $mode = $updateStepEnabled ? 'Update' : 'Update simulation'; - $status = $self->upgradeFailed ? 'failed' : 'successful'; + $status = $success ? 'successful' : 'failed' ; $message = "<info>$mode $status</info>"; $output->writeln($message); }); @@ -138,13 +140,16 @@ class Upgrade extends Command { }); $updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) { $output->writeln("<error>$message</error>"); - $self->upgradeFailed = true; }); - $updater->upgrade(); + $success = $updater->upgrade(); $this->postUpgradeCheck($input, $output); + if(!$success) { + return self::ERROR_FAILURE; + } + return self::ERROR_SUCCESS; } else if($this->config->getSystemValue('maintenance', false)) { //Possible scenario: ownCloud core is updated but an app failed diff --git a/lib/private/updater.php b/lib/private/updater.php index d28060c100a..4d2f3ab7d75 100644 --- a/lib/private/updater.php +++ b/lib/private/updater.php @@ -159,14 +159,20 @@ class Updater extends BasicEmitter { } $this->emit('\OC\Updater', 'maintenanceStart'); + $success = true; try { $this->doUpgrade($currentVersion, $installedVersion); } catch (\Exception $exception) { - $this->emit('\OC\Updater', 'failure', array($exception->getMessage())); + \OCP\Util::logException('update', $exception); + $this->emit('\OC\Updater', 'failure', array(get_class($exception) . ': ' .$exception->getMessage())); + $success = false; } $this->config->setSystemValue('maintenance', false); $this->emit('\OC\Updater', 'maintenanceEnd'); + $this->emit('\OC\Updater', 'updateEnd', array($success)); + + return $success; } /** |