diff options
Diffstat (limited to 'core/ajax/update.php')
-rw-r--r-- | core/ajax/update.php | 121 |
1 files changed, 56 insertions, 65 deletions
diff --git a/core/ajax/update.php b/core/ajax/update.php index 39a99323cf5..56dffef409c 100644 --- a/core/ajax/update.php +++ b/core/ajax/update.php @@ -30,8 +30,19 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\IEventSource; +use OCP\IL10N; use OCP\ILogger; -use Symfony\Component\EventDispatcher\GenericEvent; +use OC\DB\MigratorExecuteSqlEvent; +use OC\Repair\Events\RepairAdvanceEvent; +use OC\Repair\Events\RepairErrorEvent; +use OC\Repair\Events\RepairFinishEvent; +use OC\Repair\Events\RepairInfoEvent; +use OC\Repair\Events\RepairStartEvent; +use OC\Repair\Events\RepairStepEvent; +use OC\Repair\Events\RepairWarningEvent; if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { @set_time_limit(0); @@ -48,57 +59,40 @@ $eventSource = \OC::$server->createEventSource(); $eventSource->send('success', $l->t('Preparing update')); class FeedBackHandler { - /** @var integer */ - private $progressStateMax = 100; - /** @var integer */ - private $progressStateStep = 0; - /** @var string */ - private $currentStep; - /** @var \OCP\IEventSource */ - private $eventSource; - /** @var \OCP\IL10N */ - private $l10n; - - public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { + private int $progressStateMax = 100; + private int $progressStateStep = 0; + private string $currentStep = ''; + private IEventSource $eventSource; + private IL10N $l10n; + + public function __construct(IEventSource $eventSource, 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', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); - break; - case '\OC\Repair::finishProgress': - $this->progressStateMax = $this->progressStateStep; - $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); - break; - case '\OC\Repair::step': - $this->eventSource->send('success', $this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); - break; - case '\OC\Repair::info': - $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); - break; - case '\OC\Repair::warning': - $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); - break; - case '\OC\Repair::error': - $this->eventSource->send('notice', $this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); - break; + public function handleRepairFeedback(Event $event): void { + if ($event instanceof RepairStartEvent) { + $this->progressStateMax = $event->getMaxStep(); + $this->progressStateStep = 0; + $this->currentStep = $event->getCurrentStepName(); + } elseif ($event instanceof RepairAdvanceEvent) { + $this->progressStateStep += $event->getIncrement(); + $desc = $event->getDescription(); + if (empty($desc)) { + $desc = $this->currentStep; + } + $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); + } elseif ($event instanceof RepairFinishEvent) { + $this->progressStateMax = $this->progressStateStep; + $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); + } elseif ($event instanceof RepairStepEvent) { + $this->eventSource->send('success', $this->l10n->t('Repair step:') . ' ' . $event->getStepName()); + } elseif ($event instanceof RepairInfoEvent) { + $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getMessage()); + } elseif ($event instanceof RepairWarningEvent) { + $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getMessage()); + } elseif ($event instanceof RepairErrorEvent) { + $this->eventSource->send('error', $this->l10n->t('Repair error:') . ' ' . $event->getMessage()); } } } @@ -125,25 +119,22 @@ if (\OCP\Util::needUpgrade()) { ); $incompatibleApps = []; - $dispatcher = \OC::$server->getEventDispatcher(); - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { - if ($event instanceof GenericEvent) { - $eventSource->send('success', $l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); + /** @var IEventDispatcher $dispatcher */ + $dispatcher = \OC::$server->get(IEventDispatcher::class); + $dispatcher->addListener( + MigratorExecuteSqlEvent::class, + function (MigratorExecuteSqlEvent $event) use ($eventSource, $l): void { + $eventSource->send('success', $l->t('[%d / %d]: %s', [$event->getCurrentStep(), $event->getMaxStep(), $event->getSql()])); } - }); - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { - if ($event instanceof GenericEvent) { - $eventSource->send('success', $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']); + $dispatcher->addListener(RepairStartEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairAdvanceEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairFinishEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairStepEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairInfoEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairWarningEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairErrorEvent::class, [$feedBack, 'handleRepairFeedback']); $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { $eventSource->send('success', $l->t('Turned on maintenance mode')); |