Set plugin status to "errored" if it errored (#2084)

This commit is contained in:
Boy132
2026-01-08 17:43:31 +01:00
committed by GitHub
parent bd012f52a9
commit 3b24e22316

View File

@@ -285,62 +285,74 @@ class PluginService
/** @throws Exception */
public function installPlugin(Plugin $plugin, bool $enable = true): void
{
$this->manageComposerPackages(json_decode($plugin->composer_packages, true, 512));
try {
$this->manageComposerPackages(json_decode($plugin->composer_packages, true, 512));
if ($enable) {
$this->enablePlugin($plugin);
} else {
if ($plugin->status === PluginStatus::NotInstalled) {
$this->disablePlugin($plugin);
if ($enable) {
$this->enablePlugin($plugin);
} else {
if ($plugin->status === PluginStatus::NotInstalled) {
$this->disablePlugin($plugin);
}
}
}
$this->buildAssets();
$this->buildAssets();
$this->runPluginMigrations($plugin);
$this->runPluginMigrations($plugin);
$this->runPluginSeeder($plugin);
$this->runPluginSeeder($plugin);
foreach (Filament::getPanels() as $panel) {
$panel->clearCachedComponents();
foreach (Filament::getPanels() as $panel) {
$panel->clearCachedComponents();
}
} catch (Exception $exception) {
$this->handlePluginException($plugin, $exception, true);
}
}
/** @throws Exception */
public function updatePlugin(Plugin $plugin): void
{
$downloadUrl = $plugin->getDownloadUrlForUpdate();
if (!$downloadUrl) {
throw new Exception('No download url found.');
try {
$downloadUrl = $plugin->getDownloadUrlForUpdate();
if (!$downloadUrl) {
throw new Exception('No download url found.');
}
$this->downloadPluginFromUrl($downloadUrl, true);
$this->installPlugin($plugin, false);
cache()->forget("plugins.$plugin->id.update");
} catch (Exception $exception) {
$this->handlePluginException($plugin, $exception, true);
}
$this->downloadPluginFromUrl($downloadUrl, true);
$this->installPlugin($plugin, false);
cache()->forget("plugins.$plugin->id.update");
}
/** @throws Exception */
public function uninstallPlugin(Plugin $plugin, bool $deleteFiles = false): void
{
$pluginPackages = json_decode($plugin->composer_packages, true, 512);
try {
$pluginPackages = json_decode($plugin->composer_packages, true, 512);
$this->rollbackPluginMigrations($plugin);
$this->rollbackPluginMigrations($plugin);
if ($deleteFiles) {
$this->deletePlugin($plugin);
} else {
$this->setStatus($plugin, PluginStatus::NotInstalled);
}
if ($deleteFiles) {
$this->deletePlugin($plugin);
} else {
$this->setStatus($plugin, PluginStatus::NotInstalled);
}
$this->buildAssets();
$this->buildAssets();
$this->manageComposerPackages(oldPackages: $pluginPackages);
$this->manageComposerPackages(oldPackages: $pluginPackages);
// This throws an error when not called with qualifier
foreach (\Filament\Facades\Filament::getPanels() as $panel) {
$panel->clearCachedComponents();
// This throws an error when not called with qualifier
foreach (\Filament\Facades\Filament::getPanels() as $panel) {
$panel->clearCachedComponents();
}
} catch (Exception $exception) {
$this->handlePluginException($plugin, $exception, true);
}
}
@@ -494,14 +506,14 @@ class PluginService
return config('panel.plugin.dev_mode', false);
}
private function handlePluginException(string|Plugin $plugin, Exception $exception): void
private function handlePluginException(string|Plugin $plugin, Exception $exception, bool $throw = false): void
{
if ($this->isDevModeActive()) {
$this->setStatus($plugin, PluginStatus::Errored, $exception->getMessage());
if ($throw || $this->isDevModeActive()) {
throw ($exception);
}
report($exception);
$this->setStatus($plugin, PluginStatus::Errored, $exception->getMessage());
}
}