Skip to content

Commit 89b06a4

Browse files
authored
Merge pull request #59676 from nextcloud/fix/noid/reinstall-missing-apps-on-upgrade
Restore missing apps on upgrade
2 parents ee40b5b + 7f9fdfb commit 89b06a4

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/private/Updater.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use OC\Repair\Events\RepairStartEvent;
2424
use OC\Repair\Events\RepairStepEvent;
2525
use OC\Repair\Events\RepairWarningEvent;
26+
use OCP\App\AppPathNotFoundException;
2627
use OCP\App\IAppManager;
2728
use OCP\EventDispatcher\Event;
2829
use 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

tests/lib/UpdaterTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OC\Installer;
1212
use OC\IntegrityCheck\Checker;
1313
use OC\Updater;
14+
use OCP\App\AppPathNotFoundException;
1415
use OCP\App\IAppManager;
1516
use OCP\IAppConfig;
1617
use OCP\IConfig;
@@ -107,4 +108,36 @@ public function testIsUpgradePossible($oldVersion, $newVersion, $allowedVersions
107108

108109
$this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersions));
109110
}
111+
112+
public function testUpgradeAppStoreAppsRestoresMissingAutoDisabledAppBeforeEnabling(): void {
113+
$this->installer->expects($this->once())
114+
->method('isUpdateAvailable')
115+
->with('mailroundcube')
116+
->willReturn(false);
117+
118+
$this->installer->expects($this->once())
119+
->method('downloadApp')
120+
->with('mailroundcube');
121+
122+
$this->installer->expects($this->once())
123+
->method('installApp')
124+
->with('mailroundcube');
125+
126+
$this->appManager->expects($this->once())
127+
->method('getAppPath')
128+
->with('mailroundcube', true)
129+
->willThrowException(new AppPathNotFoundException('missing'));
130+
131+
$this->appManager->expects($this->once())
132+
->method('enableApp')
133+
->with('mailroundcube');
134+
135+
$this->appManager->expects($this->never())
136+
->method('enableAppForGroups');
137+
138+
self::invokePrivate($this->updater, 'upgradeAppStoreApps', [
139+
['mailroundcube'],
140+
['mailroundcube' => 'yes'],
141+
]);
142+
}
110143
}

0 commit comments

Comments
 (0)