- Plugins nach WordPress-Prinzip: plugin.json-Manifest mit Versions- und Abhängigkeitsprüfung, eigenes PSR-4-Autoloading, register()/boot(), activate()/deactivate()/uninstall(), Migrationen, Routen und Views je Plugin - plugins-core/ (mitgeliefert, aktiv bis zur Deaktivierung) und plugins/ (Kunden-Plugins, geschützt vor Updates, inaktiv bis zur Aktivierung) - Zustand in storage/app/plugins.json – Laden ohne Datenbankabfrage - Wiederherstellungsmodus: Ausnahmen und Fatal Errors beim Laden deaktivieren das Plugin, das Portal bleibt erreichbar - Hooks (Actions/Filter mit Prioritäten) und Registries für Navigation, Startseiten-Kacheln, Rechte und Admin-Seiten (Filament-Discovery) - Admin-Seite „Plugins“: aktivieren, deaktivieren, per ZIP installieren (ZIP-Slip-Schutz), löschen mit oder ohne Daten; abschaltbar per INHAUS_DISALLOW_FILE_MODS - Startseite komplett aus Kacheln; Plugin-Seiten als „slug::Seite“ - Version 0.3.0 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
102 lines
3.5 KiB
PHP
102 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Plugins\PluginInstaller;
|
|
use App\Plugins\PluginManager;
|
|
use App\Plugins\PluginManifest;
|
|
use BackedEnum;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
use Livewire\WithFileUploads;
|
|
use Throwable;
|
|
use UnitEnum;
|
|
|
|
class Plugins extends Page
|
|
{
|
|
use WithFileUploads;
|
|
|
|
protected string $view = 'filament.pages.plugins';
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPuzzlePiece;
|
|
|
|
protected static string|UnitEnum|null $navigationGroup = 'System';
|
|
|
|
protected static ?int $navigationSort = 5;
|
|
|
|
protected static ?string $title = 'Plugins';
|
|
|
|
protected static ?string $slug = 'plugins';
|
|
|
|
/** @var TemporaryUploadedFile|null */
|
|
public $archive = null;
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
return auth()->user()?->can('plugins.manage') ?? false;
|
|
}
|
|
|
|
public function activate(string $slug, PluginManager $plugins): void
|
|
{
|
|
$this->run(fn () => $plugins->activate($slug), 'Plugin aktiviert', 'Die Änderungen sind ab dem nächsten Seitenaufruf sichtbar.');
|
|
}
|
|
|
|
public function deactivate(string $slug, PluginManager $plugins): void
|
|
{
|
|
$this->run(fn () => $plugins->deactivate($slug), 'Plugin deaktiviert', 'Die Daten bleiben erhalten und stehen nach erneuter Aktivierung wieder zur Verfügung.');
|
|
}
|
|
|
|
public function delete(string $slug, bool $removeData, PluginManager $plugins): void
|
|
{
|
|
$this->run(fn () => $plugins->delete($slug, $removeData), 'Plugin gelöscht', $removeData ? 'Das Plugin und seine Daten wurden entfernt.' : 'Die Daten des Plugins sind noch in der Datenbank.');
|
|
}
|
|
|
|
public function upload(PluginInstaller $installer): void
|
|
{
|
|
$this->validate(['archive' => ['required', 'file', 'mimes:zip', 'max:51200']], attributes: ['archive' => 'ZIP-Archiv']);
|
|
|
|
try {
|
|
$manifest = $installer->install($this->archive->getRealPath());
|
|
$this->archive = null;
|
|
|
|
Notification::make()
|
|
->success()
|
|
->title("„{$manifest->name}“ {$manifest->version} installiert")
|
|
->body('Das Plugin kann jetzt aktiviert werden.')
|
|
->send();
|
|
} catch (Throwable $e) {
|
|
$this->addError('archive', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
private function run(callable $action, string $title, string $body): void
|
|
{
|
|
try {
|
|
$action();
|
|
Notification::make()->success()->title($title)->body($body)->send();
|
|
$this->redirect(static::getUrl());
|
|
} catch (Throwable $e) {
|
|
Notification::make()->danger()->title('Nicht möglich')->body($e->getMessage())->send();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function getViewData(): array
|
|
{
|
|
$plugins = app(PluginManager::class);
|
|
|
|
return [
|
|
'plugins' => collect($plugins->all())->map(fn (PluginManifest $m) => [
|
|
'manifest' => $m,
|
|
'enabled' => $plugins->isEnabled($m->slug),
|
|
'problem' => $plugins->problem($m->slug) ?? (($issues = $m->incompatibilities()) ? implode(', ', $issues) : null),
|
|
'dependents' => $plugins->dependents($m->slug),
|
|
])->sortBy(fn (array $p) => [$p['manifest']->core ? 0 : 1, $p['manifest']->name])->values(),
|
|
'uploadsAllowed' => PluginInstaller::uploadsAllowed(),
|
|
];
|
|
}
|
|
}
|