7272use OCP \AppFramework \Http \DataDisplayResponse ;
7373use OCP \AppFramework \Http \DataResponse ;
7474use OCP \AppFramework \Http \RedirectResponse ;
75+ use OCP \DB \Events \AddMissingIndicesEvent ;
7576use OCP \DB \Types ;
77+ use OCP \EventDispatcher \IEventDispatcher ;
7678use OCP \Http \Client \IClientService ;
7779use OCP \IConfig ;
7880use OCP \IDateTimeFormatter ;
@@ -102,6 +104,8 @@ class CheckSetupController extends Controller {
102104 private $ checker ;
103105 /** @var LoggerInterface */
104106 private $ logger ;
107+ /** @var IEventDispatcher */
108+ private $ eventDispatcher ;
105109 /** @var EventDispatcherInterface */
106110 private $ dispatcher ;
107111 /** @var Connection */
@@ -135,6 +139,7 @@ public function __construct($AppName,
135139 IL10N $ l10n ,
136140 Checker $ checker ,
137141 LoggerInterface $ logger ,
142+ IEventDispatcher $ eventDispatcher ,
138143 EventDispatcherInterface $ dispatcher ,
139144 Connection $ db ,
140145 ILockingProvider $ lockingProvider ,
@@ -155,6 +160,7 @@ public function __construct($AppName,
155160 $ this ->l10n = $ l10n ;
156161 $ this ->checker = $ checker ;
157162 $ this ->logger = $ logger ;
163+ $ this ->eventDispatcher = $ eventDispatcher ;
158164 $ this ->dispatcher = $ dispatcher ;
159165 $ this ->db = $ db ;
160166 $ this ->lockingProvider = $ lockingProvider ;
@@ -551,10 +557,27 @@ protected function hasFreeTypeSupport() {
551557
552558 protected function hasMissingIndexes (): array {
553559 $ indexInfo = new MissingIndexInformation ();
560+
554561 // Dispatch event so apps can also hint for pending index updates if needed
555562 $ event = new GenericEvent ($ indexInfo );
556563 $ this ->dispatcher ->dispatch (IDBConnection::CHECK_MISSING_INDEXES_EVENT , $ event );
557564
565+ $ event = new AddMissingIndicesEvent ();
566+ $ this ->eventDispatcher ->dispatchTyped ($ event );
567+ $ missingIndices = $ event ->getMissingIndices ();
568+
569+ if ($ missingIndices !== []) {
570+ $ schema = new SchemaWrapper (\OCP \Server::get (Connection::class));
571+ foreach ($ missingIndices as $ missingIndex ) {
572+ if ($ schema ->hasTable ($ missingIndex ['tableName ' ])) {
573+ $ table = $ schema ->getTable ($ missingIndex ['tableName ' ]);
574+ if (!$ table ->hasIndex ($ missingIndex ['indexName ' ])) {
575+ $ indexInfo ->addHintForMissingSubject ($ missingIndex ['tableName ' ], $ missingIndex ['indexName ' ]);
576+ }
577+ }
578+ }
579+ }
580+
558581 return $ indexInfo ->getListOfMissingIndexes ();
559582 }
560583
0 commit comments