mirror of
https://github.com/pelican-dev/panel.git
synced 2026-05-04 18:00:48 +03:00
Set plugin status to "errored" if it errored (#2084)
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user