Compare commits

..

4 Commits

Author SHA1 Message Date
Boy132
6d6490dae7 make folder name lower case after file_exists check 2026-02-13 20:30:44 +01:00
Boy132
a25f3cb32f add own exception for plugin id mismatch 2026-02-13 20:22:28 +01:00
Boy132
b8a909d655 make plugin id and folder name check case-insensitive 2026-02-13 20:18:53 +01:00
Boy132
187e3af3df do not try to load "Error" plugins 2026-02-13 19:41:19 +01:00
4 changed files with 21 additions and 18 deletions

View File

@@ -0,0 +1,7 @@
<?php
namespace App\Exceptions;
use Exception;
class PluginIdMismatchException extends Exception {}

View File

@@ -5,6 +5,7 @@ namespace App\Models;
use App\Contracts\Plugins\HasPluginSettings;
use App\Enums\PluginCategory;
use App\Enums\PluginStatus;
use App\Exceptions\PluginIdMismatchException;
use App\Facades\Plugins;
use Exception;
use Filament\Schemas\Components\Component;
@@ -108,11 +109,14 @@ class Plugin extends Model implements HasPluginSettings
continue;
}
$plugin = Str::lower($plugin);
try {
$data = File::json($path, JSON_THROW_ON_ERROR);
$data['id'] = Str::lower($data['id']);
if ($data['id'] !== $plugin) {
throw new Exception("Plugin id mismatch for folder name ($plugin) and id in plugin.json ({$data['id']})!");
throw new PluginIdMismatchException("Plugin id mismatch for folder name ($plugin) and id in plugin.json ({$data['id']})!");
}
$panels = null;
@@ -158,12 +162,12 @@ class Plugin extends Model implements HasPluginSettings
if (!$exception instanceof JsonException) {
$plugins[] = [
'id' => $data['id'] ?? Str::uuid(),
'name' => $data['name'] ?? $plugin,
'name' => $data['name'] ?? Str::headline($plugin),
'author' => $data['author'] ?? 'Unknown',
'version' => '0.0.0',
'description' => 'Plugin.json is invalid!',
'version' => $data['version'] ?? '0.0.0',
'description' => $exception instanceof PluginIdMismatchException ? $exception->getMessage() : 'Plugin.json is invalid!',
'category' => PluginCategory::Plugin->value,
'url' => null,
'url' => $data['url'] ?? null,
'update_url' => null,
'namespace' => 'Error',
'class' => 'Error',
@@ -197,7 +201,7 @@ class Plugin extends Model implements HasPluginSettings
public function shouldLoad(?string $panelId = null): bool
{
return ($this->status === PluginStatus::Enabled || $this->status === PluginStatus::Errored) && (is_null($panelId) || !$this->panels || in_array($panelId, explode(',', $this->panels)));
return $this->fullClass() !== '\\Error\\Error' && ($this->status === PluginStatus::Enabled || $this->status === PluginStatus::Errored) && (is_null($panelId) || !$this->panels || in_array($panelId, explode(',', $this->panels)));
}
public function canEnable(): bool

View File

@@ -189,18 +189,6 @@ class EggImporterService
}
}
// Convert YAML booleans to strings to prevent Laravel from converting them to 1/0
// when saving to TEXT field. Required for validation rules like "in:true,false".
if (isset($parsed['variables'])) {
$parsed['variables'] = array_map(function ($variable) {
if (isset($variable['default_value']) && is_bool($variable['default_value'])) {
$variable['default_value'] = $variable['default_value'] ? 'true' : 'false';
}
return $variable;
}, $parsed['variables']);
}
// Reserved env var name handling
[$forbidden, $allowed] = collect($parsed['variables'])
->map(fn ($variable) => array_merge(

View File

@@ -54,6 +54,10 @@ class PluginService
}
}
if ($plugin->namespace === 'Error') {
continue;
}
// Always autoload src directory to make sure all class names can be resolved (e.g. in migrations)
$namespace = $plugin->namespace . '\\';
if (!array_key_exists($namespace, $classLoader->getPrefixesPsr4())) {