aboutsummaryrefslogtreecommitdiffstats
path: root/core/ajax
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-08-22 17:59:26 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2022-08-25 16:15:48 +0200
commita2a7150d6d87a499e6745651edb27c9795939d0c (patch)
tree43c24a93b22268ec324ec30b2ef026ea09df1b4b /core/ajax
parenta83a8f0dde07bff67e0ceb7008cc26b3fad32516 (diff)
downloadnextcloud-server-a2a7150d6d87a499e6745651edb27c9795939d0c.tar.gz
nextcloud-server-a2a7150d6d87a499e6745651edb27c9795939d0c.zip
Migrate Repair events to OCP\EventDispatcher\Event
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'core/ajax')
-rw-r--r--core/ajax/update.php88
1 files changed, 41 insertions, 47 deletions
diff --git a/core/ajax/update.php b/core/ajax/update.php
index 653a594f069..105cedd05f2 100644
--- a/core/ajax/update.php
+++ b/core/ajax/update.php
@@ -30,12 +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 OC\DB\MigratorExecuteSqlEvent;
-use Symfony\Component\EventDispatcher\GenericEvent;
+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);
@@ -63,41 +70,29 @@ class FeedBackHandler {
$this->l10n = $l10n;
}
- public function handleRepairFeedback($event): void {
- if (!$event instanceof GenericEvent) {
- return;
- }
-
- switch ($event->getSubject()) {
- case '\OC\Repair::startProgress':
- $this->progressStateMax = $event->getArgument('max');
- $this->progressStateStep = 0;
- $this->currentStep = (string)$event->getArgument('step');
- break;
- case '\OC\Repair::advance':
- $this->progressStateStep += $event->getArgument('step');
- $desc = $event->getArgument('desc');
- 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('step'));
- break;
- case '\OC\Repair::info':
- $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getArgument('message'));
- break;
- case '\OC\Repair::warning':
- $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getArgument('message'));
- break;
- case '\OC\Repair::error':
- $this->eventSource->send('notice', $this->l10n->t('Repair error:') . ' ' . $event->getArgument('message'));
- 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->getCurrentStep();
+ $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('notice', $this->l10n->t('Repair error:') . ' ' . $event->getMessage());
}
}
}
@@ -124,20 +119,19 @@ if (\OCP\Util::needUpgrade()) {
);
$incompatibleApps = [];
- $dispatcher = \OC::$server->getEventDispatcher();
- /** @var IEventDispatcher $newDispatcher */
- $newDispatcher = \OC::$server->get(IEventDispatcher::class);
- $newDispatcher->addListener(MigratorExecuteSqlEvent::class, function (MigratorExecuteSqlEvent $event) use ($eventSource, $l) {
+ /** @var IEventDispatcher $dispatcher */
+ $dispatcher = \OC::$server->get(IEventDispatcher::class);
+ $dispatcher->addListener(MigratorExecuteSqlEvent::class, function (MigratorExecuteSqlEvent $event) use ($eventSource, $l) {
$eventSource->send('success', $l->t('[%d / %d]: %s', [$event->getCurrentStep(), $event->getMaxStep(), $event->getSql()]));
});
$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'));