AddMissingIndicesEvent.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
  5. * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
  6. *
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCP\DB\Events;
  27. /**
  28. * Event to allow apps to register information about missing database indices
  29. *
  30. * This event will be dispatched for checking on the admin settings and when running
  31. * occ db:add-missing-indices which will then create those indices
  32. *
  33. * @since 28.0.0
  34. */
  35. class AddMissingIndicesEvent extends \OCP\EventDispatcher\Event {
  36. /** @var array<array-key, array{tableName: string, indexName: string, columns: string[], options: array{}, dropUnnamedIndex: bool, uniqueIndex: bool}> */
  37. private array $missingIndices = [];
  38. /**
  39. * @param string[] $columns
  40. * @since 28.0.0
  41. */
  42. public function addMissingIndex(string $tableName, string $indexName, array $columns, array $options = [], bool $dropUnnamedIndex = false): void {
  43. $this->missingIndices[] = [
  44. 'tableName' => $tableName,
  45. 'indexName' => $indexName,
  46. 'columns' => $columns,
  47. 'options' => $options,
  48. 'dropUnnamedIndex' => $dropUnnamedIndex,
  49. 'uniqueIndex' => false,
  50. ];
  51. }
  52. /**
  53. * @param string[] $columns
  54. * @since 28.0.0
  55. */
  56. public function addMissingUniqueIndex(string $tableName, string $indexName, array $columns, array $options = [], bool $dropUnnamedIndex = false): void {
  57. $this->missingIndices[] = [
  58. 'tableName' => $tableName,
  59. 'indexName' => $indexName,
  60. 'columns' => $columns,
  61. 'options' => $options,
  62. 'dropUnnamedIndex' => $dropUnnamedIndex,
  63. 'uniqueIndex' => true,
  64. ];
  65. }
  66. /**
  67. * @since 28.0.0
  68. * @return array<array-key, array{tableName: string, indexName: string, columns: string[], options: array{}, dropUnnamedIndex: bool, uniqueIndex: bool}>
  69. */
  70. public function getMissingIndices(): array {
  71. return $this->missingIndices;
  72. }
  73. }