diff options
author | Julius Härtl <jus@bitgrid.net> | 2023-07-14 10:34:09 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2023-07-14 16:30:36 +0200 |
commit | 32c047267215721344ef1145dc01e5dcc64ca499 (patch) | |
tree | 04f129965d08e579bac95c48476f3c1a84428b9f /apps | |
parent | 2b281a8d607bffc738b2fd4217e105f8e40dbbac (diff) | |
download | nextcloud-server-32c047267215721344ef1145dc01e5dcc64ca499.tar.gz nextcloud-server-32c047267215721344ef1145dc01e5dcc64ca499.zip |
feat: Add public event for missing indices
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/settings/lib/Controller/CheckSetupController.php | 23 | ||||
-rw-r--r-- | apps/settings/tests/Controller/CheckSetupControllerTest.php | 8 |
2 files changed, 31 insertions, 0 deletions
diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index a6f4d7a0d41..aee99310b6a 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -71,7 +71,9 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; +use OCP\DB\Events\AddMissingIndicesEvent; use OCP\DB\Types; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\IDateTimeFormatter; @@ -101,6 +103,8 @@ class CheckSetupController extends Controller { private $checker; /** @var LoggerInterface */ private $logger; + /** @var IEventDispatcher */ + private $eventDispatcher; /** @var EventDispatcherInterface */ private $dispatcher; /** @var Connection */ @@ -134,6 +138,7 @@ class CheckSetupController extends Controller { IL10N $l10n, Checker $checker, LoggerInterface $logger, + IEventDispatcher $eventDispatcher, EventDispatcherInterface $dispatcher, Connection $db, ILockingProvider $lockingProvider, @@ -154,6 +159,7 @@ class CheckSetupController extends Controller { $this->l10n = $l10n; $this->checker = $checker; $this->logger = $logger; + $this->eventDispatcher = $eventDispatcher; $this->dispatcher = $dispatcher; $this->db = $db; $this->lockingProvider = $lockingProvider; @@ -550,10 +556,27 @@ Raw output protected function hasMissingIndexes(): array { $indexInfo = new MissingIndexInformation(); + // Dispatch event so apps can also hint for pending index updates if needed $event = new GenericEvent($indexInfo); $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_INDEXES_EVENT, $event); + $event = new AddMissingIndicesEvent(); + $this->eventDispatcher->dispatchTyped($event); + $missingIndices = $event->getMissingIndices(); + + if ($missingIndices !== []) { + $schema = new SchemaWrapper(\OCP\Server::get(Connection::class)); + foreach ($missingIndices as $missingIndex) { + if ($schema->hasTable($missingIndex['tableName'])) { + $table = $schema->getTable($missingIndex['tableName']); + if (!$table->hasIndex($missingIndex['indexName'])) { + $indexInfo->addHintForMissingSubject($missingIndex['tableName'], $missingIndex['indexName']); + } + } + } + } + return $indexInfo->getListOfMissingIndexes(); } diff --git a/apps/settings/tests/Controller/CheckSetupControllerTest.php b/apps/settings/tests/Controller/CheckSetupControllerTest.php index 81aa7af0b21..f290a4689e5 100644 --- a/apps/settings/tests/Controller/CheckSetupControllerTest.php +++ b/apps/settings/tests/Controller/CheckSetupControllerTest.php @@ -47,6 +47,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Http\Client\IClientService; use OCP\IConfig; use OCP\IDateTimeFormatter; @@ -87,6 +88,8 @@ class CheckSetupControllerTest extends TestCase { private $logger; /** @var Checker|\PHPUnit\Framework\MockObject\MockObject */ private $checker; + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ + private $eventDispatcher; /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */ private $dispatcher; /** @var Connection|\PHPUnit\Framework\MockObject\MockObject */ @@ -137,6 +140,7 @@ class CheckSetupControllerTest extends TestCase { ->willReturnCallback(function ($message, array $replace) { return vsprintf($message, $replace); }); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class) ->disableOriginalConstructor()->getMock(); $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') @@ -167,6 +171,7 @@ class CheckSetupControllerTest extends TestCase { $this->l10n, $this->checker, $this->logger, + $this->eventDispatcher, $this->dispatcher, $this->db, $this->lockingProvider, @@ -670,6 +675,7 @@ class CheckSetupControllerTest extends TestCase { $this->l10n, $this->checker, $this->logger, + $this->eventDispatcher, $this->dispatcher, $this->db, $this->lockingProvider, @@ -1434,6 +1440,7 @@ Array $this->l10n, $this->checker, $this->logger, + $this->eventDispatcher, $this->dispatcher, $this->db, $this->lockingProvider, @@ -1488,6 +1495,7 @@ Array $this->l10n, $this->checker, $this->logger, + $this->eventDispatcher, $this->dispatcher, $this->db, $this->lockingProvider, |