summaryrefslogtreecommitdiffstats
path: root/apps/settings
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-07-14 10:34:09 +0200
committerJulius Härtl <jus@bitgrid.net>2023-07-14 16:29:37 +0200
commit18db96c304c2b2d93c3effc2c1d5b9320fe78ce1 (patch)
tree18696f94169845386bbd3d27f95cbf175458b75f /apps/settings
parent2a18283b824a4b9271d3903c5d5432786846051e (diff)
downloadnextcloud-server-18db96c304c2b2d93c3effc2c1d5b9320fe78ce1.tar.gz
nextcloud-server-18db96c304c2b2d93c3effc2c1d5b9320fe78ce1.zip
feat: Add public event for missing indices
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/settings')
-rw-r--r--apps/settings/lib/Controller/CheckSetupController.php23
-rw-r--r--apps/settings/tests/Controller/CheckSetupControllerTest.php8
2 files changed, 31 insertions, 0 deletions
diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php
index be0abe0d75c..a0c52f6e13d 100644
--- a/apps/settings/lib/Controller/CheckSetupController.php
+++ b/apps/settings/lib/Controller/CheckSetupController.php
@@ -72,7 +72,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;
@@ -102,6 +104,8 @@ class CheckSetupController extends Controller {
private $checker;
/** @var LoggerInterface */
private $logger;
+ /** @var IEventDispatcher */
+ private $eventDispatcher;
/** @var EventDispatcherInterface */
private $dispatcher;
/** @var Connection */
@@ -135,6 +139,7 @@ class CheckSetupController extends Controller {
IL10N $l10n,
Checker $checker,
LoggerInterface $logger,
+ IEventDispatcher $eventDispatcher,
EventDispatcherInterface $dispatcher,
Connection $db,
ILockingProvider $lockingProvider,
@@ -155,6 +160,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;
@@ -551,10 +557,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 2b074d24c39..390166cb947 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,
@@ -676,6 +681,7 @@ class CheckSetupControllerTest extends TestCase {
$this->l10n,
$this->checker,
$this->logger,
+ $this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,
@@ -1440,6 +1446,7 @@ Array
$this->l10n,
$this->checker,
$this->logger,
+ $this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,
@@ -1494,6 +1501,7 @@ Array
$this->l10n,
$this->checker,
$this->logger,
+ $this->eventDispatcher,
$this->dispatcher,
$this->db,
$this->lockingProvider,