2323use OC \Repair \Events \RepairStartEvent ;
2424use OC \Repair \Events \RepairStepEvent ;
2525use OC \Repair \Events \RepairWarningEvent ;
26+ use OCP \App \AppPathNotFoundException ;
2627use OCP \App \IAppManager ;
2728use OCP \EventDispatcher \Event ;
2829use OCP \EventDispatcher \IEventDispatcher ;
@@ -391,6 +392,8 @@ private function upgradeAppStoreApps(array $apps, array $previousEnableStates =
391392 $ this ->emit ('\OC\Updater ' , 'checkAppStoreApp ' , [$ app ]);
392393
393394 if (isset ($ previousEnableStates [$ app ])) {
395+ $ this ->restoreMissingAppStoreApp ($ app );
396+
394397 if (!empty ($ previousEnableStates [$ app ]) && is_array ($ previousEnableStates [$ app ])) {
395398 $ this ->appManager ->enableAppForGroups ($ app , $ previousEnableStates [$ app ]);
396399 } elseif ($ previousEnableStates [$ app ] === 'yes ' ) {
@@ -405,6 +408,17 @@ private function upgradeAppStoreApps(array $apps, array $previousEnableStates =
405408 }
406409 }
407410
411+ private function restoreMissingAppStoreApp (string $ appId ): void {
412+ try {
413+ $ this ->appManager ->getAppPath ($ appId , true );
414+ } catch (AppPathNotFoundException ) {
415+ // the app was not found locally but we know it was previously enabled
416+ // so we automatically download it from the appstore and run its missing migrations
417+ $ this ->installer ->downloadApp ($ appId );
418+ $ this ->installer ->installApp ($ appId );
419+ }
420+ }
421+
408422 private function logAllEvents (): void {
409423 $ log = $ this ->log ;
410424
0 commit comments