aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-07-17 11:26:00 +0200
committerGitHub <noreply@github.com>2023-07-17 11:26:00 +0200
commit83f7ea01cd1bd30b2bba5d304ae6c2279f68d6f8 (patch)
tree0e815d5b40fa445e628aa39645e794cfab29e2d9 /apps
parent31f07f31926a061268c28055dbde74f9dc058b6d (diff)
parent18db96c304c2b2d93c3effc2c1d5b9320fe78ce1 (diff)
downloadnextcloud-server-83f7ea01cd1bd30b2bba5d304ae6c2279f68d6f8.tar.gz
nextcloud-server-83f7ea01cd1bd30b2bba5d304ae6c2279f68d6f8.zip
Merge pull request #39396 from nextcloud/backport/39389/stable27
Diffstat (limited to 'apps')
-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,