aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php8
-rw-r--r--lib/composer/composer/autoload_static.php8
-rw-r--r--lib/private/DB/Connection.php2
-rw-r--r--lib/private/DB/Migrator.php37
-rw-r--r--lib/private/DB/MigratorExecuteSqlEvent.php55
-rw-r--r--lib/private/Migration/BackgroundRepair.php12
-rw-r--r--lib/private/Repair.php72
-rw-r--r--lib/private/Repair/Events/RepairAdvanceEvent.php48
-rw-r--r--lib/private/Repair/Events/RepairErrorEvent.php41
-rw-r--r--lib/private/Repair/Events/RepairFinishEvent.php30
-rw-r--r--lib/private/Repair/Events/RepairInfoEvent.php41
-rw-r--r--lib/private/Repair/Events/RepairStartEvent.php48
-rw-r--r--lib/private/Repair/Events/RepairStepEvent.php41
-rw-r--r--lib/private/Repair/Events/RepairWarningEvent.php41
-rw-r--r--lib/private/Updater.php140
-rw-r--r--lib/private/legacy/OC_App.php17
-rw-r--r--lib/public/IEventSource.php2
-rw-r--r--lib/public/Migration/IOutput.php6
18 files changed, 481 insertions, 168 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 530373599af..5b8e057636c 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -1063,6 +1063,7 @@ return array(
'OC\\DB\\MigrationException' => $baseDir . '/lib/private/DB/MigrationException.php',
'OC\\DB\\MigrationService' => $baseDir . '/lib/private/DB/MigrationService.php',
'OC\\DB\\Migrator' => $baseDir . '/lib/private/DB/Migrator.php',
+ 'OC\\DB\\MigratorExecuteSqlEvent' => $baseDir . '/lib/private/DB/MigratorExecuteSqlEvent.php',
'OC\\DB\\MissingColumnInformation' => $baseDir . '/lib/private/DB/MissingColumnInformation.php',
'OC\\DB\\MissingIndexInformation' => $baseDir . '/lib/private/DB/MissingIndexInformation.php',
'OC\\DB\\MissingPrimaryKeyInformation' => $baseDir . '/lib/private/DB/MissingPrimaryKeyInformation.php',
@@ -1417,6 +1418,13 @@ return array(
'OC\\Repair\\ClearFrontendCaches' => $baseDir . '/lib/private/Repair/ClearFrontendCaches.php',
'OC\\Repair\\ClearGeneratedAvatarCache' => $baseDir . '/lib/private/Repair/ClearGeneratedAvatarCache.php',
'OC\\Repair\\Collation' => $baseDir . '/lib/private/Repair/Collation.php',
+ 'OC\\Repair\\Events\\RepairAdvanceEvent' => $baseDir . '/lib/private/Repair/Events/RepairAdvanceEvent.php',
+ 'OC\\Repair\\Events\\RepairErrorEvent' => $baseDir . '/lib/private/Repair/Events/RepairErrorEvent.php',
+ 'OC\\Repair\\Events\\RepairFinishEvent' => $baseDir . '/lib/private/Repair/Events/RepairFinishEvent.php',
+ 'OC\\Repair\\Events\\RepairInfoEvent' => $baseDir . '/lib/private/Repair/Events/RepairInfoEvent.php',
+ 'OC\\Repair\\Events\\RepairStartEvent' => $baseDir . '/lib/private/Repair/Events/RepairStartEvent.php',
+ 'OC\\Repair\\Events\\RepairStepEvent' => $baseDir . '/lib/private/Repair/Events/RepairStepEvent.php',
+ 'OC\\Repair\\Events\\RepairWarningEvent' => $baseDir . '/lib/private/Repair/Events/RepairWarningEvent.php',
'OC\\Repair\\MoveUpdaterStepFile' => $baseDir . '/lib/private/Repair/MoveUpdaterStepFile.php',
'OC\\Repair\\NC11\\FixMountStorages' => $baseDir . '/lib/private/Repair/NC11/FixMountStorages.php',
'OC\\Repair\\NC13\\AddLogRotateJob' => $baseDir . '/lib/private/Repair/NC13/AddLogRotateJob.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 3fb77f62439..dd3031d3a9b 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -1096,6 +1096,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\DB\\MigrationException' => __DIR__ . '/../../..' . '/lib/private/DB/MigrationException.php',
'OC\\DB\\MigrationService' => __DIR__ . '/../../..' . '/lib/private/DB/MigrationService.php',
'OC\\DB\\Migrator' => __DIR__ . '/../../..' . '/lib/private/DB/Migrator.php',
+ 'OC\\DB\\MigratorExecuteSqlEvent' => __DIR__ . '/../../..' . '/lib/private/DB/MigratorExecuteSqlEvent.php',
'OC\\DB\\MissingColumnInformation' => __DIR__ . '/../../..' . '/lib/private/DB/MissingColumnInformation.php',
'OC\\DB\\MissingIndexInformation' => __DIR__ . '/../../..' . '/lib/private/DB/MissingIndexInformation.php',
'OC\\DB\\MissingPrimaryKeyInformation' => __DIR__ . '/../../..' . '/lib/private/DB/MissingPrimaryKeyInformation.php',
@@ -1450,6 +1451,13 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Repair\\ClearFrontendCaches' => __DIR__ . '/../../..' . '/lib/private/Repair/ClearFrontendCaches.php',
'OC\\Repair\\ClearGeneratedAvatarCache' => __DIR__ . '/../../..' . '/lib/private/Repair/ClearGeneratedAvatarCache.php',
'OC\\Repair\\Collation' => __DIR__ . '/../../..' . '/lib/private/Repair/Collation.php',
+ 'OC\\Repair\\Events\\RepairAdvanceEvent' => __DIR__ . '/../../..' . '/lib/private/Repair/Events/RepairAdvanceEvent.php',
+ 'OC\\Repair\\Events\\RepairErrorEvent' => __DIR__ . '/../../..' . '/lib/private/Repair/Events/RepairErrorEvent.php',
+ 'OC\\Repair\\Events\\RepairFinishEvent' => __DIR__ . '/../../..' . '/lib/private/Repair/Events/RepairFinishEvent.php',
+ 'OC\\Repair\\Events\\RepairInfoEvent' => __DIR__ . '/../../..' . '/lib/private/Repair/Events/RepairInfoEvent.php',
+ 'OC\\Repair\\Events\\RepairStartEvent' => __DIR__ . '/../../..' . '/lib/private/Repair/Events/RepairStartEvent.php',
+ 'OC\\Repair\\Events\\RepairStepEvent' => __DIR__ . '/../../..' . '/lib/private/Repair/Events/RepairStepEvent.php',
+ 'OC\\Repair\\Events\\RepairWarningEvent' => __DIR__ . '/../../..' . '/lib/private/Repair/Events/RepairWarningEvent.php',
'OC\\Repair\\MoveUpdaterStepFile' => __DIR__ . '/../../..' . '/lib/private/Repair/MoveUpdaterStepFile.php',
'OC\\Repair\\NC11\\FixMountStorages' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/FixMountStorages.php',
'OC\\Repair\\NC13\\AddLogRotateJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC13/AddLogRotateJob.php',
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index 22c2bbbb793..73e0f4b4ac2 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -588,7 +588,7 @@ class Connection extends \Doctrine\DBAL\Connection {
$random = \OC::$server->getSecureRandom();
$platform = $this->getDatabasePlatform();
$config = \OC::$server->getConfig();
- $dispatcher = \OC::$server->getEventDispatcher();
+ $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
if ($platform instanceof SqlitePlatform) {
return new SQLiteMigrator($this, $config, $dispatcher);
} elseif ($platform instanceof OraclePlatform) {
diff --git a/lib/private/DB/Migrator.php b/lib/private/DB/Migrator.php
index 9ca37d7180a..5dc07be1d2b 100644
--- a/lib/private/DB/Migrator.php
+++ b/lib/private/DB/Migrator.php
@@ -27,48 +27,41 @@
*/
namespace OC\DB;
+use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
+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 {
- /** @var \Doctrine\DBAL\Connection */
+ /** @var Connection */
protected $connection;
/** @var IConfig */
protected $config;
- /** @var EventDispatcherInterface */
- private $dispatcher;
+ private ?IEventDispatcher $dispatcher;
/** @var bool */
private $noEmit = false;
- /**
- * @param \Doctrine\DBAL\Connection $connection
- * @param IConfig $config
- * @param EventDispatcherInterface $dispatcher
- */
- public function __construct(\Doctrine\DBAL\Connection $connection,
+ public function __construct(Connection $connection,
IConfig $config,
- EventDispatcherInterface $dispatcher = null) {
+ ?IEventDispatcher $dispatcher = null) {
$this->connection = $connection;
$this->config = $config;
$this->dispatcher = $dispatcher;
}
/**
- * @param \Doctrine\DBAL\Schema\Schema $targetSchema
- *
* @throws Exception
*/
public function migrate(Schema $targetSchema) {
@@ -77,7 +70,6 @@ class Migrator {
}
/**
- * @param \Doctrine\DBAL\Schema\Schema $targetSchema
* @return string
*/
public function generateChangeScript(Schema $targetSchema) {
@@ -108,11 +100,9 @@ class Migrator {
}
/**
- * @param Schema $targetSchema
- * @param \Doctrine\DBAL\Connection $connection
- * @return \Doctrine\DBAL\Schema\SchemaDiff
+ * @return SchemaDiff
*/
- protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
+ protected function getDiff(Schema $targetSchema, Connection $connection) {
// adjust varchar columns with a length higher then getVarcharMaxLength to clob
foreach ($targetSchema->getTables() as $table) {
foreach ($table->getColumns() as $column) {
@@ -153,12 +143,9 @@ class Migrator {
}
/**
- * @param \Doctrine\DBAL\Schema\Schema $targetSchema
- * @param \Doctrine\DBAL\Connection $connection
- *
* @throws Exception
*/
- protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) {
+ protected function applySchema(Schema $targetSchema, Connection $connection = null) {
if (is_null($connection)) {
$connection = $this->connection;
}
@@ -194,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 + 1, $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..997a4eee53a
--- /dev/null
+++ b/lib/private/DB/MigratorExecuteSqlEvent.php
@@ -0,0 +1,55 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @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/Migration/BackgroundRepair.php b/lib/private/Migration/BackgroundRepair.php
index f3ae8f4bdcf..579ba494e58 100644
--- a/lib/private/Migration/BackgroundRepair.php
+++ b/lib/private/Migration/BackgroundRepair.php
@@ -26,14 +26,14 @@
*/
namespace OC\Migration;
-use OC\NeedsUpdateException;
-use OC\Repair;
-use OC_App;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\TimedJob;
+use OCP\EventDispatcher\IEventDispatcher;
+use OC\NeedsUpdateException;
+use OC\Repair;
+use OC_App;
use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Class BackgroundRepair
@@ -43,9 +43,9 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class BackgroundRepair extends TimedJob {
private IJobList $jobList;
private LoggerInterface $logger;
- private EventDispatcherInterface $dispatcher;
+ private IEventDispatcher $dispatcher;
- public function __construct(EventDispatcherInterface $dispatcher, ITimeFactory $time, LoggerInterface $logger, IJobList $jobList) {
+ public function __construct(IEventDispatcher $dispatcher, ITimeFactory $time, LoggerInterface $logger, IJobList $jobList) {
parent::__construct($time);
$this->dispatcher = $dispatcher;
$this->logger = $logger;
diff --git a/lib/private/Repair.php b/lib/private/Repair.php
index 98a1f4ce036..e2e5da79216 100644
--- a/lib/private/Repair.php
+++ b/lib/private/Repair.php
@@ -34,6 +34,12 @@
*/
namespace OC;
+use OCP\AppFramework\QueryException;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Collaboration\Resources\IManager;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
use OC\App\AppStore\Bundles\BundleFetcher;
use OC\Avatar\AvatarManager;
use OC\DB\Connection;
@@ -44,15 +50,15 @@ use OC\Repair\CleanTags;
use OC\Repair\ClearFrontendCaches;
use OC\Repair\ClearGeneratedAvatarCache;
use OC\Repair\Collation;
+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\Repair\MoveUpdaterStepFile;
-use OC\Repair\NC22\LookupServerSendCheck;
-use OC\Repair\NC24\AddTokenCleanupJob;
-use OC\Repair\Owncloud\CleanPreviews;
-use OC\Repair\Owncloud\MigrateOauthTables;
use OC\Repair\NC11\FixMountStorages;
-use OC\Repair\Owncloud\MoveAvatars;
-use OC\Repair\Owncloud\InstallCoreBundle;
-use OC\Repair\Owncloud\UpdateLanguageCodes;
use OC\Repair\NC13\AddLogRotateJob;
use OC\Repair\NC14\AddPreviewBackgroundCleanupJob;
use OC\Repair\NC16\AddClenupLoginFlowV2BackgroundJob;
@@ -64,23 +70,23 @@ use OC\Repair\NC20\EncryptionMigration;
use OC\Repair\NC20\ShippedDashboardEnable;
use OC\Repair\NC21\AddCheckForUserCertificatesJob;
use OC\Repair\NC21\ValidatePhoneNumber;
+use OC\Repair\NC22\LookupServerSendCheck;
+use OC\Repair\NC24\AddTokenCleanupJob;
use OC\Repair\OldGroupMembershipShares;
+use OC\Repair\Owncloud\CleanPreviews;
use OC\Repair\Owncloud\DropAccountTermsTable;
+use OC\Repair\Owncloud\InstallCoreBundle;
+use OC\Repair\Owncloud\MigrateOauthTables;
+use OC\Repair\Owncloud\MoveAvatars;
use OC\Repair\Owncloud\SaveAccountsTableData;
+use OC\Repair\Owncloud\UpdateLanguageCodes;
use OC\Repair\RemoveLinkShares;
use OC\Repair\RepairDavShares;
use OC\Repair\RepairInvalidShares;
use OC\Repair\RepairMimeTypes;
use OC\Repair\SqliteAutoincrement;
use OC\Template\JSCombiner;
-use OCP\AppFramework\QueryException;
-use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Collaboration\Resources\IManager;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
use Throwable;
class Repair implements IOutput {
@@ -88,8 +94,7 @@ class Repair implements IOutput {
/** @var IRepairStep[] */
private $repairSteps;
- /** @var EventDispatcherInterface */
- private $dispatcher;
+ private IEventDispatcher $dispatcher;
/** @var string */
private $currentStep;
@@ -101,7 +106,7 @@ class Repair implements IOutput {
*
* @param IRepairStep[] $repairSteps array of RepairStep instances
*/
- public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher, LoggerInterface $logger) {
+ public function __construct(array $repairSteps, IEventDispatcher $dispatcher, LoggerInterface $logger) {
$this->repairSteps = $repairSteps;
$this->dispatcher = $dispatcher;
$this->logger = $logger;
@@ -112,19 +117,19 @@ class Repair implements IOutput {
*/
public function run() {
if (count($this->repairSteps) === 0) {
- $this->emit('\OC\Repair', 'info', ['No repair steps available']);
+ $this->dispatcher->dispatchTyped(new RepairInfoEvent('No repair steps available'));
return;
}
// run each repair step
foreach ($this->repairSteps as $step) {
$this->currentStep = $step->getName();
- $this->emit('\OC\Repair', 'step', [$this->currentStep]);
+ $this->dispatcher->dispatchTyped(new RepairStepEvent($this->currentStep));
try {
$step->run($this);
} catch (\Exception $e) {
$this->logger->error("Exception while executing repair step " . $step->getName(), ['exception' => $e]);
- $this->emit('\OC\Repair', 'error', [$e->getMessage()]);
+ $this->dispatcher->dispatchTyped(new RepairErrorEvent($e->getMessage()));
}
}
}
@@ -138,7 +143,7 @@ class Repair implements IOutput {
public function addStep($repairStep) {
if (is_string($repairStep)) {
try {
- $s = \OC::$server->query($repairStep);
+ $s = \OC::$server->get($repairStep);
} catch (QueryException $e) {
if (class_exists($repairStep)) {
try {
@@ -250,20 +255,11 @@ class Repair implements IOutput {
}
/**
- * @param string $scope
- * @param string $method
- * @param array $arguments
+ * @param string $message
*/
- public function emit($scope, $method, array $arguments = []) {
- if (!is_null($this->dispatcher)) {
- $this->dispatcher->dispatch("$scope::$method",
- new GenericEvent("$scope::$method", $arguments));
- }
- }
-
- public function info($string) {
+ public function info($message) {
// for now just emit as we did in the past
- $this->emit('\OC\Repair', 'info', [$string]);
+ $this->dispatcher->dispatchTyped(new RepairInfoEvent($message));
}
/**
@@ -271,7 +267,7 @@ class Repair implements IOutput {
*/
public function warning($message) {
// for now just emit as we did in the past
- $this->emit('\OC\Repair', 'warning', [$message]);
+ $this->dispatcher->dispatchTyped(new RepairWarningEvent($message));
}
/**
@@ -279,16 +275,16 @@ class Repair implements IOutput {
*/
public function startProgress($max = 0) {
// for now just emit as we did in the past
- $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]);
+ $this->dispatcher->dispatchTyped(new RepairStartEvent($max, $this->currentStep));
}
/**
- * @param int $step
+ * @param int $step number of step to advance
* @param string $description
*/
public function advance($step = 1, $description = '') {
// for now just emit as we did in the past
- $this->emit('\OC\Repair', 'advance', [$step, $description]);
+ $this->dispatcher->dispatchTyped(new RepairAdvanceEvent($step, $description));
}
/**
@@ -296,6 +292,6 @@ class Repair implements IOutput {
*/
public function finishProgress() {
// for now just emit as we did in the past
- $this->emit('\OC\Repair', 'finishProgress', []);
+ $this->dispatcher->dispatchTyped(new RepairFinishEvent());
}
}
diff --git a/lib/private/Repair/Events/RepairAdvanceEvent.php b/lib/private/Repair/Events/RepairAdvanceEvent.php
new file mode 100644
index 00000000000..174d4ec48cd
--- /dev/null
+++ b/lib/private/Repair/Events/RepairAdvanceEvent.php
@@ -0,0 +1,48 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @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\Repair\Events;
+
+use OCP\EventDispatcher\Event;
+
+class RepairAdvanceEvent extends Event {
+ private int $increment;
+ private string $description;
+
+ public function __construct(
+ int $increment,
+ string $description
+ ) {
+ $this->increment = $increment;
+ $this->description = $description;
+ }
+
+ public function getIncrement(): int {
+ return $this->increment;
+ }
+
+ public function getDescription(): string {
+ return $this->description;
+ }
+}
diff --git a/lib/private/Repair/Events/RepairErrorEvent.php b/lib/private/Repair/Events/RepairErrorEvent.php
new file mode 100644
index 00000000000..7f8a87cfda3
--- /dev/null
+++ b/lib/private/Repair/Events/RepairErrorEvent.php
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @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\Repair\Events;
+
+use OCP\EventDispatcher\Event;
+
+class RepairErrorEvent extends Event {
+ private string $message;
+
+ public function __construct(
+ string $message
+ ) {
+ $this->message = $message;
+ }
+
+ public function getMessage(): string {
+ return $this->message;
+ }
+}
diff --git a/lib/private/Repair/Events/RepairFinishEvent.php b/lib/private/Repair/Events/RepairFinishEvent.php
new file mode 100644
index 00000000000..abdc2acd1ce
--- /dev/null
+++ b/lib/private/Repair/Events/RepairFinishEvent.php
@@ -0,0 +1,30 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @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\Repair\Events;
+
+use OCP\EventDispatcher\Event;
+
+class RepairFinishEvent extends Event {
+}
diff --git a/lib/private/Repair/Events/RepairInfoEvent.php b/lib/private/Repair/Events/RepairInfoEvent.php
new file mode 100644
index 00000000000..5c2a53fce4f
--- /dev/null
+++ b/lib/private/Repair/Events/RepairInfoEvent.php
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @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\Repair\Events;
+
+use OCP\EventDispatcher\Event;
+
+class RepairInfoEvent extends Event {
+ private string $message;
+
+ public function __construct(
+ string $message
+ ) {
+ $this->message = $message;
+ }
+
+ public function getMessage(): string {
+ return $this->message;
+ }
+}
diff --git a/lib/private/Repair/Events/RepairStartEvent.php b/lib/private/Repair/Events/RepairStartEvent.php
new file mode 100644
index 00000000000..7bb270595c5
--- /dev/null
+++ b/lib/private/Repair/Events/RepairStartEvent.php
@@ -0,0 +1,48 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @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\Repair\Events;
+
+use OCP\EventDispatcher\Event;
+
+class RepairStartEvent extends Event {
+ private int $max;
+ private string $current;
+
+ public function __construct(
+ int $max,
+ string $current
+ ) {
+ $this->max = $max;
+ $this->current = $current;
+ }
+
+ public function getMaxStep(): int {
+ return $this->max;
+ }
+
+ public function getCurrentStepName(): string {
+ return $this->current;
+ }
+}
diff --git a/lib/private/Repair/Events/RepairStepEvent.php b/lib/private/Repair/Events/RepairStepEvent.php
new file mode 100644
index 00000000000..82af670b950
--- /dev/null
+++ b/lib/private/Repair/Events/RepairStepEvent.php
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @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\Repair\Events;
+
+use OCP\EventDispatcher\Event;
+
+class RepairStepEvent extends Event {
+ private string $stepName;
+
+ public function __construct(
+ string $stepName
+ ) {
+ $this->stepName = $stepName;
+ }
+
+ public function getStepName(): string {
+ return $this->stepName;
+ }
+}
diff --git a/lib/private/Repair/Events/RepairWarningEvent.php b/lib/private/Repair/Events/RepairWarningEvent.php
new file mode 100644
index 00000000000..2aaa44d4719
--- /dev/null
+++ b/lib/private/Repair/Events/RepairWarningEvent.php
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @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\Repair\Events;
+
+use OCP\EventDispatcher\Event;
+
+class RepairWarningEvent extends Event {
+ private string $message;
+
+ public function __construct(
+ string $message
+ ) {
+ $this->message = $message;
+ }
+
+ public function getMessage(): string {
+ return $this->message;
+ }
+}
diff --git a/lib/private/Updater.php b/lib/private/Updater.php
index da989c4db91..78613ddbb0c 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,11 +297,11 @@ 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
- $this->config->setAppValue('core', 'lastupdatedat', 0);
+ $this->config->setAppValue('core', 'lastupdatedat', '0');
// Check for code integrity if not disabled
if (\OC::$server->getIntegrityCodeChecker()->isCodeCheckEnforced()) {
@@ -432,91 +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();
- $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($log) {
- if (!$event instanceof GenericEvent) {
- return;
- }
- $log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
- });
- $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($log) {
- if (!$event instanceof GenericEvent) {
- return;
+ /** @var IEventDispatcher $dispatcher */
+ $dispatcher = \OC::$server->get(IEventDispatcher::class);
+ $dispatcher->addListener(
+ MigratorExecuteSqlEvent::class,
+ function (MigratorExecuteSqlEvent $event) use ($log): void {
+ $log->info(get_class($event).': ' . $event->getSql() . ' (' . $event->getCurrentStep() . ' of ' . $event->getMaxStep() . ')', ['app' => 'updater']);
}
- $log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['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(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
- break;
- case '\OC\Repair::advance':
- $desc = $event->getArgument(1);
- if (empty($desc)) {
- $desc = '';
- }
- $log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['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(0), ['app' => 'updater']);
- break;
- case '\OC\Repair::info':
- $log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']);
- break;
- case '\OC\Repair::warning':
- $log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']);
- break;
- case '\OC\Repair::error':
- $log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']);
- break;
+ );
+
+ $repairListener = function (Event $event) use ($log): void {
+ 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->getIncrement() . ')', ['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) {
diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php
index 482fc4e88e7..a5eb26d0d4b 100644
--- a/lib/private/legacy/OC_App.php
+++ b/lib/private/legacy/OC_App.php
@@ -50,18 +50,19 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
+use OCP\AppFramework\QueryException;
+use OCP\App\ManagerEvent;
+use OCP\Authentication\IAlternativeLogin;
+use OCP\ILogger;
+use OCP\Settings\IManager as ISettingsManager;
+use OC\AppFramework\Bootstrap\Coordinator;
use OC\App\DependencyAnalyzer;
use OC\App\Platform;
-use OC\AppFramework\Bootstrap\Coordinator;
use OC\DB\MigrationService;
use OC\Installer;
use OC\Repair;
+use OC\Repair\Events\RepairErrorEvent;
use OC\ServerNotAvailableException;
-use OCP\App\ManagerEvent;
-use OCP\AppFramework\QueryException;
-use OCP\Authentication\IAlternativeLogin;
-use OCP\ILogger;
-use OCP\Settings\IManager as ISettingsManager;
use Psr\Log\LoggerInterface;
/**
@@ -1047,7 +1048,7 @@ class OC_App {
// load the app
self::loadApp($appId);
- $dispatcher = OC::$server->getEventDispatcher();
+ $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
// load the steps
$r = new Repair([], $dispatcher, \OC::$server->get(LoggerInterface::class));
@@ -1055,7 +1056,7 @@ class OC_App {
try {
$r->addStep($step);
} catch (Exception $ex) {
- $r->emit('\OC\Repair', 'error', [$ex->getMessage()]);
+ $dispatcher->dispatchTyped(new RepairErrorEvent($ex->getMessage()));
\OC::$server->getLogger()->logException($ex);
}
}
diff --git a/lib/public/IEventSource.php b/lib/public/IEventSource.php
index 85f09837125..879b365cc77 100644
--- a/lib/public/IEventSource.php
+++ b/lib/public/IEventSource.php
@@ -35,7 +35,7 @@ interface IEventSource {
/**
* send a message to the client
*
- * @param string $type
+ * @param string $type One of success, notice, error, failure and done. Used in core/js/update.js
* @param mixed $data
*
* if only one parameter is given, a typeless message will be send with that parameter as data
diff --git a/lib/public/Migration/IOutput.php b/lib/public/Migration/IOutput.php
index 2dba50ab2c6..212b5d927f8 100644
--- a/lib/public/Migration/IOutput.php
+++ b/lib/public/Migration/IOutput.php
@@ -32,18 +32,21 @@ interface IOutput {
/**
* @param string $message
+ * @return void
* @since 9.1.0
*/
public function info($message);
/**
* @param string $message
+ * @return void
* @since 9.1.0
*/
public function warning($message);
/**
* @param int $max
+ * @return void
* @since 9.1.0
*/
public function startProgress($max = 0);
@@ -51,12 +54,13 @@ interface IOutput {
/**
* @param int $step
* @param string $description
+ * @return void
* @since 9.1.0
*/
public function advance($step = 1, $description = '');
/**
- * @param int $max
+ * @return void
* @since 9.1.0
*/
public function finishProgress();