7474use OCP \AppFramework \Http \DataDisplayResponse ;
7575use OCP \AppFramework \Http \DataResponse ;
7676use OCP \AppFramework \Http \RedirectResponse ;
77+ use OCP \DB \Events \AddMissingIndicesEvent ;
7778use OCP \DB \Types ;
79+ use OCP \EventDispatcher \IEventDispatcher ;
7880use OCP \Http \Client \IClientService ;
7981use OCP \IConfig ;
8082use OCP \IDateTimeFormatter ;
@@ -105,6 +107,8 @@ class CheckSetupController extends Controller {
105107 private $ checker ;
106108 /** @var LoggerInterface */
107109 private $ logger ;
110+ /** @var IEventDispatcher */
111+ private $ eventDispatcher ;
108112 /** @var EventDispatcherInterface */
109113 private $ dispatcher ;
110114 /** @var Connection */
@@ -138,6 +142,7 @@ public function __construct($AppName,
138142 IL10N $ l10n ,
139143 Checker $ checker ,
140144 LoggerInterface $ logger ,
145+ IEventDispatcher $ eventDispatcher ,
141146 EventDispatcherInterface $ dispatcher ,
142147 Connection $ db ,
143148 ILockingProvider $ lockingProvider ,
@@ -158,6 +163,7 @@ public function __construct($AppName,
158163 $ this ->l10n = $ l10n ;
159164 $ this ->checker = $ checker ;
160165 $ this ->logger = $ logger ;
166+ $ this ->eventDispatcher = $ eventDispatcher ;
161167 $ this ->dispatcher = $ dispatcher ;
162168 $ this ->db = $ db ;
163169 $ this ->lockingProvider = $ lockingProvider ;
@@ -543,10 +549,27 @@ protected function hasFreeTypeSupport() {
543549
544550 protected function hasMissingIndexes (): array {
545551 $ indexInfo = new MissingIndexInformation ();
552+
546553 // Dispatch event so apps can also hint for pending index updates if needed
547554 $ event = new GenericEvent ($ indexInfo );
548555 $ this ->dispatcher ->dispatch (IDBConnection::CHECK_MISSING_INDEXES_EVENT , $ event );
549556
557+ $ event = new AddMissingIndicesEvent ();
558+ $ this ->eventDispatcher ->dispatchTyped ($ event );
559+ $ missingIndices = $ event ->getMissingIndices ();
560+
561+ if ($ missingIndices !== []) {
562+ $ schema = new SchemaWrapper (\OCP \Server::get (Connection::class));
563+ foreach ($ missingIndices as $ missingIndex ) {
564+ if ($ schema ->hasTable ($ missingIndex ['tableName ' ])) {
565+ $ table = $ schema ->getTable ($ missingIndex ['tableName ' ]);
566+ if (!$ table ->hasIndex ($ missingIndex ['indexName ' ])) {
567+ $ indexInfo ->addHintForMissingSubject ($ missingIndex ['tableName ' ], $ missingIndex ['indexName ' ]);
568+ }
569+ }
570+ }
571+ }
572+
550573 return $ indexInfo ->getListOfMissingIndexes ();
551574 }
552575
0 commit comments