Plugin-System; Neuigkeiten und Termine als mitgelieferte Plugins
- 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>
This commit is contained in:
parent
cc0020458f
commit
28ef1e4a20
155 changed files with 2762 additions and 573 deletions
75
app/Plugins/PluginInstaller.php
Normal file
75
app/Plugins/PluginInstaller.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace App\Plugins;
|
||||
|
||||
use App\Support\Audit;
|
||||
use App\Support\Update\Filesystem;
|
||||
use App\Support\Update\ZipExtractor;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Installiert Kunden-Plugins aus einem ZIP-Archiv nach plugins/<slug>.
|
||||
* Nutzt denselben ZIP-Slip-Schutz wie der Self-Updater. Ein vorhandenes Plugin
|
||||
* mit gleichem Kürzel wird ersetzt (Update), seine Daten bleiben erhalten.
|
||||
*/
|
||||
class PluginInstaller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PluginManager $plugins,
|
||||
private readonly ZipExtractor $extractor,
|
||||
) {}
|
||||
|
||||
public static function uploadsAllowed(): bool
|
||||
{
|
||||
return ! filter_var(config('inhaus.disallow_file_mods'), FILTER_VALIDATE_BOOL);
|
||||
}
|
||||
|
||||
public function install(string $zipFile): PluginManifest
|
||||
{
|
||||
if (! self::uploadsAllowed()) {
|
||||
throw new RuntimeException('Das Installieren von Plugins ist in dieser Installation abgeschaltet.');
|
||||
}
|
||||
|
||||
$staging = storage_path('framework/plugin-upload-'.bin2hex(random_bytes(4)));
|
||||
|
||||
try {
|
||||
$this->extractor->extract($zipFile, $staging);
|
||||
|
||||
try {
|
||||
$manifest = PluginManifest::fromDirectory($staging, core: false);
|
||||
} catch (Throwable $e) {
|
||||
throw new RuntimeException('Das Archiv enthält kein gültiges Plugin: '.$e->getMessage());
|
||||
}
|
||||
|
||||
$existing = $this->plugins->find($manifest->slug);
|
||||
|
||||
if ($existing?->core) {
|
||||
throw new RuntimeException("Das Kürzel „{$manifest->slug}“ gehört zu einem mitgelieferten Plugin.");
|
||||
}
|
||||
|
||||
if (! is_file($staging.'/src/'.str_replace('\\', '/', substr($manifest->class, strlen($manifest->namespace))).'.php')) {
|
||||
throw new RuntimeException("Die Plugin-Klasse {$manifest->class} fehlt im Archiv (erwartet unter src/).");
|
||||
}
|
||||
|
||||
$target = $this->plugins->customerPath().'/'.$manifest->slug;
|
||||
|
||||
if (! is_dir(dirname($target)) && ! @mkdir(dirname($target), 0775, true)) {
|
||||
throw new RuntimeException('Das Verzeichnis plugins/ ist nicht beschreibbar.');
|
||||
}
|
||||
|
||||
Filesystem::deleteDirectory($target);
|
||||
|
||||
if (! Filesystem::moveDirectory($staging, $target)) {
|
||||
throw new RuntimeException('Das Plugin konnte nicht nach plugins/ verschoben werden. Bitte Schreibrechte prüfen.');
|
||||
}
|
||||
|
||||
$this->plugins->forgetDiscovered();
|
||||
Audit::log($existing ? 'plugin.updated' : 'plugin.installed', ['plugin' => $manifest->slug, 'version' => $manifest->version]);
|
||||
|
||||
return PluginManifest::fromDirectory($target, core: false);
|
||||
} finally {
|
||||
Filesystem::deleteDirectory($staging);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue