From 821d8736c89eae3ad35c0ddc726a583b0c0cf99c Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Wed, 27 Apr 2016 12:21:31 +0200 Subject: Adding progress to web upgrade --- core/ajax/update.php | 64 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 6 deletions(-) (limited to 'core/ajax') diff --git a/core/ajax/update.php b/core/ajax/update.php index 0e6c1176ac1..f673467f64a 100644 --- a/core/ajax/update.php +++ b/core/ajax/update.php @@ -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; }); -- cgit v1.2.3