Unverified Commit 821d8736 authored by Thomas Müller's avatar Thomas Müller
Browse files

Adding progress to web upgrade

parent bbd2a075
......@@ -39,6 +39,56 @@ $eventSource = \OC::$server->createEventSource();
// message
$eventSource->send('success', (string)$l->t('Preparing update'));
class FeedBackHandler {
/** @var integer */
private $progressStateMax = 100;
/** @var integer */
private $progressStateStep = 0;
/** @var string */
private $currentStep;
public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) {
$this->eventSource = $eventSource;
$this->l10n = $l10n;
}
public function handleRepairFeedback($event) {
if (!$event instanceof GenericEvent) {
return;
}
switch ($event->getSubject()) {
case '\OC\Repair::startProgress':
$this->progressStateMax = $event->getArgument(0);
$this->progressStateStep = 0;
$this->currentStep = $event->getArgument(1);
break;
case '\OC\Repair::advance':
$this->progressStateStep += $event->getArgument(0);
$desc = $event->getArgument(1);
if (empty($desc)) {
$desc = $this->currentStep;
}
$this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc]));
break;
case '\OC\Repair::finishProgress':
$this->progressStateMax = $this->progressStateStep;
$this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep]));
break;
case '\OC\Repair::step':
break;
case '\OC\Repair::info':
break;
case '\OC\Repair::warning':
$this->eventSource->send('notice', (string)$this->l10n->t('Repair warning: ') . $event->getArgument(0));
break;
case '\OC\Repair::error':
$this->eventSource->send('notice', (string)$this->l10n->t('Repair error: ') . $event->getArgument(0));
break;
}
}
}
if (OC::checkUpgrade(false)) {
$config = \OC::$server->getSystemConfig();
......@@ -73,6 +123,14 @@ if (OC::checkUpgrade(false)) {
$eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()]));
}
});
$feedBack = new FeedBackHandler($eventSource, $l);
$dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']);
$dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']);
$dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']);
$dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']);
$dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']);
$dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']);
$dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']);
$updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) {
$eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
......@@ -107,12 +165,6 @@ if (OC::checkUpgrade(false)) {
$updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) {
$eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version)));
});
$updater->listen('\OC\Updater', 'repairWarning', function ($description) use ($eventSource, $l) {
$eventSource->send('notice', (string)$l->t('Repair warning: ') . $description);
});
$updater->listen('\OC\Updater', 'repairError', function ($description) use ($eventSource, $l) {
$eventSource->send('notice', (string)$l->t('Repair error: ') . $description);
});
$updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) {
$incompatibleApps[]= $app;
});
......
......@@ -61,7 +61,7 @@ class DropOldTables implements IRepairStep {
if ($this->connection->tableExists($tableName)){
$this->connection->dropTable($tableName);
}
$output->advance();
$output->advance(1, "Drop old database table: $tableName");
}
$output->finishProgress();
}
......
......@@ -55,6 +55,8 @@ class Repair implements IOutput{
private $repairSteps;
/** @var EventDispatcher */
private $dispatcher;
/** @var string */
private $currentStep;
/**
* Creates a new repair step runner
......@@ -78,7 +80,8 @@ class Repair implements IOutput{
}
// run each repair step
foreach ($this->repairSteps as $step) {
$this->emit('\OC\Repair', 'step', array($step->getName()));
$this->currentStep = $step->getName();
$this->emit('\OC\Repair', 'step', [$this->currentStep]);
if ($step instanceof Emitter) {
$step->listen('\OC\Repair', 'warning', function ($description) use ($self) {
......@@ -206,15 +209,16 @@ class Repair implements IOutput{
*/
public function startProgress($max = 0) {
// for now just emit as we did in the past
$this->emit('\OC\Repair', 'startProgress', [$max]);
$this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]);
}
/**
* @param int $step
* @param string $description
*/
public function advance($step = 1) {
public function advance($step = 1, $description = '') {
// for now just emit as we did in the past
$this->emit('\OC\Repair', 'advance', [$step]);
$this->emit('\OC\Repair', 'advance', [$step, $description]);
}
/**
......
......@@ -48,9 +48,10 @@ interface IOutput {
/**
* @param int $step
* @param string $description
* @since 9.1.0
*/
public function advance($step = 1);
public function advance($step = 1, $description = '');
/**
* @param int $max
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment