Umsetzung von docs/specs/self-updater.md für Laravel: - Installierter Stand als SHA in storage/.version, Fortschritt in storage/.update-progress, selbstheilender Wartungsmodus in storage/.maintenance - Update-Client je Kanal (stable/development), nur HTTPS, begrenzte Redirects, ZIP-Download per Stream mit PK- und SHA-256-Prüfung - Entpacken mit zweistufigem ZIP-Slip-Schutz, Übernahme mit geschützten Pfaden (atomar je Datei, nie löschen), Migrationen, Cache- und OPcache-Reset - Lizenzspeicher außerhalb der DB, Geräte-ID als Zufallszahl, rotierendes Gerätetoken wird bei jeder Antwort (auch Fehler und Downloads) sofort gespeichert - Lizenzfehler mit verständlichen Meldungen – sie sperren nie das Portal - Seite „Aktualisierung“ mit Kanal, Suche, Changelog-Vorschau, Fortschritt, Migrationen, Änderungsprotokoll, Lizenz und Datenschutzhinweis - Wartungs-Middleware (503 + Retry-After) und Auto-Migration per Fingerabdruck - Audit-Log für Updates, Kanalwechsel und Lizenzänderungen - Version 0.2.0 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
81 lines
1.9 KiB
PHP
81 lines
1.9 KiB
PHP
<?php
|
||
|
||
namespace App\Support\Update;
|
||
|
||
use Illuminate\Database\Migrations\Migrator;
|
||
use Illuminate\Support\Facades\Artisan;
|
||
|
||
/**
|
||
* Migrationen ohne Shell: Status, Ausführen und Fingerabdruck über die Dateien.
|
||
*/
|
||
class Migrations
|
||
{
|
||
public function __construct(private readonly Migrator $migrator) {}
|
||
|
||
/**
|
||
* @return list<array{name: string, ran: bool}>
|
||
*/
|
||
public function status(): array
|
||
{
|
||
$ran = $this->ran();
|
||
|
||
return array_map(fn (string $name) => [
|
||
'name' => $name,
|
||
'ran' => in_array($name, $ran, true),
|
||
], array_keys($this->files()));
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function pending(): array
|
||
{
|
||
return array_values(array_diff(array_keys($this->files()), $this->ran()));
|
||
}
|
||
|
||
/**
|
||
* Führt ausstehende Migrationen aus und gibt deren Anzahl zurück.
|
||
*/
|
||
public function run(): int
|
||
{
|
||
$before = count($this->ran());
|
||
|
||
Artisan::call('migrate', ['--force' => true]);
|
||
|
||
return count($this->ran()) - $before;
|
||
}
|
||
|
||
/**
|
||
* Fingerabdruck über die Liste der Migrationsdateien. Ändert sich nur, wenn
|
||
* Migrationen dazukommen – dann lohnt sich ein Blick auf die Datenbank.
|
||
*/
|
||
public function fingerprint(): string
|
||
{
|
||
return sha1(implode("\n", array_keys($this->files())));
|
||
}
|
||
|
||
/**
|
||
* @return array<string, string> Name => Pfad
|
||
*/
|
||
private function files(): array
|
||
{
|
||
$files = $this->migrator->getMigrationFiles(array_merge(
|
||
[database_path('migrations')],
|
||
$this->migrator->paths(),
|
||
));
|
||
|
||
ksort($files);
|
||
|
||
return $files;
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
private function ran(): array
|
||
{
|
||
$repository = $this->migrator->getRepository();
|
||
|
||
return $repository->repositoryExists() ? $repository->getRan() : [];
|
||
}
|
||
}
|