Disable plugins that have errors (#14383)

* Disable plugins that have errors
Disable plugin if a hook throws an error and set a notification
Move notification code to class, so we can access it
Clear notification when plugin is attempted to be enabled again

* fix style and lint fixes

* another lint fix and handle if property is missing
This commit is contained in:
Tony Murray
2022-09-25 22:47:58 -05:00
committed by GitHub
parent 333ba7c2cd
commit e990dfcb35
9 changed files with 222 additions and 197 deletions

View File

@@ -6,6 +6,7 @@ use App\Models\Plugin;
use App\Plugins\Hooks\SettingsHook;
use App\Plugins\PluginManager;
use Illuminate\Http\Request;
use LibreNMS\Util\Notifications;
class PluginSettingsController extends Controller
{
@@ -31,12 +32,17 @@ class PluginSettingsController extends Controller
public function update(Request $request, Plugin $plugin): \Illuminate\Http\RedirectResponse
{
$validated = $this->validate($request, [
$plugin->fill($this->validate($request, [
'plugin_active' => 'in:0,1',
'settings' => 'array',
]);
]));
$plugin->fill($validated)->save();
if ($plugin->isDirty('plugin_active') && $plugin->plugin_active == 1) {
// enabling plugin delete notifications assuming they are fixed
Notifications::remove("Plugin $plugin->plugin_name disabled");
}
$plugin->save();
return redirect()->back();
}