mirror of
https://github.com/pelican-dev/panel.git
synced 2026-02-14 03:13:26 +03:00
Compare commits
4 Commits
main
...
boy132/imp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d6490dae7 | ||
|
|
a25f3cb32f | ||
|
|
b8a909d655 | ||
|
|
187e3af3df |
7
app/Exceptions/PluginIdMismatchException.php
Normal file
7
app/Exceptions/PluginIdMismatchException.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class PluginIdMismatchException extends Exception {}
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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())) {
|
||||
|
||||
Reference in New Issue
Block a user