summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/DB/Migrator.php12
-rw-r--r--lib/private/DB/MigratorExecuteSqlEvent.php52
-rw-r--r--lib/private/Updater.php12
3 files changed, 64 insertions, 12 deletions
diff --git a/lib/private/DB/Migrator.php b/lib/private/DB/Migrator.php
index d2fdefefb39..5dc07be1d2b 100644
--- a/lib/private/DB/Migrator.php
+++ b/lib/private/DB/Migrator.php
@@ -37,9 +37,8 @@ use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\Type;
use OCP\IConfig;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
use function preg_match;
+use OCP\EventDispatcher\IEventDispatcher;
class Migrator {
@@ -49,15 +48,14 @@ class Migrator {
/** @var IConfig */
protected $config;
- /** @var ?EventDispatcherInterface */
- private $dispatcher;
+ private ?IEventDispatcher $dispatcher;
/** @var bool */
private $noEmit = false;
public function __construct(Connection $connection,
IConfig $config,
- ?EventDispatcherInterface $dispatcher = null) {
+ ?IEventDispatcher $dispatcher = null) {
$this->connection = $connection;
$this->config = $config;
$this->dispatcher = $dispatcher;
@@ -183,13 +181,13 @@ class Migrator {
return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
}
- protected function emit($sql, $step, $max) {
+ protected function emit(string $sql, int $step, int $max): void {
if ($this->noEmit) {
return;
}
if (is_null($this->dispatcher)) {
return;
}
- $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, ['step' => $step + 1, 'max' => $max]));
+ $this->dispatcher->dispatchTyped(new MigratorExecuteSqlEvent($sql, $step, $max));
}
}
diff --git a/lib/private/DB/MigratorExecuteSqlEvent.php b/lib/private/DB/MigratorExecuteSqlEvent.php
new file mode 100644
index 00000000000..d8a0e2ac3ad
--- /dev/null
+++ b/lib/private/DB/MigratorExecuteSqlEvent.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @copyright Copyright (c) 2022 Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+namespace OC\DB;
+
+use OCP\EventDispatcher\Event;
+
+class MigratorExecuteSqlEvent extends Event {
+ private string $sql;
+ private int $current;
+ private int $max;
+
+ public function __construct(
+ string $sql,
+ int $current,
+ int $max,
+ ) {
+ $this->sql = $sql;
+ $this->current = $current;
+ $this->max = $max;
+ }
+
+ public function getSql(): string {
+ return $this->sql;
+ }
+
+ public function getCurrentStep(): int {
+ return $this->current;
+ }
+
+ public function getMaxStep(): int {
+ return $this->max;
+ }
+}
diff --git a/lib/private/Updater.php b/lib/private/Updater.php
index 1b91441d676..e63c158f7a2 100644
--- a/lib/private/Updater.php
+++ b/lib/private/Updater.php
@@ -463,12 +463,14 @@ class Updater extends BasicEmitter {
$log = $this->log;
$dispatcher = \OC::$server->getEventDispatcher();
- $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($log) {
- if (!$event instanceof GenericEvent) {
- return;
+ /** @var IEventDispatcher $newDispatcher */
+ $newDispatcher = \OC::$server->get(IEventDispatcher::class);
+ $newDispatcher->addListener(
+ MigratorExecuteSqlEvent::class,
+ function (MigratorExecuteSqlEvent $event) use ($log) {
+ $log->info(get_class($event).': ' . $event->getSql() . ' (' . $event->getCurrentStep() . ' of ' . $event->getMaxStep() . ')', ['app' => 'updater']);
}
- $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument('step') . ' of ' . $event->getArgument('max') . ')', ['app' => 'updater']);
- });
+ );
$repairListener = function ($event) use ($log) {
if (!$event instanceof GenericEvent) {