mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
committed by
Tony Murray
parent
3b6af60fa6
commit
2e2c329e9c
@@ -1129,9 +1129,9 @@ function scan_new_plugins()
|
|||||||
if (is_dir(Config::get('plugin_dir') . '/' . $name)) {
|
if (is_dir(Config::get('plugin_dir') . '/' . $name)) {
|
||||||
if ($name != '.' && $name != '..') {
|
if ($name != '.' && $name != '..') {
|
||||||
if (is_file(Config::get('plugin_dir') . '/' . $name . '/' . $name . '.php') && is_file(Config::get('plugin_dir') . '/' . $name . '/' . $name . '.inc.php')) {
|
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 (empty($plugin_id)) {
|
||||||
if (dbInsert(array('plugin_name' => $name, 'plugin_active' => '0'), 'plugins')) {
|
if (dbInsert(['plugin_name' => $name, 'plugin_active' => '0'], 'plugins')) {
|
||||||
$installed++;
|
$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)
|
function validate_device_id($id)
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
if (Auth::user()->hasGlobalAdmin()) {
|
if (Auth::user()->hasGlobalAdmin()) {
|
||||||
// Scan for new plugins and add to the database
|
// Scan for new plugins and add to the database
|
||||||
$new_plugins = scan_new_plugins();
|
$new_plugins = scan_new_plugins();
|
||||||
|
$removed_plugins = scan_removed_plugins();
|
||||||
|
|
||||||
|
|
||||||
// Check if we have to toggle enabled / disable a particular module
|
// Check if we have to toggle enabled / disable a particular module
|
||||||
@@ -46,6 +47,13 @@ if ($new_plugins > 0) {
|
|||||||
</div>
|
</div>
|
||||||
</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">
|
<table class="table table-condensed">
|
||||||
<tr>
|
<tr>
|
||||||
|
Reference in New Issue
Block a user