fix(plugin): auto-remove plugin record if class file is missing

This commit is contained in:
xboard
2025-07-12 21:54:12 +08:00
parent 1bb1e032d6
commit 328461b093
+6 -2
View File
@@ -8,6 +8,7 @@ use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
@@ -51,13 +52,15 @@ class PluginManager
if (!class_exists($pluginClass)) { if (!class_exists($pluginClass)) {
$pluginFile = $this->getPluginPath($pluginCode) . '/Plugin.php'; $pluginFile = $this->getPluginPath($pluginCode) . '/Plugin.php';
if (!File::exists($pluginFile)) { if (!File::exists($pluginFile)) {
throw new \Exception("Plugin class file not found: {$pluginFile}"); Log::error("Plugin class file not found: {$pluginFile}");
return null;
} }
require_once $pluginFile; require_once $pluginFile;
} }
if (!class_exists($pluginClass)) { if (!class_exists($pluginClass)) {
throw new \Exception("Plugin class not found: {$pluginClass}"); Log::error("Plugin class not found: {$pluginClass}");
return null;
} }
$plugin = new $pluginClass($pluginCode); $plugin = new $pluginClass($pluginCode);
@@ -265,6 +268,7 @@ class PluginManager
$plugin = $this->loadPlugin($pluginCode); $plugin = $this->loadPlugin($pluginCode);
if (!$plugin) { if (!$plugin) {
Plugin::where('code', $pluginCode)->delete();
throw new \Exception('Plugin not found: ' . $pluginCode); throw new \Exception('Plugin not found: ' . $pluginCode);
} }