Jelajahi Sumber

Merge pull request #16507 from nextcloud/bugfix/15416/update_autodisabled_apps

Fix tracking of auto disabled apps in Updater
Roeland Jago Douma 5 tahun lalu
induk
melakukan
9c2d70125a

+ 17 - 1
lib/private/App/AppManager.php

@@ -91,6 +91,9 @@ class AppManager implements IAppManager {
 	/** @var array */
 	private $appVersions = [];
 
+	/** @var array */
+	private $autoDisabledApps = [];
+
 	/**
 	 * @param IUserSession $userSession
 	 * @param AppConfig $appConfig
@@ -167,6 +170,13 @@ class AppManager implements IAppManager {
 		return array_keys($appsForGroups);
 	}
 
+	/**
+	 * @return array
+	 */
+	public function getAutoDisabledApps(): array {
+		return $this->autoDisabledApps;
+	}
+
 	/**
 	 * @param string $appId
 	 * @return array
@@ -351,12 +361,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');
 

+ 3 - 2
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

+ 1 - 3
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);

+ 8 - 1
lib/public/App/IAppManager.php

@@ -110,9 +110,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.
@@ -167,6 +168,12 @@ interface IAppManager {
 	 */
 	public function getEnabledAppsForGroup(IGroup $group): array;
 
+	/**
+	 * @return array
+	 * @since 17.0.0
+	 */
+	public function getAutoDisabledApps(): array;
+
 	/**
 	 * @param String $appId
 	 * @return string[]