aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Updater.php
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 /lib/private/Updater.php
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 'lib/private/Updater.php')
-rw-r--r--lib/private/Updater.php124
1 files changed, 46 insertions, 78 deletions
diff --git a/lib/private/Updater.php b/lib/private/Updater.php
index e63c158f7a2..889b54eec51 100644
--- a/lib/private/Updater.php
+++ b/lib/private/Updater.php
@@ -40,19 +40,28 @@ declare(strict_types=1);
*/
namespace OC;
+use OCP\App\IAppManager;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\HintException;
+use OCP\IConfig;
+use OCP\ILogger;
+use OCP\Util;
use OC\App\AppManager;
use OC\DB\Connection;
use OC\DB\MigrationService;
+use OC\DB\MigratorExecuteSqlEvent;
use OC\Hooks\BasicEmitter;
use OC\IntegrityCheck\Checker;
+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;
use OC_App;
-use OCP\App\IAppManager;
-use OCP\HintException;
-use OCP\IConfig;
-use OCP\ILogger;
-use OCP\Util;
use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class that handles autoupdating of ownCloud
@@ -102,7 +111,6 @@ class Updater extends BasicEmitter {
* @return bool true if the operation succeeded, false otherwise
*/
public function upgrade(): bool {
- $this->emitRepairEvents();
$this->logAllEvents();
$logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN);
@@ -248,7 +256,7 @@ class Updater extends BasicEmitter {
file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
// pre-upgrade repairs
- $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class));
+ $repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
$repair->run();
$this->doCoreUpgrade();
@@ -289,7 +297,7 @@ class Updater extends BasicEmitter {
}
// post-upgrade repairs
- $repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class));
+ $repair = new Repair(Repair::getRepairSteps(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
$repair->run();
//Invalidate update feed
@@ -432,87 +440,47 @@ class Updater extends BasicEmitter {
}
}
- /**
- * Forward messages emitted by the repair routine
- */
- private function emitRepairEvents(): void {
- $dispatcher = \OC::$server->getEventDispatcher();
- $dispatcher->addListener('\OC\Repair::warning', function ($event) {
- if ($event instanceof GenericEvent) {
- $this->emit('\OC\Updater', 'repairWarning', $event->getArguments());
- }
- });
- $dispatcher->addListener('\OC\Repair::error', function ($event) {
- if ($event instanceof GenericEvent) {
- $this->emit('\OC\Updater', 'repairError', $event->getArguments());
- }
- });
- $dispatcher->addListener('\OC\Repair::info', function ($event) {
- if ($event instanceof GenericEvent) {
- $this->emit('\OC\Updater', 'repairInfo', $event->getArguments());
- }
- });
- $dispatcher->addListener('\OC\Repair::step', function ($event) {
- if ($event instanceof GenericEvent) {
- $this->emit('\OC\Updater', 'repairStep', $event->getArguments());
- }
- });
- }
-
private function logAllEvents(): void {
$log = $this->log;
- $dispatcher = \OC::$server->getEventDispatcher();
- /** @var IEventDispatcher $newDispatcher */
- $newDispatcher = \OC::$server->get(IEventDispatcher::class);
- $newDispatcher->addListener(
+ /** @var IEventDispatcher $dispatcher */
+ $dispatcher = \OC::$server->get(IEventDispatcher::class);
+ $dispatcher->addListener(
MigratorExecuteSqlEvent::class,
function (MigratorExecuteSqlEvent $event) use ($log) {
$log->info(get_class($event).': ' . $event->getSql() . ' (' . $event->getCurrentStep() . ' of ' . $event->getMaxStep() . ')', ['app' => 'updater']);
}
);
- $repairListener = function ($event) use ($log) {
- if (!$event instanceof GenericEvent) {
- return;
- }
- switch ($event->getSubject()) {
- case '\OC\Repair::startProgress':
- $log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument('max') . ' (' . $event->getArgument('step') . ')', ['app' => 'updater']);
- break;
- case '\OC\Repair::advance':
- $desc = $event->getArgument('desc');
- if (empty($desc)) {
- $desc = '';
- }
- $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument('step') . ')', ['app' => 'updater']);
-
- break;
- case '\OC\Repair::finishProgress':
- $log->info('\OC\Repair::finishProgress', ['app' => 'updater']);
- break;
- case '\OC\Repair::step':
- $log->info('\OC\Repair::step: Repair step: ' . $event->getArgument('step'), ['app' => 'updater']);
- break;
- case '\OC\Repair::info':
- $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument('message'), ['app' => 'updater']);
- break;
- case '\OC\Repair::warning':
- $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument('message'), ['app' => 'updater']);
- break;
- case '\OC\Repair::error':
- $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument('message'), ['app' => 'updater']);
- break;
+ $repairListener = function (Event $event) use ($log) {
+ if ($event instanceof RepairStartEvent) {
+ $log->info(get_class($event).': Starting ... ' . $event->getMaxStep() . ' (' . $event->getCurrentStepName() . ')', ['app' => 'updater']);
+ } elseif ($event instanceof RepairAdvanceEvent) {
+ $desc = $event->getDescription();
+ if (empty($desc)) {
+ $desc = '';
+ }
+ $log->info(get_class($event).': ' . $desc . ' (' . $event->getCurrentStep() . ')', ['app' => 'updater']);
+ } elseif ($event instanceof RepairFinishEvent) {
+ $log->info(get_class($event), ['app' => 'updater']);
+ } elseif ($event instanceof RepairStepEvent) {
+ $log->info(get_class($event).': Repair step: ' . $event->getStepName(), ['app' => 'updater']);
+ } elseif ($event instanceof RepairInfoEvent) {
+ $log->info(get_class($event).': Repair info: ' . $event->getMessage(), ['app' => 'updater']);
+ } elseif ($event instanceof RepairWarningEvent) {
+ $log->warning(get_class($event).': Repair warning: ' . $event->getMessage(), ['app' => 'updater']);
+ } elseif ($event instanceof RepairErrorEvent) {
+ $log->error(get_class($event).': Repair error: ' . $event->getMessage(), ['app' => 'updater']);
}
};
- $dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
- $dispatcher->addListener('\OC\Repair::advance', $repairListener);
- $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
- $dispatcher->addListener('\OC\Repair::step', $repairListener);
- $dispatcher->addListener('\OC\Repair::info', $repairListener);
- $dispatcher->addListener('\OC\Repair::warning', $repairListener);
- $dispatcher->addListener('\OC\Repair::error', $repairListener);
+ $dispatcher->addListener(RepairStartEvent::class, $repairListener);
+ $dispatcher->addListener(RepairAdvanceEvent::class, $repairListener);
+ $dispatcher->addListener(RepairFinishEvent::class, $repairListener);
+ $dispatcher->addListener(RepairStepEvent::class, $repairListener);
+ $dispatcher->addListener(RepairInfoEvent::class, $repairListener);
+ $dispatcher->addListener(RepairWarningEvent::class, $repairListener);
+ $dispatcher->addListener(RepairErrorEvent::class, $repairListener);
$this->listen('\OC\Updater', 'maintenanceEnabled', function () use ($log) {