]> source.dussan.org Git - nextcloud-server.git/commitdiff
attempt to remove section and settings entries when an app got disabled
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Mon, 15 Aug 2016 18:03:19 +0000 (20:03 +0200)
committerLukas Reschke <lukas@statuscode.ch>
Tue, 16 Aug 2016 19:10:54 +0000 (21:10 +0200)
lib/base.php
lib/private/Settings/Manager.php
lib/public/Settings/IManager.php

index d22490ca5dc7e96c2f1d3641e8cfb9de734c0db4..1b53282fb9115e09c9f5a31bf5c0ec52f2ce5c1d 100644 (file)
@@ -723,6 +723,7 @@ class OC {
                self::registerLogRotate();
                self::registerEncryptionWrapper();
                self::registerEncryptionHooks();
+               self::registerSettingsHooks();
 
                //make sure temporary files are cleaned up
                $tmpManager = \OC::$server->getTempManager();
@@ -801,6 +802,14 @@ class OC {
                }
        }
 
+       public static function registerSettingsHooks() {
+               $dispatcher = \OC::$server->getEventDispatcher();
+               $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_DISABLE, function($event) {
+                       /** @var \OCP\App\ManagerEvent $event */
+                       \OC::$server->getSettingsManager()->onAppDisabled($event->getAppID());
+               });
+       }
+
        private static function registerEncryptionWrapper() {
                $manager = self::$server->getEncryptionManager();
                \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage');
index 1304a60949e7a2a17645d94fc4e638f3262ef5db..8fdc7fefbb3acc63e4aa3cb63de047990c788203 100644 (file)
@@ -93,6 +93,25 @@ class Manager implements IManager {
                }
        }
 
+       /**
+        * attempts to remove an apps section and/or settings entry. A listener is
+        * added centrally making sure that this method is called ones an app was
+        * disabled.
+        *
+        * @param string $appId
+        * @since 9.1.0
+        */
+       public function onAppDisabled($appId) {
+               $appInfo = \OC_App::getAppInfo($appId); // hello static legacy
+
+               if(isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) {
+                       $this->remove(self::TABLE_ADMIN_SECTIONS, $appInfo['settings'][IManager::KEY_ADMIN_SECTION]);
+               }
+               if(isset($settings['settings'][IManager::KEY_ADMIN_SETTINGS])) {
+                       $this->remove(self::TABLE_ADMIN_SETTINGS, $appInfo['settings'][IManager::KEY_ADMIN_SETTINGS]);
+               }
+       }
+
        /**
         * @param string $sectionClassName
         */
@@ -222,6 +241,20 @@ class Manager implements IManager {
                return (bool) $row;
        }
 
+       /**
+        * deletes an settings or admin entry from the given table
+        *
+        * @param $table
+        * @param $className
+        */
+       private function remove($table, $className) {
+               $query = $this->dbc->getQueryBuilder();
+               $query->delete($table)
+                       ->where($query->expr()->eq('class', $query->createNamedParameter($className)));
+
+               $query->execute();
+       }
+
        private function setupAdminSettings($settingsClassName) {
                if(!class_exists($settingsClassName)) {
                        $this->log->debug('Could not find admin section class ' . $settingsClassName);
index 8aa7a9ac2488cffdb6c74693feffa69fe32ecb04..cba4efbd0370955e2b8a46f59c30a138cd98ca23 100644 (file)
@@ -50,6 +50,20 @@ interface IManager {
         */
        public function setupSettings(array $settings);
 
+       /**
+        * attempts to remove an apps section and/or settings entry. A listener is
+        * added centrally making sure that this method is called ones an app was
+        * disabled.
+        *
+        * What this does not help with is when applications change their settings
+        * or section classes during their life time. New entries will be added,
+        * but inactive ones will still reside in the database.
+        *
+        * @param string $appId
+        * @since 9.1.0
+        */
+       public function onAppDisabled($appId);
+
        /**
         * returns a list of the admin sections
         *