]> source.dussan.org Git - nextcloud-server.git/commitdiff
Correctly purge the cache when an app is disabled via cli
authorJoas Schilling <nickvergessen@owncloud.com>
Wed, 1 Apr 2015 13:37:22 +0000 (15:37 +0200)
committerJoas Schilling <nickvergessen@owncloud.com>
Wed, 1 Apr 2015 13:43:38 +0000 (15:43 +0200)
lib/private/app/appmanager.php
lib/private/server.php
settings/ajax/disableapp.php
settings/ajax/enableapp.php

index 1cfa0bce25cdf466c86281c80d29c34373861271..c05b2a3b0358c5e0ac5f2d46b33cf0fbc8cd9ef3 100644 (file)
@@ -24,6 +24,7 @@ namespace OC\App;
 
 use OCP\App\IAppManager;
 use OCP\IAppConfig;
+use OCP\ICacheFactory;
 use OCP\IGroupManager;
 use OCP\IUser;
 use OCP\IUserSession;
@@ -44,6 +45,9 @@ class AppManager implements IAppManager {
         */
        private $groupManager;
 
+       /** @var \OCP\ICacheFactory */
+       private $memCacheFactory;
+
        /**
         * @var string[] $appId => $enabled
         */
@@ -54,10 +58,11 @@ class AppManager implements IAppManager {
         * @param \OCP\IAppConfig $appConfig
         * @param \OCP\IGroupManager $groupManager
         */
-       public function __construct(IUserSession $userSession, IAppConfig $appConfig, IGroupManager $groupManager) {
+       public function __construct(IUserSession $userSession, IAppConfig $appConfig, IGroupManager $groupManager, ICacheFactory $memCacheFactory) {
                $this->userSession = $userSession;
                $this->appConfig = $appConfig;
                $this->groupManager = $groupManager;
+               $this->memCacheFactory = $memCacheFactory;
        }
 
        /**
@@ -157,6 +162,7 @@ class AppManager implements IAppManager {
        public function enableApp($appId) {
                $this->installedAppsCache[$appId] = 'yes';
                $this->appConfig->setValue($appId, 'enabled', 'yes');
+               $this->clearAppsCache();
        }
 
        /**
@@ -172,6 +178,7 @@ class AppManager implements IAppManager {
                }, $groups);
                $this->installedAppsCache[$appId] = json_encode($groupIds);
                $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds));
+               $this->clearAppsCache();
        }
 
        /**
@@ -186,5 +193,14 @@ class AppManager implements IAppManager {
                }
                unset($this->installedAppsCache[$appId]);
                $this->appConfig->setValue($appId, 'enabled', 'no');
+               $this->clearAppsCache();
+       }
+
+       /**
+        * Clear the cached list of apps when enabling/disabling an app
+        */
+       protected function clearAppsCache() {
+               $settingsMemCache = $this->memCacheFactory->create('settings');
+               $settingsMemCache->clear('listApps');
        }
 }
index 592f8d9a042ead382a4f2d922daf4306c6894ce7..8c5169f229e39b0fa3992891f3823cfe885a72aa 100644 (file)
@@ -309,10 +309,12 @@ class Server extends SimpleContainer implements IServerContainer {
                        return new TempManager(get_temp_dir(), $c->getLogger());
                });
                $this->registerService('AppManager', function(Server $c) {
-                       $userSession = $c->getUserSession();
-                       $appConfig = $c->getAppConfig();
-                       $groupManager = $c->getGroupManager();
-                       return new \OC\App\AppManager($userSession, $appConfig, $groupManager);
+                       return new \OC\App\AppManager(
+                               $c->getUserSession(),
+                               $c->getAppConfig(),
+                               $c->getGroupManager(),
+                               $c->getMemCacheFactory()
+                       );
                });
                $this->registerService('DateTimeZone', function(Server $c) {
                        return new DateTimeZone(
index cc02203b4a335302aaee2e0391c378469ae8b735..f99969d91a47e1901be6c2ac61fcd1ade4d0ae44 100644 (file)
@@ -31,9 +31,5 @@ if (!array_key_exists('appid', $_POST)) {
 $appId = (string)$_POST['appid'];
 $appId = OC_App::cleanAppId($appId);
 
-// FIXME: Clear the cache - move that into some sane helper method
-\OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-0');
-\OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-1');
-
 OC_App::disable($appId);
 OC_JSON::success();
index aa688c4964c48250937f49a89346d0cdc1dba0f2..b63bce76d92ddf7309239c586cf4da6a7855870b 100644 (file)
@@ -30,9 +30,6 @@ $groups = isset($_POST['groups']) ? (array)$_POST['groups'] : null;
 
 try {
        OC_App::enable(OC_App::cleanAppId((string)$_POST['appid']), $groups);
-       // FIXME: Clear the cache - move that into some sane helper method
-       \OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-0');
-       \OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-1');
        OC_JSON::success();
 } catch (Exception $e) {
        OC_Log::write('core', $e->getMessage(), OC_Log::ERROR);