[Pkg-owncloud-commits] [owncloud] 18/58: [updater] propagate error case properly

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


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

taffit pushed a commit to annotated tag v8.0.6
in repository owncloud.

commit b94657a554ab25cf38c2306bcc95d02fc03e2e7c
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 | 17 +++++++++++------
 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 a4a5be2..0941386 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 d28060c..4d2f3ab 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;
 	}
 
 	/**

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