[Pkg-owncloud-commits] [owncloud] 03/20: [updater] propagate error case properly

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 15:57:44 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 917002f3ecc91b1d06a4ca126bbbf392cee1285f
Author: Morris Jobke <hey at morrisjobke.de>
Date:   Tue Jun 23 10:03:27 2015 +0200

    [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
---
 core/command/upgrade.php | 29 ++++++++++++++++++-----------
 lib/private/updater.php  |  8 +++++++-
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/core/command/upgrade.php b/core/command/upgrade.php
index 22f4293..456d924 100644
--- a/core/command/upgrade.php
+++ b/core/command/upgrade.php
@@ -21,6 +21,7 @@ class Upgrade extends Command {
 	const ERROR_MAINTENANCE_MODE = 2;
 	const ERROR_UP_TO_DATE = 3;
 	const ERROR_INVALID_ARGUMENTS = 4;
+	const ERROR_FAILURE = 5;
 
 	protected function configure() {
 		$this
@@ -83,15 +84,17 @@ class Upgrade extends Command {
 			$updater->listen('\OC\Updater', 'maintenanceStart', function () use($output) {
 				$output->writeln('<info>Turned on maintenance mode</info>');
 			});
-			$updater->listen('\OC\Updater', 'maintenanceEnd', function () use($output, $updateStepEnabled) {
-				$output->writeln('<info>Turned off maintenance mode</info>');
-				if (!$updateStepEnabled) {
-					$output->writeln('<info>Update simulation successful</info>');
-				}
-				else {
-					$output->writeln('<info>Update successful</info>');
-				}
-			});
+			$updater->listen('\OC\Updater', 'maintenanceEnd',
+				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 = $success ? 'successful' : 'failed' ;
+					$message = "<info>$mode $status</info>";
+					$output->writeln($message);
+				});
 			$updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
 				$output->writeln('<info>Updated database</info>');
 			});
@@ -106,14 +109,18 @@ class Upgrade extends Command {
 			});
 
 			$updater->listen('\OC\Updater', 'failure', function ($message) use($output) {
-				$output->writeln($message);
+				$output->writeln("<error>$message</error>");
 				\OC_Config::setValue('maintenance', false);
 			});
 
-			$updater->upgrade();
+			$success = $updater->upgrade();
 
 			$this->postUpgradeCheck($input, $output);
 
+			if(!$success) {
+				return self::ERROR_FAILURE;
+			}
+
 			return self::ERROR_SUCCESS;
 		} else if(\OC_Config::getValue('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 c6c2ad2..64f8dc3 100644
--- a/lib/private/updater.php
+++ b/lib/private/updater.php
@@ -136,14 +136,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;
 		}
 
 		\OC_Config::setValue('maintenance', false);
 		$this->emit('\OC\Updater', 'maintenanceEnd');
+		$this->emit('\OC\Updater', 'updateEnd', array($success));
+
+		return $success;
 	}
 
 	/**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list