]> git.mxchange.org Git - friendica.git/commitdiff
Fix uninstall of installed addons
authorMichael <heluecht@pirati.ca>
Mon, 9 Mar 2020 23:28:37 +0000 (23:28 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 9 Mar 2020 23:28:37 +0000 (23:28 +0000)
src/Core/Addon.php
src/Model/Nodeinfo.php
src/Module/Admin/Addons/Details.php
update.php

index be4e94152f44f8e9dd4c99bcea5bc59f736e246e..3dd28af44bf8ea25077013c4b1378a5e303a528f 100644 (file)
@@ -112,37 +112,14 @@ class Addon
         */
        public static function loadAddons()
        {
-               $installed_addons = [];
+               $installed_addons = DBA::selectToArray('addon', ['name'], ['installed' => true]);
 
-               $r = DBA::select('addon', [], ['installed' => 1]);
-               if (DBA::isResult($r)) {
-                       $installed_addons = DBA::toArray($r);
-               }
-
-               $addons = DI::config()->get('system', 'addon');
                $addons_arr = [];
-
-               if ($addons) {
-                       $addons_arr = explode(',', str_replace(' ', '', $addons));
-               }
-
-               self::$addons = $addons_arr;
-
-               $installed_arr = [];
-
                foreach ($installed_addons as $addon) {
-                       if (!self::isEnabled($addon['name'])) {
-                               self::uninstall($addon['name']);
-                       } else {
-                               $installed_arr[] = $addon['name'];
-                       }
+                       $addons_arr[] = $addon['name'];
                }
 
-               foreach (self::$addons as $p) {
-                       if (!in_array($p, $installed_arr)) {
-                               self::install($p);
-                       }
-               }
+               self::$addons = $addons_arr;
        }
 
        /**
@@ -168,8 +145,6 @@ class Addon
                DBA::delete('hook', ['file' => 'addon/' . $addon . '/' . $addon . '.php']);
 
                unset(self::$addons[array_search($addon, self::$addons)]);
-
-               Addon::saveEnabledList();
        }
 
        /**
@@ -212,8 +187,6 @@ class Addon
                                self::$addons[] = $addon;
                        }
 
-                       Addon::saveEnabledList();
-
                        return true;
                } else {
                        Logger::error("Addon {addon}: {action} failed", ['action' => 'install', 'addon' => $addon]);
@@ -226,38 +199,33 @@ class Addon
         */
        public static function reload()
        {
-               $addons = DI::config()->get('system', 'addon');
-               if (strlen($addons)) {
-                       $r = DBA::select('addon', [], ['installed' => 1]);
-                       if (DBA::isResult($r)) {
-                               $installed = DBA::toArray($r);
-                       } else {
-                               $installed = [];
-                       }
+               $installed = DBA::selectToArray('addon', [], ['installed' => 1]);
+
+               $addon_list = [];
+               foreach ($installed as $addon) {
+                       $addon_list[] = $addon['name'];
+               }
+
+               foreach ($addon_list as $addon) {
+                       $addon = Strings::sanitizeFilePathItem(trim($addon));
+                       $fname = 'addon/' . $addon . '/' . $addon . '.php';
+                       if (file_exists($fname)) {
+                               $t = @filemtime($fname);
+                               foreach ($installed as $i) {
+                                       if (($i['name'] == $addon) && ($i['timestamp'] != $t)) {
 
-                       $addon_list = explode(',', $addons);
-
-                       foreach ($addon_list as $addon) {
-                               $addon = Strings::sanitizeFilePathItem(trim($addon));
-                               $fname = 'addon/' . $addon . '/' . $addon . '.php';
-                               if (file_exists($fname)) {
-                                       $t = @filemtime($fname);
-                                       foreach ($installed as $i) {
-                                               if (($i['name'] == $addon) && ($i['timestamp'] != $t)) {
-
-                                                       Logger::notice("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $i['name']]);
-                                                       @include_once($fname);
-
-                                                       if (function_exists($addon . '_uninstall')) {
-                                                               $func = $addon . '_uninstall';
-                                                               $func(DI::app());
-                                                       }
-                                                       if (function_exists($addon . '_install')) {
-                                                               $func = $addon . '_install';
-                                                               $func(DI::app());
-                                                       }
-                                                       DBA::update('addon', ['timestamp' => $t], ['id' => $i['id']]);
+                                               Logger::notice("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $i['name']]);
+                                               @include_once($fname);
+
+                                               if (function_exists($addon . '_uninstall')) {
+                                                       $func = $addon . '_uninstall';
+                                                       $func(DI::app());
+                                               }
+                                               if (function_exists($addon . '_install')) {
+                                                       $func = $addon . '_install';
+                                                       $func(DI::app());
                                                }
+                                               DBA::update('addon', ['timestamp' => $t], ['id' => $i['id']]);
                                        }
                                }
                        }
@@ -357,16 +325,6 @@ class Addon
                return self::$addons;
        }
 
-       /**
-        * Saves the current enabled addon list in the system.addon config key
-        *
-        * @return boolean
-        */
-       public static function saveEnabledList()
-       {
-               return DI::config()->set('system', 'addon', implode(',', self::$addons));
-       }
-
        /**
         * Returns the list of non-hidden enabled addon names
         *
index d39641553114acc8fa527b36f40457a5b6504e80..d2e168fa5961788641f32905e84fe7a7158ec8b8 100644 (file)
@@ -43,20 +43,7 @@ class Nodeinfo
                // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
                if (Addon::isEnabled('statistics_json')) {
                        $config->set('system', 'nodeinfo', true);
-
-                       $addon = 'statistics_json';
-                       $addons = $config->get('system', 'addon');
-
-                       if ($addons) {
-                               $addons_arr = explode(',', str_replace(' ', '', $addons));
-
-                               $idx = array_search($addon, $addons_arr);
-                               if ($idx !== false) {
-                                       unset($addons_arr[$idx]);
-                                       Addon::uninstall($addon);
-                                       $config->set('system', 'addon', implode(', ', $addons_arr));
-                               }
-                       }
+                       Addon::uninstall('statistics_json');
                }
 
                if (empty($config->get('system', 'nodeinfo'))) {
index dba2f061ce058469a52caa9bd8d68a846825d1f2..8e0e14f22b805b1f12279caa970014b0cac1db94 100644 (file)
@@ -84,8 +84,6 @@ class Details extends BaseAdmin
                                        info(DI::l10n()->t('Addon %s enabled.', $addon));
                                }
 
-                               Addon::saveEnabledList();
-
                                DI::baseUrl()->redirect('admin/addons/' . $addon);
                        }
 
index 314b166e727045d514a5bd538b7f7603790428f7..107368ea0fa4bcea472a6392f55ed63d155cb183 100644 (file)
@@ -92,23 +92,10 @@ function update_1191()
        DI::config()->set('system', 'maintenance', 1);
 
        if (Addon::isEnabled('forumlist')) {
-               $addon = 'forumlist';
-               $addons = DI::config()->get('system', 'addon');
-               $addons_arr = [];
-
-               if ($addons) {
-                       $addons_arr = explode(",", str_replace(" ", "", $addons));
-
-                       $idx = array_search($addon, $addons_arr);
-                       if ($idx !== false) {
-                               unset($addons_arr[$idx]);
-                               //delete forumlist manually from addon and hook table
-                               // since Addon::uninstall() don't work here
-                               q("DELETE FROM `addon` WHERE `name` = 'forumlist' ");
-                               q("DELETE FROM `hook` WHERE `file` = 'addon/forumlist/forumlist.php' ");
-                               DI::config()->set('system', 'addon', implode(", ", $addons_arr));
-                       }
-               }
+               //delete forumlist manually from addon and hook table
+               // since Addon::uninstall() don't work here
+               DBA::delete('addon', ['name' => 'forumlist']);
+               DBA::delete('hook', ['file' => 'addon/forumlist/forumlist.php']);
        }
 
        // select old formlist addon entries