automatically cleanup plugin-table from removed plugins (#10533)

* automatically cleanup plugin-table from removed plugins

* Update functions.php

* mis-placed bracket
This commit is contained in:
SourceDoctor
2019-08-27 19:47:04 +02:00
committed by Tony Murray
parent 3b6af60fa6
commit 2e2c329e9c
2 changed files with 31 additions and 3 deletions

View File

@@ -1129,9 +1129,9 @@ function scan_new_plugins()
if (is_dir(Config::get('plugin_dir') . '/' . $name)) {
if ($name != '.' && $name != '..') {
if (is_file(Config::get('plugin_dir') . '/' . $name . '/' . $name . '.php') && is_file(Config::get('plugin_dir') . '/' . $name . '/' . $name . '.inc.php')) {
$plugin_id = dbFetchRow("SELECT `plugin_id` FROM `plugins` WHERE `plugin_name` = '$name'");
$plugin_id = dbFetchRow("SELECT `plugin_id` FROM `plugins` WHERE `plugin_name` = ?", [$name]);
if (empty($plugin_id)) {
if (dbInsert(array('plugin_name' => $name, 'plugin_active' => '0'), 'plugins')) {
if (dbInsert(['plugin_name' => $name, 'plugin_active' => '0'], 'plugins')) {
$installed++;
}
}
@@ -1141,7 +1141,27 @@ function scan_new_plugins()
}
}
return( $installed );
return $installed;
}
function scan_removed_plugins()
{
$removed = 0; # Track how many plugins will be removed from database
if (file_exists(Config::get('plugin_dir'))) {
$plugin_files = scandir(Config::get('plugin_dir'));
$installed_plugins = dbFetchColumn("SELECT `plugin_name` FROM `plugins`");
foreach ($installed_plugins as $name) {
if (in_array($name, $plugin_files)) {
continue;
}
if (dbDelete('plugins', "`plugin_name` = ?", $name)) {
$removed++;
}
}
}
return( $removed );
}
function validate_device_id($id)

View File

@@ -3,6 +3,7 @@
if (Auth::user()->hasGlobalAdmin()) {
// Scan for new plugins and add to the database
$new_plugins = scan_new_plugins();
$removed_plugins = scan_removed_plugins();
// Check if we have to toggle enabled / disable a particular module
@@ -46,6 +47,13 @@ if ($new_plugins > 0) {
</div>
</div>';
}
if ($removed_plugins > 0) {
echo '<div class="panel-body">
<div class="alert alert-warning">
We have found '.$removed_plugins.' removed plugins
</div>
</div>';
}
?>
<table class="table table-condensed">
<tr>