diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-07-25 13:37:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-25 13:37:51 +0200 |
commit | f824d87fc1f3aa99ddb141b7ba19b48641d2cb84 (patch) | |
tree | 52e9690556a722051d7b71ddf7f46ce13a409f31 /lib | |
parent | 468fb5c8db2318702c9a1895271b7d9c4f579dc0 (diff) | |
parent | ab70bbd3ffbc3788035588c86984f9508db8edbe (diff) | |
download | nextcloud-server-f824d87fc1f3aa99ddb141b7ba19b48641d2cb84.tar.gz nextcloud-server-f824d87fc1f3aa99ddb141b7ba19b48641d2cb84.zip |
Merge pull request #39487 from nextcloud/feat/noid/typed-events-for-db_add-missing
Feat/noid/typed events for db add missing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 2 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 2 | ||||
-rw-r--r-- | lib/public/DB/Events/AddMissingColumnsEvent.php | 60 | ||||
-rw-r--r-- | lib/public/DB/Events/AddMissingIndicesEvent.php | 31 | ||||
-rw-r--r-- | lib/public/DB/Events/AddMissingPrimaryKeyEvent.php | 60 | ||||
-rw-r--r-- | lib/public/IDBConnection.php | 31 |
6 files changed, 149 insertions, 37 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index fcd1020be10..89ae83e83e4 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -210,7 +210,9 @@ return array( 'OCP\\Contacts\\ContactsMenu\\IProvider' => $baseDir . '/lib/public/Contacts/ContactsMenu/IProvider.php', 'OCP\\Contacts\\Events\\ContactInteractedWithEvent' => $baseDir . '/lib/public/Contacts/Events/ContactInteractedWithEvent.php', 'OCP\\Contacts\\IManager' => $baseDir . '/lib/public/Contacts/IManager.php', + 'OCP\\DB\\Events\\AddMissingColumnsEvent' => $baseDir . '/lib/public/DB/Events/AddMissingColumnsEvent.php', 'OCP\\DB\\Events\\AddMissingIndicesEvent' => $baseDir . '/lib/public/DB/Events/AddMissingIndicesEvent.php', + 'OCP\\DB\\Events\\AddMissingPrimaryKeyEvent' => $baseDir . '/lib/public/DB/Events/AddMissingPrimaryKeyEvent.php', 'OCP\\DB\\Exception' => $baseDir . '/lib/public/DB/Exception.php', 'OCP\\DB\\IPreparedStatement' => $baseDir . '/lib/public/DB/IPreparedStatement.php', 'OCP\\DB\\IResult' => $baseDir . '/lib/public/DB/IResult.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 783e63550c0..0480448a1b8 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -243,7 +243,9 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Contacts\\ContactsMenu\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Contacts/ContactsMenu/IProvider.php', 'OCP\\Contacts\\Events\\ContactInteractedWithEvent' => __DIR__ . '/../../..' . '/lib/public/Contacts/Events/ContactInteractedWithEvent.php', 'OCP\\Contacts\\IManager' => __DIR__ . '/../../..' . '/lib/public/Contacts/IManager.php', + 'OCP\\DB\\Events\\AddMissingColumnsEvent' => __DIR__ . '/../../..' . '/lib/public/DB/Events/AddMissingColumnsEvent.php', 'OCP\\DB\\Events\\AddMissingIndicesEvent' => __DIR__ . '/../../..' . '/lib/public/DB/Events/AddMissingIndicesEvent.php', + 'OCP\\DB\\Events\\AddMissingPrimaryKeyEvent' => __DIR__ . '/../../..' . '/lib/public/DB/Events/AddMissingPrimaryKeyEvent.php', 'OCP\\DB\\Exception' => __DIR__ . '/../../..' . '/lib/public/DB/Exception.php', 'OCP\\DB\\IPreparedStatement' => __DIR__ . '/../../..' . '/lib/public/DB/IPreparedStatement.php', 'OCP\\DB\\IResult' => __DIR__ . '/../../..' . '/lib/public/DB/IResult.php', diff --git a/lib/public/DB/Events/AddMissingColumnsEvent.php b/lib/public/DB/Events/AddMissingColumnsEvent.php new file mode 100644 index 00000000000..1fb44e86842 --- /dev/null +++ b/lib/public/DB/Events/AddMissingColumnsEvent.php @@ -0,0 +1,60 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com> + * + * @author Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\DB\Events; + +/** + * Event to allow apps to register information about missing database columns + * + * This event will be dispatched for checking on the admin settings and when running + * occ db:add-missing-columns which will then create those columns + * + * @since 28.0.0 + */ +class AddMissingColumnsEvent extends \OCP\EventDispatcher\Event { + /** @var array<array-key, array{tableName: string, columnName: string, typeName: string, options: array{}}> */ + private array $missingColumns = []; + + /** + * @param mixed[] $options + * @since 28.0.0 + */ + public function addMissingColumn(string $tableName, string $columnName, string $typeName, array $options): void { + $this->missingColumns[] = [ + 'tableName' => $tableName, + 'columnName' => $columnName, + 'typeName' => $typeName, + 'options' => $options, + ]; + } + + /** + * @since 28.0.0 + * @return array<array-key, array{tableName: string, columnName: string, typeName: string, options: array{}}> + */ + public function getMissingColumns(): array { + return $this->missingColumns; + } +} diff --git a/lib/public/DB/Events/AddMissingIndicesEvent.php b/lib/public/DB/Events/AddMissingIndicesEvent.php index 139b776b136..dc942f3d63e 100644 --- a/lib/public/DB/Events/AddMissingIndicesEvent.php +++ b/lib/public/DB/Events/AddMissingIndicesEvent.php @@ -2,9 +2,11 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net + * @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com> + * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net> * - * @author Julius Härtl <jus@bitgrid.net + * @author Joas Schilling <coding@schilljs.com> + * @author Julius Härtl <jus@bitgrid.net> * * @license GNU AGPL version 3 or any later version * @@ -34,24 +36,41 @@ namespace OCP\DB\Events; * @since 28.0.0 */ class AddMissingIndicesEvent extends \OCP\EventDispatcher\Event { - /** @var array<array-key, array{tableName: string, indexName: string, columns: string[]}> */ + /** @var array<array-key, array{tableName: string, indexName: string, columns: string[], options: array{}, dropUnnamedIndex: bool, uniqueIndex: bool}> */ private array $missingIndices = []; /** * @param string[] $columns * @since 28.0.0 */ - public function addMissingIndex(string $tableName, string $indexName, array $columns): void { + public function addMissingIndex(string $tableName, string $indexName, array $columns, array $options = [], bool $dropUnnamedIndex = false): void { $this->missingIndices[] = [ 'tableName' => $tableName, 'indexName' => $indexName, - 'columns' => $columns + 'columns' => $columns, + 'options' => $options, + 'dropUnnamedIndex' => $dropUnnamedIndex, + 'uniqueIndex' => false, + ]; + } + /** + * @param string[] $columns + * @since 28.0.0 + */ + public function addMissingUniqueIndex(string $tableName, string $indexName, array $columns, array $options = [], bool $dropUnnamedIndex = false): void { + $this->missingIndices[] = [ + 'tableName' => $tableName, + 'indexName' => $indexName, + 'columns' => $columns, + 'options' => $options, + 'dropUnnamedIndex' => $dropUnnamedIndex, + 'uniqueIndex' => true, ]; } /** * @since 28.0.0 - * @return array<array-key, array{tableName: string, indexName: string, columns: string[]}> + * @return array<array-key, array{tableName: string, indexName: string, columns: string[], options: array{}, dropUnnamedIndex: bool, uniqueIndex: bool}> */ public function getMissingIndices(): array { return $this->missingIndices; diff --git a/lib/public/DB/Events/AddMissingPrimaryKeyEvent.php b/lib/public/DB/Events/AddMissingPrimaryKeyEvent.php new file mode 100644 index 00000000000..ace55d7538b --- /dev/null +++ b/lib/public/DB/Events/AddMissingPrimaryKeyEvent.php @@ -0,0 +1,60 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\DB\Events; + +/** + * Event to allow apps to register information about missing database primary keys + * + * This event will be dispatched for checking on the admin settings and when running + * occ db:add-missing-primary-keys which will then create those keys + * + * @since 28.0.0 + */ +class AddMissingPrimaryKeyEvent extends \OCP\EventDispatcher\Event { + /** @var array<array-key, array{tableName: string, primaryKeyName: string, columns: string[], formerIndex: null|string}> */ + private array $missingPrimaryKeys = []; + + /** + * @param string[] $columns + * @since 28.0.0 + */ + public function addMissingPrimaryKey(string $tableName, string $primaryKeyName, array $columns, ?string $formerIndex = null): void { + $this->missingPrimaryKeys[] = [ + 'tableName' => $tableName, + 'primaryKeyName' => $primaryKeyName, + 'columns' => $columns, + 'formerIndex' => $formerIndex, + ]; + } + + /** + * @since 28.0.0 + * @return array<array-key, array{tableName: string, primaryKeyName: string, columns: string[], formerIndex: null|string}> + */ + public function getMissingPrimaryKeys(): array { + return $this->missingPrimaryKeys; + } +} diff --git a/lib/public/IDBConnection.php b/lib/public/IDBConnection.php index bfc63b2aab0..fe0267facc5 100644 --- a/lib/public/IDBConnection.php +++ b/lib/public/IDBConnection.php @@ -34,7 +34,6 @@ namespace OCP; use Doctrine\DBAL\Schema\Schema; -use OCP\DB\Events\AddMissingIndicesEvent; use OCP\DB\Exception; use OCP\DB\IPreparedStatement; use OCP\DB\IResult; @@ -47,36 +46,6 @@ use OCP\DB\QueryBuilder\IQueryBuilder; */ interface IDBConnection { /** - * @deprecated 22.0.0 this is an internal event, use {@see AddMissingIndicesEvent} instead - */ - public const ADD_MISSING_INDEXES_EVENT = self::class . '::ADD_MISSING_INDEXES'; - - /** - * @deprecated 22.0.0 this is an internal event, use {@see AddMissingIndicesEvent} instead - */ - public const CHECK_MISSING_INDEXES_EVENT = self::class . '::CHECK_MISSING_INDEXES'; - - /** - * @deprecated 22.0.0 this is an internal event - */ - public const ADD_MISSING_PRIMARY_KEYS_EVENT = self::class . '::ADD_MISSING_PRIMARY_KEYS'; - - /** - * @deprecated 22.0.0 this is an internal event - */ - public const CHECK_MISSING_PRIMARY_KEYS_EVENT = self::class . '::CHECK_MISSING_PRIMARY_KEYS'; - - /** - * @deprecated 22.0.0 this is an internal event - */ - public const ADD_MISSING_COLUMNS_EVENT = self::class . '::ADD_MISSING_COLUMNS'; - - /** - * @deprecated 22.0.0 this is an internal event - */ - public const CHECK_MISSING_COLUMNS_EVENT = self::class . '::CHECK_MISSING_COLUMNS'; - - /** * Gets the QueryBuilder for the connection. * * @return \OCP\DB\QueryBuilder\IQueryBuilder |