Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 12m25s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 12m51s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 10m43s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 10m37s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 12m42s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 13m38s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m39s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 9m33s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 44s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
- Ladefehler während eines Updates schalten keine Plugins mehr ab: Wartungsmodus merkt sich den Update-Zeitraum (+2 min Nachlauf), Plugin-Uploads markieren den Dateiaustausch ohne Wartungsmodus; guard/recoverFromCrash prüfen das, betroffene Plugins (mit disabled_at im Zeitraum) werden wieder eingeschaltet - Plugin-Oberflächen werden nach public/plugin-assets kopiert (Webserver statt PHP), bei Deaktivieren/Löschen/Neu-Hochladen entfernt; Route bleibt als Rückfall - RichTextEditor in SDK, Leichte-Sprache-Leiste und Glossar asynchron; fehlende Menü-Symbole kuratiert → kein Laden des kompletten Symbolsatzes - Inertia-Prefetch (hover, 10 s) für Menülinks und Neuigkeiten-Vorschauen; Prefetch zählt nicht als Lesen (Reach) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
94 lines
3.5 KiB
PHP
94 lines
3.5 KiB
PHP
<?php
|
||
|
||
namespace App\Plugins;
|
||
|
||
use App\Support\Audit;
|
||
use App\Support\Update\Filesystem;
|
||
use App\Support\Update\MaintenanceFlag;
|
||
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);
|
||
}
|
||
|
||
/**
|
||
* @param string|null $expectedSlug bei Updates: das Archiv muss genau dieses Plugin enthalten
|
||
*/
|
||
public function install(string $zipFile, ?string $expectedSlug = null): 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());
|
||
}
|
||
|
||
if ($expectedSlug !== null && $manifest->slug !== $expectedSlug) {
|
||
throw new RuntimeException("Das Archiv enthält das Plugin „{$manifest->slug}“ statt „{$expectedSlug}“.");
|
||
}
|
||
|
||
$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.');
|
||
}
|
||
|
||
// Parallele Anfragen sehen kurz ein halbes Plugin – das soll es nicht abschalten
|
||
$window = app(MaintenanceFlag::class);
|
||
$window->beginQuietUpdate();
|
||
|
||
try {
|
||
Filesystem::deleteDirectory($target);
|
||
|
||
if (! Filesystem::moveDirectory($staging, $target)) {
|
||
throw new RuntimeException('Das Plugin konnte nicht nach plugins/ verschoben werden. Bitte Schreibrechte prüfen.');
|
||
}
|
||
} finally {
|
||
$window->endQuietUpdate();
|
||
}
|
||
|
||
// Neu veröffentlichen (auch bei gleicher Versionsnummer)
|
||
PluginAssets::unpublish($manifest->slug);
|
||
|
||
$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);
|
||
}
|
||
}
|
||
}
|