Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/private/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OC\Repair\Events\RepairStartEvent;
use OC\Repair\Events\RepairStepEvent;
use OC\Repair\Events\RepairWarningEvent;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
Expand Down Expand Up @@ -390,6 +391,8 @@ private function upgradeAppStoreApps(array $apps, array $previousEnableStates =
$this->emit('\OC\Updater', 'checkAppStoreApp', [$app]);

if (isset($previousEnableStates[$app])) {
$this->restoreMissingAppStoreApp($app);

if (!empty($previousEnableStates[$app]) && is_array($previousEnableStates[$app])) {
$this->appManager->enableAppForGroups($app, $previousEnableStates[$app]);
} elseif ($previousEnableStates[$app] === 'yes') {
Expand All @@ -404,6 +407,17 @@ private function upgradeAppStoreApps(array $apps, array $previousEnableStates =
}
}

private function restoreMissingAppStoreApp(string $appId): void {
try {
$this->appManager->getAppPath($appId, true);
} catch (AppPathNotFoundException) {
// the app was not found locally but we know it was previously enabled
// so we automatically download it from the appstore and run its missing migrations
$this->installer->downloadApp($appId);
$this->installer->installApp($appId);
}
}

private function logAllEvents(): void {
$log = $this->log;

Expand Down
33 changes: 33 additions & 0 deletions tests/lib/UpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OC\Installer;
use OC\IntegrityCheck\Checker;
use OC\Updater;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\IConfig;
Expand Down Expand Up @@ -107,4 +108,36 @@ public function testIsUpgradePossible($oldVersion, $newVersion, $allowedVersions

$this->assertSame($result, $this->updater->isUpgradePossible($oldVersion, $newVersion, $allowedVersions));
}

public function testUpgradeAppStoreAppsRestoresMissingAutoDisabledAppBeforeEnabling(): void {
$this->installer->expects($this->once())
->method('isUpdateAvailable')
->with('mailroundcube')
->willReturn(false);

$this->installer->expects($this->once())
->method('downloadApp')
->with('mailroundcube');

$this->installer->expects($this->once())
->method('installApp')
->with('mailroundcube');

$this->appManager->expects($this->once())
->method('getAppPath')
->with('mailroundcube', true)
->willThrowException(new AppPathNotFoundException('missing'));

$this->appManager->expects($this->once())
->method('enableApp')
->with('mailroundcube');

$this->appManager->expects($this->never())
->method('enableAppForGroups');

self::invokePrivate($this->updater, 'upgradeAppStoreApps', [
['mailroundcube'],
['mailroundcube' => 'yes'],
]);
}
}
Loading