AddMissingPrimaryKeyEvent.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\DB\Events;
  8. /**
  9. * Event to allow apps to register information about missing database primary keys
  10. *
  11. * This event will be dispatched for checking on the admin settings and when running
  12. * occ db:add-missing-primary-keys which will then create those keys
  13. *
  14. * @since 28.0.0
  15. */
  16. class AddMissingPrimaryKeyEvent extends \OCP\EventDispatcher\Event {
  17. /** @var array<array-key, array{tableName: string, primaryKeyName: string, columns: string[], formerIndex: null|string}> */
  18. private array $missingPrimaryKeys = [];
  19. /**
  20. * @param string[] $columns
  21. * @since 28.0.0
  22. */
  23. public function addMissingPrimaryKey(string $tableName, string $primaryKeyName, array $columns, ?string $formerIndex = null): void {
  24. $this->missingPrimaryKeys[] = [
  25. 'tableName' => $tableName,
  26. 'primaryKeyName' => $primaryKeyName,
  27. 'columns' => $columns,
  28. 'formerIndex' => $formerIndex,
  29. ];
  30. }
  31. /**
  32. * @since 28.0.0
  33. * @return array<array-key, array{tableName: string, primaryKeyName: string, columns: string[], formerIndex: null|string}>
  34. */
  35. public function getMissingPrimaryKeys(): array {
  36. return $this->missingPrimaryKeys;
  37. }
  38. }