Merge pull request #8397 from annando/addon-concurrent

Fix uninstall of installed addons
This commit is contained in:
Hypolite Petovan 2020-03-10 16:13:14 -04:00 committed by GitHub
commit 89121b869c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 109 deletions

View file

@ -112,37 +112,8 @@ class Addon
*/ */
public static function loadAddons() public static function loadAddons()
{ {
$installed_addons = []; $installed_addons = DBA::selectToArray('addon', ['name'], ['installed' => true]);
self::$addons = array_column($installed_addons, 'name');
$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'];
}
}
foreach (self::$addons as $p) {
if (!in_array($p, $installed_arr)) {
self::install($p);
}
}
} }
/** /**
@ -168,8 +139,6 @@ class Addon
DBA::delete('hook', ['file' => 'addon/' . $addon . '/' . $addon . '.php']); DBA::delete('hook', ['file' => 'addon/' . $addon . '/' . $addon . '.php']);
unset(self::$addons[array_search($addon, self::$addons)]); unset(self::$addons[array_search($addon, self::$addons)]);
Addon::saveEnabledList();
} }
/** /**
@ -212,8 +181,6 @@ class Addon
self::$addons[] = $addon; self::$addons[] = $addon;
} }
Addon::saveEnabledList();
return true; return true;
} else { } else {
Logger::error("Addon {addon}: {action} failed", ['action' => 'install', 'addon' => $addon]); Logger::error("Addon {addon}: {action} failed", ['action' => 'install', 'addon' => $addon]);
@ -226,41 +193,28 @@ class Addon
*/ */
public static function reload() public static function reload()
{ {
$addons = DI::config()->get('system', 'addon'); $addons = DBA::selectToArray('addon', [], ['installed' => true]);
if (strlen($addons)) {
$r = DBA::select('addon', [], ['installed' => 1]); foreach ($addons as $addon) {
if (DBA::isResult($r)) { $addonname = Strings::sanitizeFilePathItem(trim($addon['name']));
$installed = DBA::toArray($r); $fname = 'addon/' . $addonname . '/' . $addonname . '.php';
} else { $t = @filemtime($fname);
$installed = []; if (!file_exists($fname) || ($addon['timestamp'] == $t)) {
continue;
} }
$addon_list = explode(',', $addons); Logger::notice("Addon {addon}: {action}", ['action' => 'reload', 'addon' => $addon['name']]);
@include_once($fname);
foreach ($addon_list as $addon) { if (function_exists($addonname . '_uninstall')) {
$addon = Strings::sanitizeFilePathItem(trim($addon)); $func = $addonname . '_uninstall';
$fname = 'addon/' . $addon . '/' . $addon . '.php'; $func(DI::app());
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']]);
}
}
}
} }
if (function_exists($addonname . '_install')) {
$func = $addonname . '_install';
$func(DI::app());
}
DBA::update('addon', ['timestamp' => $t], ['id' => $addon['id']]);
} }
} }
@ -357,16 +311,6 @@ class Addon
return self::$addons; 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 * Returns the list of non-hidden enabled addon names
* *

View file

@ -43,20 +43,7 @@ class Nodeinfo
// If the addon 'statistics_json' is enabled then disable it and activate nodeinfo. // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
if (Addon::isEnabled('statistics_json')) { if (Addon::isEnabled('statistics_json')) {
$config->set('system', 'nodeinfo', true); $config->set('system', 'nodeinfo', true);
Addon::uninstall('statistics_json');
$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));
}
}
} }
if (empty($config->get('system', 'nodeinfo'))) { if (empty($config->get('system', 'nodeinfo'))) {

View file

@ -84,8 +84,6 @@ class Details extends BaseAdmin
info(DI::l10n()->t('Addon %s enabled.', $addon)); info(DI::l10n()->t('Addon %s enabled.', $addon));
} }
Addon::saveEnabledList();
DI::baseUrl()->redirect('admin/addons/' . $addon); DI::baseUrl()->redirect('admin/addons/' . $addon);
} }

View file

@ -92,23 +92,7 @@ function update_1191()
DI::config()->set('system', 'maintenance', 1); DI::config()->set('system', 'maintenance', 1);
if (Addon::isEnabled('forumlist')) { if (Addon::isEnabled('forumlist')) {
$addon = 'forumlist'; Addon::uninstall('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));
}
}
} }
// select old formlist addon entries // select old formlist addon entries