diff options
author | Joas Schilling <coding@schilljs.com> | 2023-07-19 22:36:59 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-07-24 14:51:32 +0200 |
commit | 2eded24eff5f3f0c911ffbd5841178030c8f9363 (patch) | |
tree | 3f073316f1aac7cd4669fbb2216ab12ed466ff07 /apps | |
parent | 7548e62181832dca36fa1a6ad4ec715d71fe83e6 (diff) | |
download | nextcloud-server-2eded24eff5f3f0c911ffbd5841178030c8f9363.tar.gz nextcloud-server-2eded24eff5f3f0c911ffbd5841178030c8f9363.zip |
feat(dispatcher): Add typed event for "db:add-missing-columns"
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/settings/lib/Controller/CheckSetupController.php | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 07fb627dbd8..170c6a3870a 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -74,6 +74,7 @@ use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI; use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; +use OCP\DB\Events\AddMissingColumnsEvent; use OCP\DB\Events\AddMissingIndicesEvent; use OCP\DB\Types; use OCP\EventDispatcher\IEventDispatcher; @@ -583,12 +584,28 @@ Raw output } protected function hasMissingColumns(): array { - $indexInfo = new MissingColumnInformation(); + $columnInfo = new MissingColumnInformation(); // Dispatch event so apps can also hint for pending index updates if needed - $event = new GenericEvent($indexInfo); + $event = new GenericEvent($columnInfo); $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_COLUMNS_EVENT, $event); - return $indexInfo->getListOfMissingColumns(); + $event = new AddMissingColumnsEvent(); + $this->eventDispatcher->dispatchTyped($event); + $missingColumns = $event->getMissingColumns(); + + if (!empty($missingColumns)) { + $schema = new SchemaWrapper(\OCP\Server::get(Connection::class)); + foreach ($missingColumns as $missingColumn) { + if ($schema->hasTable($missingColumn['tableName'])) { + $table = $schema->getTable($missingColumn['tableName']); + if (!$table->hasColumn($missingColumn['columnName'])) { + $columnInfo->addHintForMissingColumn($missingColumn['tableName'], $missingColumn['columnName']); + } + } + } + } + + return $columnInfo->getListOfMissingColumns(); } protected function isSqliteUsed() { |