Schneller und stabiler bei Updates (0.45.0)
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
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>
This commit is contained in:
parent
55a26e3f8e
commit
bf68be68f9
205 changed files with 773 additions and 464 deletions
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace App\Plugins;
|
||||
|
||||
use App\Support\Update\Filesystem;
|
||||
use App\Version;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Vorkompilierte Oberflächen separat installierter Plugins (Plugin-SDK).
|
||||
|
|
@ -59,6 +61,9 @@ class PluginAssets
|
|||
|
||||
$clean = fn ($file) => is_string($file) && preg_match('#^[A-Za-z0-9_./-]+$#', $file) && ! str_contains($file, '..') ? $file : null;
|
||||
|
||||
// Einmal nach public/ kopieren – dann liefert der Webserver die Dateien ohne PHP aus
|
||||
$this->publish($slug, $manifest);
|
||||
|
||||
$this->cache[$slug] = [
|
||||
'base' => '/plugin-assets/'.rawurlencode($slug).'/'.rawurlencode($manifest->version).'/',
|
||||
'components' => array_filter(array_map($clean, (array) ($data['components'] ?? [])), fn ($file, $key) => $file !== null && preg_match('#^[A-Za-z0-9_/-]+$#', (string) $key), ARRAY_FILTER_USE_BOTH),
|
||||
|
|
@ -85,6 +90,83 @@ class PluginAssets
|
|||
]];
|
||||
}
|
||||
|
||||
/**
|
||||
* dist/ eines aktiven Plugins nach public/plugin-assets/<slug>/<version>/ kopieren (gleiche
|
||||
* Adresse wie die PHP-Route). Der Webserver liefert vorhandene Dateien direkt aus – schneller
|
||||
* und ohne Sitzung. Geht das Kopieren nicht (public/ schreibgeschützt), springt die Route ein.
|
||||
*/
|
||||
public function publish(string $slug, PluginManifest $manifest): bool
|
||||
{
|
||||
$target = self::publicPath($slug).'/'.$manifest->version;
|
||||
|
||||
if (is_file($target.'/.complete')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$dist = realpath($manifest->path.'/dist');
|
||||
|
||||
if (! $dist || ! preg_match('#^[A-Za-z0-9.+-]+$#', $manifest->version)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$staging = self::publicPath($slug).'/.tmp-'.bin2hex(random_bytes(4));
|
||||
|
||||
try {
|
||||
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dist, \FilesystemIterator::SKIP_DOTS));
|
||||
|
||||
foreach ($files as $file) {
|
||||
$relative = substr($file->getPathname(), strlen($dist) + 1);
|
||||
|
||||
// Nur erlaubte Dateitypen und saubere Namen (wie bei der Route)
|
||||
if (! $file->isFile() || ! isset(self::TYPES[strtolower($file->getExtension())]) || ! preg_match('#^[A-Za-z0-9_./-]+$#', $relative)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! is_dir(dirname($staging.'/'.$relative)) && ! @mkdir(dirname($staging.'/'.$relative), 0775, true)) {
|
||||
throw new \RuntimeException('public/plugin-assets ist nicht beschreibbar.');
|
||||
}
|
||||
|
||||
if (! @copy($file->getPathname(), $staging.'/'.$relative)) {
|
||||
throw new \RuntimeException("{$relative} konnte nicht kopiert werden.");
|
||||
}
|
||||
}
|
||||
|
||||
@file_put_contents($staging.'/.complete', (string) time());
|
||||
Filesystem::deleteDirectory($target);
|
||||
|
||||
if (! @rename($staging, $target)) {
|
||||
throw new \RuntimeException('Kopie konnte nicht übernommen werden.');
|
||||
}
|
||||
|
||||
// Ältere Versionen dieses Plugins entfernen
|
||||
foreach (glob(self::publicPath($slug).'/*', GLOB_ONLYDIR) ?: [] as $dir) {
|
||||
if (basename($dir) !== $manifest->version) {
|
||||
Filesystem::deleteDirectory($dir);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Filesystem::deleteDirectory($staging);
|
||||
Log::info("Plugin-Dateien von {$slug} werden über PHP ausgeliefert: ".$e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Veröffentlichte Kopie entfernen (Plugin deaktiviert oder gelöscht) */
|
||||
public static function unpublish(string $slug): void
|
||||
{
|
||||
if (preg_match('#^[a-z0-9-]+$#', $slug)) {
|
||||
Filesystem::deleteDirectory(self::publicPath($slug));
|
||||
}
|
||||
}
|
||||
|
||||
private static function publicPath(string $slug): string
|
||||
{
|
||||
return rtrim((string) (config('inhaus.plugin_assets_path') ?: public_path('plugin-assets')), '/').'/'.$slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pfad einer ausgelieferten Datei – nur aus dist/ eines aktiven Kunden-Plugins.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ 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;
|
||||
|
|
@ -65,12 +66,23 @@ class PluginInstaller
|
|||
throw new RuntimeException('Das Verzeichnis plugins/ ist nicht beschreibbar.');
|
||||
}
|
||||
|
||||
Filesystem::deleteDirectory($target);
|
||||
// Parallele Anfragen sehen kurz ein halbes Plugin – das soll es nicht abschalten
|
||||
$window = app(MaintenanceFlag::class);
|
||||
$window->beginQuietUpdate();
|
||||
|
||||
if (! Filesystem::moveDirectory($staging, $target)) {
|
||||
throw new RuntimeException('Das Plugin konnte nicht nach plugins/ verschoben werden. Bitte Schreibrechte prüfen.');
|
||||
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]);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Plugins;
|
|||
use App\Http\Middleware\EnsurePluginAccess;
|
||||
use App\Support\Audit;
|
||||
use App\Support\Update\Filesystem;
|
||||
use App\Support\Update\MaintenanceFlag;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
|
@ -28,6 +29,8 @@ class PluginManager
|
|||
/** Ab diesem Alter gilt eine liegengebliebene Lade-Markierung als Absturz. */
|
||||
private const CRASH_AFTER_SECONDS = 30;
|
||||
|
||||
private ?MaintenanceFlag $updateWindow = null;
|
||||
|
||||
/** @var array<string, PluginManifest>|null */
|
||||
private ?array $manifests = null;
|
||||
|
||||
|
|
@ -176,6 +179,7 @@ class PluginManager
|
|||
{
|
||||
$this->recoverFromCrash();
|
||||
$this->reenableAfterIncompleteUpload();
|
||||
$this->reenableAfterUpdate();
|
||||
|
||||
foreach ($this->bootOrder() as $manifest) {
|
||||
$this->guard($manifest, function () use ($manifest) {
|
||||
|
|
@ -256,6 +260,7 @@ class PluginManager
|
|||
}
|
||||
|
||||
$this->state->setEnabled($slug, false, $reason);
|
||||
PluginAssets::unpublish($slug);
|
||||
Audit::log('plugin.deactivated', ['plugin' => $slug, 'reason' => $reason]);
|
||||
}
|
||||
|
||||
|
|
@ -284,6 +289,7 @@ class PluginManager
|
|||
}
|
||||
|
||||
Filesystem::deleteDirectory($manifest->path);
|
||||
PluginAssets::unpublish($slug);
|
||||
$this->state->forget($slug);
|
||||
$this->manifests = null;
|
||||
Audit::log('plugin.deleted', ['plugin' => $slug, 'data_removed' => $removeData]);
|
||||
|
|
@ -381,8 +387,14 @@ class PluginManager
|
|||
|
||||
private function guard(PluginManifest $manifest, callable $callback): void
|
||||
{
|
||||
// Während eines Updates tauscht das Portal gerade Dateien aus: Fehler beim Laden sind dann
|
||||
// meist nur ein Zwischenstand – das Plugin fehlt in dieser Anfrage, wird aber nicht abgeschaltet.
|
||||
$updating = $this->updateWindow()->isUpdating();
|
||||
$marker = $this->markerPath($manifest->slug);
|
||||
@file_put_contents($marker, (string) time());
|
||||
|
||||
if (! $updating) {
|
||||
@file_put_contents($marker, (string) time());
|
||||
}
|
||||
|
||||
try {
|
||||
$callback();
|
||||
|
|
@ -395,6 +407,13 @@ class PluginManager
|
|||
} catch (Throwable $e) {
|
||||
unset($this->loaded[$manifest->slug]);
|
||||
$this->problems[$manifest->slug] = $e->getMessage();
|
||||
|
||||
if ($updating) {
|
||||
Log::warning("Plugin {$manifest->slug} konnte während eines Updates nicht geladen werden (nicht deaktiviert): ".$e->getMessage());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Log::error("Plugin {$manifest->slug} wurde wegen eines Fehlers deaktiviert: ".$e->getMessage(), ['exception' => $e]);
|
||||
|
||||
try {
|
||||
|
|
@ -415,6 +434,15 @@ class PluginManager
|
|||
}
|
||||
|
||||
$slug = substr(basename($marker), strlen('booting-'));
|
||||
|
||||
// Abgestürzt, während ein Update Dateien austauschte: kein Fehler des Plugins
|
||||
if ($this->updateWindow()->covers((int) @filemtime($marker))) {
|
||||
Log::warning("Plugin {$slug} ist während eines Updates beim Laden abgebrochen – es bleibt aktiv.");
|
||||
@unlink($marker);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Log::critical("Plugin {$slug} hat beim Laden einen schweren Fehler verursacht und wurde deaktiviert.");
|
||||
$this->state->setEnabled($slug, false, 'Schwerer Fehler beim Laden (das Portal wurde dadurch unterbrochen).');
|
||||
@unlink($marker);
|
||||
|
|
@ -444,6 +472,30 @@ class PluginManager
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugins, die während eines Updates wegen eines Ladefehlers abgeschaltet wurden (ältere
|
||||
* Portal-Versionen taten das), wieder einschalten – der Fehler war nur ein Zwischenstand.
|
||||
* Ist das Plugin wirklich defekt, fällt es beim nächsten Laden außerhalb des Updates erneut auf.
|
||||
*/
|
||||
private function reenableAfterUpdate(): void
|
||||
{
|
||||
foreach ($this->state->all() as $slug => $entry) {
|
||||
$reason = (string) ($entry['disabled_reason'] ?? '');
|
||||
$at = $this->state->disabledAt($slug);
|
||||
$crash = str_starts_with($reason, 'Fehler beim Laden') || str_starts_with($reason, 'Schwerer Fehler beim Laden');
|
||||
|
||||
if (($entry['enabled'] ?? true) === false && $crash && $at !== null && $this->updateWindow()->covers($at)) {
|
||||
$this->state->setEnabled($slug, true);
|
||||
Log::info("Plugin {$slug} wieder aktiviert (Ladefehler während eines Updates).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function updateWindow(): MaintenanceFlag
|
||||
{
|
||||
return $this->updateWindow ??= $this->app->make(MaintenanceFlag::class);
|
||||
}
|
||||
|
||||
private function markerPath(string $slug): string
|
||||
{
|
||||
$dir = storage_path('framework/plugins');
|
||||
|
|
|
|||
|
|
@ -32,7 +32,15 @@ class PluginState
|
|||
|
||||
public function setEnabled(string $slug, bool $enabled, ?string $reason = null): void
|
||||
{
|
||||
$this->update($slug, ['enabled' => $enabled, 'disabled_reason' => $enabled ? null : $reason]);
|
||||
$this->update($slug, ['enabled' => $enabled, 'disabled_reason' => $enabled ? null : $reason, 'disabled_at' => $enabled ? null : time()]);
|
||||
}
|
||||
|
||||
/** Zeitpunkt der Deaktivierung (Unix-Zeit), falls bekannt */
|
||||
public function disabledAt(string $slug): ?int
|
||||
{
|
||||
$at = $this->all()[$slug]['disabled_at'] ?? null;
|
||||
|
||||
return is_int($at) ? $at : null;
|
||||
}
|
||||
|
||||
public function disabledReason(string $slug): ?string
|
||||
|
|
|
|||
|
|
@ -11,6 +11,12 @@ namespace App\Support\Update;
|
|||
*/
|
||||
class MaintenanceFlag
|
||||
{
|
||||
/**
|
||||
* So lange nach einem Update gelten Abstürze beim Laden noch als Folge des Dateiaustauschs
|
||||
* (Zwischenspeicher wie OPcache und parallele Anfragen brauchen einen Moment).
|
||||
*/
|
||||
public const GRACE_SECONDS = 120;
|
||||
|
||||
public function __construct(private readonly ?string $file = null) {}
|
||||
|
||||
public function activate(int $maxSeconds = 600): void
|
||||
|
|
@ -23,7 +29,67 @@ class MaintenanceFlag
|
|||
|
||||
public function deactivate(): void
|
||||
{
|
||||
$data = json_decode((string) @file_get_contents($this->path()), true);
|
||||
@unlink($this->path());
|
||||
|
||||
// Zeitraum des letzten Updates merken (siehe covers())
|
||||
if (is_array($data) && isset($data['since'])) {
|
||||
AtomicFile::write($this->lastPath(), json_encode(['since' => (int) $data['since'], 'until' => time()]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dateiaustausch ohne Wartungsmodus (z. B. ein Plugin wird aktualisiert): Die Seite bleibt
|
||||
* erreichbar, Ladefehler in dieser Zeit schalten aber kein Plugin ab.
|
||||
*/
|
||||
public function beginQuietUpdate(): void
|
||||
{
|
||||
AtomicFile::write($this->windowPath(), json_encode(['since' => time()]));
|
||||
}
|
||||
|
||||
public function endQuietUpdate(): void
|
||||
{
|
||||
$data = json_decode((string) @file_get_contents($this->windowPath()), true);
|
||||
@unlink($this->windowPath());
|
||||
|
||||
if (is_array($data) && isset($data['since'])) {
|
||||
AtomicFile::write($this->lastPath(), json_encode(['since' => (int) $data['since'], 'until' => time()]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Läuft gerade ein Update – oder ist eines erst eben zu Ende gegangen?
|
||||
*/
|
||||
public function isUpdating(): bool
|
||||
{
|
||||
return $this->isActive() || $this->covers(time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Fiel dieser Zeitpunkt in ein Update (einschließlich der Nachlaufzeit)?
|
||||
*/
|
||||
public function covers(int $timestamp): bool
|
||||
{
|
||||
foreach ([$this->path(), $this->windowPath(), $this->lastPath()] as $file) {
|
||||
$data = json_decode((string) @file_get_contents($file), true);
|
||||
|
||||
if (! is_array($data) || ! isset($data['since'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$until = match ($file) {
|
||||
// Läuft noch (ein abgebrochener Plugin-Austausch zählt höchstens zehn Minuten)
|
||||
$this->path() => max(time(), (int) ($data['until'] ?? 0)),
|
||||
$this->windowPath() => min(time(), (int) $data['since'] + 600),
|
||||
default => (int) ($data['until'] ?? 0),
|
||||
};
|
||||
|
||||
if ($timestamp >= (int) $data['since'] && $timestamp <= $until + self::GRACE_SECONDS) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
|
|
@ -56,4 +122,14 @@ class MaintenanceFlag
|
|||
{
|
||||
return $this->file ?? storage_path('.maintenance');
|
||||
}
|
||||
|
||||
private function windowPath(): string
|
||||
{
|
||||
return $this->path().'-quiet';
|
||||
}
|
||||
|
||||
private function lastPath(): string
|
||||
{
|
||||
return $this->path().'-last';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ namespace App;
|
|||
*/
|
||||
final class Version
|
||||
{
|
||||
public const VERSION = '0.44.0';
|
||||
public const VERSION = '0.45.0';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue