7171use OCP \AppFramework \Http \DataDisplayResponse ;
7272use OCP \AppFramework \Http \DataResponse ;
7373use OCP \AppFramework \Http \RedirectResponse ;
74+ use OCP \DB \Events \AddMissingIndicesEvent ;
7475use OCP \DB \Types ;
76+ use OCP \EventDispatcher \IEventDispatcher ;
7577use OCP \Http \Client \IClientService ;
7678use OCP \IConfig ;
7779use OCP \IDateTimeFormatter ;
@@ -101,6 +103,8 @@ class CheckSetupController extends Controller {
101103 private $ checker ;
102104 /** @var LoggerInterface */
103105 private $ logger ;
106+ /** @var IEventDispatcher */
107+ private $ eventDispatcher ;
104108 /** @var EventDispatcherInterface */
105109 private $ dispatcher ;
106110 /** @var Connection */
@@ -134,6 +138,7 @@ public function __construct($AppName,
134138 IL10N $ l10n ,
135139 Checker $ checker ,
136140 LoggerInterface $ logger ,
141+ IEventDispatcher $ eventDispatcher ,
137142 EventDispatcherInterface $ dispatcher ,
138143 Connection $ db ,
139144 ILockingProvider $ lockingProvider ,
@@ -154,6 +159,7 @@ public function __construct($AppName,
154159 $ this ->l10n = $ l10n ;
155160 $ this ->checker = $ checker ;
156161 $ this ->logger = $ logger ;
162+ $ this ->eventDispatcher = $ eventDispatcher ;
157163 $ this ->dispatcher = $ dispatcher ;
158164 $ this ->db = $ db ;
159165 $ this ->lockingProvider = $ lockingProvider ;
@@ -550,10 +556,27 @@ protected function hasFreeTypeSupport() {
550556
551557 protected function hasMissingIndexes (): array {
552558 $ indexInfo = new MissingIndexInformation ();
559+
553560 // Dispatch event so apps can also hint for pending index updates if needed
554561 $ event = new GenericEvent ($ indexInfo );
555562 $ this ->dispatcher ->dispatch (IDBConnection::CHECK_MISSING_INDEXES_EVENT , $ event );
556563
564+ $ event = new AddMissingIndicesEvent ();
565+ $ this ->eventDispatcher ->dispatchTyped ($ event );
566+ $ missingIndices = $ event ->getMissingIndices ();
567+
568+ if ($ missingIndices !== []) {
569+ $ schema = new SchemaWrapper (\OCP \Server::get (Connection::class));
570+ foreach ($ missingIndices as $ missingIndex ) {
571+ if ($ schema ->hasTable ($ missingIndex ['tableName ' ])) {
572+ $ table = $ schema ->getTable ($ missingIndex ['tableName ' ]);
573+ if (!$ table ->hasIndex ($ missingIndex ['indexName ' ])) {
574+ $ indexInfo ->addHintForMissingSubject ($ missingIndex ['tableName ' ], $ missingIndex ['indexName ' ]);
575+ }
576+ }
577+ }
578+ }
579+
557580 return $ indexInfo ->getListOfMissingIndexes ();
558581 }
559582
0 commit comments