[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
This commit is contained in:
parent
fdd01cf15c
commit
fe42553e8a
|
@ -39,8 +39,7 @@ class Upgrade extends Command {
|
||||||
const ERROR_MAINTENANCE_MODE = 2;
|
const ERROR_MAINTENANCE_MODE = 2;
|
||||||
const ERROR_UP_TO_DATE = 3;
|
const ERROR_UP_TO_DATE = 3;
|
||||||
const ERROR_INVALID_ARGUMENTS = 4;
|
const ERROR_INVALID_ARGUMENTS = 4;
|
||||||
|
const ERROR_FAILURE = 5;
|
||||||
public $upgradeFailed = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var IConfig
|
* @var IConfig
|
||||||
|
@ -128,9 +127,9 @@ class Upgrade extends Command {
|
||||||
$output->writeln('<info>Maintenance mode is kept active</info>');
|
$output->writeln('<info>Maintenance mode is kept active</info>');
|
||||||
});
|
});
|
||||||
$updater->listen('\OC\Updater', 'updateEnd',
|
$updater->listen('\OC\Updater', 'updateEnd',
|
||||||
function () use($output, $updateStepEnabled, $self) {
|
function ($success) use($output, $updateStepEnabled, $self) {
|
||||||
$mode = $updateStepEnabled ? 'Update' : 'Update simulation';
|
$mode = $updateStepEnabled ? 'Update' : 'Update simulation';
|
||||||
$status = $self->upgradeFailed ? 'failed' : 'successful';
|
$status = $success ? 'successful' : 'failed' ;
|
||||||
$message = "<info>$mode $status</info>";
|
$message = "<info>$mode $status</info>";
|
||||||
$output->writeln($message);
|
$output->writeln($message);
|
||||||
});
|
});
|
||||||
|
@ -163,13 +162,16 @@ class Upgrade extends Command {
|
||||||
});
|
});
|
||||||
$updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) {
|
$updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) {
|
||||||
$output->writeln("<error>$message</error>");
|
$output->writeln("<error>$message</error>");
|
||||||
$self->upgradeFailed = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$updater->upgrade();
|
$success = $updater->upgrade();
|
||||||
|
|
||||||
$this->postUpgradeCheck($input, $output);
|
$this->postUpgradeCheck($input, $output);
|
||||||
|
|
||||||
|
if(!$success) {
|
||||||
|
return self::ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
return self::ERROR_SUCCESS;
|
return self::ERROR_SUCCESS;
|
||||||
} else if($this->config->getSystemValue('maintenance', false)) {
|
} else if($this->config->getSystemValue('maintenance', false)) {
|
||||||
//Possible scenario: ownCloud core is updated but an app failed
|
//Possible scenario: ownCloud core is updated but an app failed
|
||||||
|
|
|
@ -189,13 +189,16 @@ class Updater extends BasicEmitter {
|
||||||
$this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
|
$this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, array('app' => 'core'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$success = true;
|
||||||
try {
|
try {
|
||||||
$this->doUpgrade($currentVersion, $installedVersion);
|
$this->doUpgrade($currentVersion, $installedVersion);
|
||||||
} catch (\Exception $exception) {
|
} 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->emit('\OC\Updater', 'updateEnd');
|
$this->emit('\OC\Updater', 'updateEnd', array($success));
|
||||||
|
|
||||||
if(!$wasMaintenanceModeEnabled) {
|
if(!$wasMaintenanceModeEnabled) {
|
||||||
$this->config->setSystemValue('maintenance', false);
|
$this->config->setSystemValue('maintenance', false);
|
||||||
|
@ -203,6 +206,8 @@ class Updater extends BasicEmitter {
|
||||||
} else {
|
} else {
|
||||||
$this->emit('\OC\Updater', 'maintenanceActive');
|
$this->emit('\OC\Updater', 'maintenanceActive');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue