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 ;
@@ -390,6 +391,8 @@ private function upgradeAppStoreApps(array $apps, array $previousEnableStates =
390391 $ this ->emit ('\OC\Updater ' , 'checkAppStoreApp ' , [$ app ]);
391392
392393 if (isset ($ previousEnableStates [$ app ])) {
394+ $ this ->restoreMissingAppStoreApp ($ app );
395+
393396 if (!empty ($ previousEnableStates [$ app ]) && is_array ($ previousEnableStates [$ app ])) {
394397 $ this ->appManager ->enableAppForGroups ($ app , $ previousEnableStates [$ app ]);
395398 } elseif ($ previousEnableStates [$ app ] === 'yes ' ) {
@@ -404,6 +407,17 @@ private function upgradeAppStoreApps(array $apps, array $previousEnableStates =
404407 }
405408 }
406409
410+ private function restoreMissingAppStoreApp (string $ appId ): void {
411+ try {
412+ $ this ->appManager ->getAppPath ($ appId , true );
413+ } catch (AppPathNotFoundException ) {
414+ // the app was not found locally but we know it was previously enabled
415+ // so we automatically download it from the appstore and run its missing migrations
416+ $ this ->installer ->downloadApp ($ appId );
417+ $ this ->installer ->installApp ($ appId );
418+ }
419+ }
420+
407421 private function logAllEvents (): void {
408422 $ log = $ this ->log ;
409423
0 commit comments