add basic local plugin uninstaller

master
Andrew Dolgov 4 years ago
parent dfdb746a76
commit 0cb719a404

@ -623,4 +623,10 @@ class PluginHost {
user_error("get_public_method_url: requested method '$method' of '" . get_class($sender) . "' is private.");
}
}
function is_local(Plugin $plugin) {
$ref = new ReflectionClass(get_class($plugin));
return basename(dirname(dirname($ref->getFileName()))) == "plugins.local";
}
}

@ -796,6 +796,7 @@ class Pref_Prefs extends Handler_Protected {
foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
$about = $plugin->about();
$is_local = $tmppluginhost->is_local($plugin);
$version = htmlspecialchars($this->_get_plugin_version($plugin));
if ($about[3] ?? false) {
@ -822,6 +823,14 @@ class Pref_Prefs extends Handler_Protected {
<i class='material-icons'>open_in_new</i> <?= __("More info...") ?></button>
<?php } ?>
<?php if ($_SESSION["access_level"] >= 10 && $is_local) { ?>
<button dojoType='dijit.form.Button'
onclick='Helpers.Plugins.uninstall("<?= htmlspecialchars($name) ?>")'>
<?= \Controls\icon("delete") ?>
<?= __("Uninstall") ?>
</button>
<?php } ?>
<?php if ($version) { ?>
<div dojoType='dijit.Tooltip' connectId='PLABEL-<?= htmlspecialchars($name) ?>' position='after'>
<?= $version ?>
@ -842,6 +851,7 @@ class Pref_Prefs extends Handler_Protected {
foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
$about = $plugin->about();
$is_local = $tmppluginhost->is_local($plugin);
$version = htmlspecialchars($this->_get_plugin_version($plugin));
if (empty($about[3]) || $about[3] == false) {
@ -889,6 +899,14 @@ class Pref_Prefs extends Handler_Protected {
<i class='material-icons'>open_in_new</i> <?= __("More info...") ?></button>
<?php } ?>
<?php if ($_SESSION["access_level"] >= 10 && $is_local) { ?>
<button dojoType='dijit.form.Button'
onclick='Helpers.Plugins.uninstall("<?= htmlspecialchars($name) ?>")'>
<?= \Controls\icon("delete") ?>
<?= __("Uninstall") ?>
</button>
<?php } ?>
<?php if ($version) { ?>
<div dojoType='dijit.Tooltip' connectId='PLABEL-<?= htmlspecialchars($name) ?>' position='after'>
<?= $version ?>
@ -1235,9 +1253,24 @@ class Pref_Prefs extends Handler_Protected {
}
}
function uninstallPlugin() {
if ($_SESSION["access_level"] >= 10) {
$plugin_name = basename(clean($_REQUEST['plugin']));
$status = 0;
$plugin_dir = dirname(dirname(__DIR__)) . "/plugins.local/$plugin_name";
if (is_dir($plugin_dir)) {
$status = $this->_recursive_rmdir($plugin_dir);
}
print json_encode(['status' => $status]);
}
}
function installPlugin() {
if ($_SESSION["access_level"] >= 10 && Config::get(Config::ENABLE_PLUGIN_INSTALLER)) {
$plugin_name = clean($_REQUEST['plugin']);
$plugin_name = basename(clean($_REQUEST['plugin']));
$all_plugins = $this->_get_available_plugins();
$plugin_dir = dirname(dirname(__DIR__)) . "/plugins.local";

@ -349,6 +349,22 @@ const Helpers = {
}
});
},
uninstall: function(plugin) {
const msg = __("Uninstall plugin %s?").replace("%s", plugin);
if (confirm(msg)) {
Notify.progress("Loading, please wait...");
xhr.json("backend.php", {op: "pref-prefs", method: "uninstallPlugin", plugin: plugin}, (reply) => {
if (reply && reply.status == 1)
Helpers.Prefs.refresh();
else {
Notify.error("Plugin uninstallation failed.");
}
});
}
},
install: function() {
const dialog = new fox.SingleUseDialog({
PI_RES_ALREADY_INSTALLED: "PI_RES_ALREADY_INSTALLED",

Loading…
Cancel
Save