From 639ff3dbda0ec2e57b8dd9b9a2a27ec94004f518 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 22 Jul 2019 21:28:03 +0200 Subject: [PATCH] Fix tracking of auto disabled apps in Updater This is a backport of #16507 (fixing #15416) for stable16. Signed-off-by: Kyle Fazzari --- lib/private/App/AppManager.php | 18 +++++++++++++++++- lib/private/Updater.php | 5 +++-- lib/private/legacy/app.php | 4 +--- lib/public/App/IAppManager.php | 9 ++++++++- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 7d4dbbbd34..7709c5ef09 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -86,6 +86,9 @@ class AppManager implements IAppManager { /** @var array */ private $appVersions = []; + /** @var array */ + private $autoDisabledApps = []; + /** * @param IUserSession $userSession * @param AppConfig $appConfig @@ -148,6 +151,13 @@ class AppManager implements IAppManager { return array_keys($appsForUser); } + /** + * @return array + */ + public function getAutoDisabledApps(): array { + return $this->autoDisabledApps; + } + /** * Check if an app is enabled for user * @@ -282,12 +292,18 @@ class AppManager implements IAppManager { * Disable an app for every user * * @param string $appId + * @param bool $automaticDisabled * @throws \Exception if app can't be disabled */ - public function disableApp($appId) { + public function disableApp($appId, $automaticDisabled = false) { if ($this->isAlwaysEnabled($appId)) { throw new \Exception("$appId can't be disabled."); } + + if ($automaticDisabled) { + $this->autoDisabledApps[] = $appId; + } + unset($this->installedAppsCache[$appId]); $this->appConfig->setValue($appId, 'enabled', 'no'); diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 56bea90ddd..d5de1bf6b2 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -256,7 +256,8 @@ class Updater extends BasicEmitter { // upgrade appstore apps $this->upgradeAppStoreApps(\OC::$server->getAppManager()->getInstalledApps()); - $this->upgradeAppStoreApps(\OC_App::$autoDisabledApps, true); + $autoDisabledApps = \OC::$server->getAppManager()->getAutoDisabledApps(); + $this->upgradeAppStoreApps($autoDisabledApps, true); // install new shipped apps on upgrade OC_App::loadApps(['authentication']); @@ -404,7 +405,7 @@ class Updater extends BasicEmitter { if ($appManager->isShipped($app)) { throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update'); } - \OC::$server->getAppManager()->disableApp($app); + \OC::$server->getAppManager()->disableApp($app, true); $this->emit('\OC\Updater', 'incompatibleAppDisabled', array($app)); } // no need to disable any app in case this is a non-core upgrade diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index d495bef2eb..58b617aae4 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -70,7 +70,6 @@ class OC_App { static private $loadedApps = []; static private $altLogin = []; static private $alreadyRegistered = []; - static public $autoDisabledApps = []; const supportedApp = 300; const officialApp = 200; @@ -157,8 +156,7 @@ class OC_App { \OC::$server->getLogger()->logException($ex); if (!\OC::$server->getAppManager()->isShipped($app)) { // Only disable apps which are not shipped - \OC::$server->getAppManager()->disableApp($app); - self::$autoDisabledApps[] = $app; + \OC::$server->getAppManager()->disableApp($app, true); } } \OC::$server->getEventLogger()->end('load_app_' . $app); diff --git a/lib/public/App/IAppManager.php b/lib/public/App/IAppManager.php index b0d04500f3..d061052341 100644 --- a/lib/public/App/IAppManager.php +++ b/lib/public/App/IAppManager.php @@ -109,9 +109,10 @@ interface IAppManager { * Disable an app for every user * * @param string $appId + * @param bool $automaticDisabled * @since 8.0.0 */ - public function disableApp($appId); + public function disableApp($appId, $automaticDisabled = false); /** * Get the directory for the given app. @@ -158,4 +159,10 @@ interface IAppManager { * @since 9.0.0 */ public function getAlwaysEnabledApps(); + + /** + * @return array + * @since 16.0.5 + */ + public function getAutoDisabledApps(): array; }