Loheide-eu-mitarbeiterplatt.../app/Filament/Pages/Updates.php
Friederich Loheide e211db9f30
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Failing after 7m34s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 11m55s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 16m43s
CI / Build-Artefakte aktuell (pull_request) Successful in 13m17s
Automatische Updates, Browser-Tests, CI grün (0.63.0)
- Opt-in „Updates automatisch installieren“ (AutoUpdate, alle 10 Minuten)
- Playwright-Tests in tests/Browser, CI-Job „Browser-Tests“
- CI: volle Matrix nur auf main, PRs mit einem MySQL-Job
- MySQL-JSON-Reihenfolge in zwei Tests, QM-Suchausschnitt ohne <mark>, h1 auf Startseite/Editor

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 17:29:20 +00:00

138 lines
4.7 KiB
PHP

<?php
namespace App\Filament\Pages;
use App\Support\Audit;
use App\Support\License\LicenseService;
use App\Support\License\LicenseStore;
use App\Support\License\ServerError;
use App\Support\License\ServerMessages;
use App\Support\Update\AutoUpdate;
use App\Support\Update\Changelog;
use App\Support\Update\Channels;
use App\Support\Update\InstalledVersion;
use App\Support\Update\Migrations;
use App\Support\Update\UpdateProgress;
use BackedEnum;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
use Throwable;
use UnitEnum;
/**
* Seite „Aktualisierung“: Version, Kanal, Update-Suche und -Installation,
* Migrationen, Änderungsprotokoll und Lizenz (docs/specs/self-updater.md).
*/
class Updates extends Page
{
protected string $view = 'filament.pages.updates';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArrowPathRoundedSquare;
protected static string|UnitEnum|null $navigationGroup = 'System';
protected static ?int $navigationSort = 10;
protected static ?string $navigationLabel = 'Aktualisierung';
protected static ?string $title = 'Aktualisierung';
public static function canAccess(): bool
{
return auth()->user()?->can('updates.manage') ?? false;
}
protected static ?string $slug = 'aktualisierung';
public string $licenseEmail = '';
public string $licenseKey = '';
public ?string $licenseError = null;
public function mount(LicenseStore $license): void
{
$this->licenseEmail = (string) $license->email();
}
public function saveLicense(LicenseStore $license, LicenseService $service): void
{
$this->validate([
'licenseEmail' => ['required', 'email', 'max:255'],
'licenseKey' => [$license->hasLicense() ? 'nullable' : 'required', 'string', 'max:500'],
], attributes: ['licenseEmail' => 'Lizenz-E-Mail', 'licenseKey' => 'Lizenzschlüssel']);
$license->setLicense($this->licenseEmail, filled($this->licenseKey) ? $this->licenseKey : (string) $license->key());
$this->licenseKey = '';
Audit::log('license.saved', ['email' => $this->licenseEmail]);
$this->checkLicense($service);
}
public function checkLicense(LicenseService $service): void
{
$this->licenseError = null;
try {
$service->check();
Notification::make()->success()->title('Lizenz geprüft')->send();
} catch (ServerError $e) {
$this->licenseError = ServerMessages::for($e);
} catch (Throwable $e) {
$this->licenseError = 'Die Lizenz konnte nicht geprüft werden: '.$e->getMessage();
}
}
public function releaseDevice(LicenseService $service, LicenseStore $license): void
{
try {
$service->releaseDevice();
Audit::log('license.device_released', ['device_label' => $license->deviceLabel()]);
Notification::make()
->success()
->title('Installation abgemeldet')
->body('Der Geräteplatz ist wieder frei. Updates sind erst nach erneuter Lizenzprüfung wieder möglich.')
->send();
} catch (ServerError $e) {
Notification::make()->danger()->title('Abmelden fehlgeschlagen')->body(ServerMessages::for($e))->send();
}
}
/**
* @return array<string, mixed>
*/
protected function getViewData(): array
{
$version = app(InstalledVersion::class);
$license = app(LicenseStore::class);
$channels = app(Channels::class);
try {
$migrations = app(Migrations::class)->status();
} catch (Throwable) {
$migrations = [];
}
return [
'release' => $version->release(),
'shortSha' => $version->short(),
'channels' => $channels->all(),
'activeChannel' => $channels->active(),
'autoUpdate' => app(AutoUpdate::class)->enabled(),
'progress' => app(UpdateProgress::class)->get(),
'migrations' => $migrations,
'pendingMigrations' => count(array_filter($migrations, fn (array $m) => ! $m['ran'])),
'changelog' => app(Changelog::class)->sections(),
'hasLicense' => $license->hasLicense(),
'maskedKey' => ($key = $license->key()) ? str_repeat('•', 8).substr($key, -4) : null,
'licenseSummary' => app(LicenseService::class)->summary(),
'licenseStatusError' => ($code = $license->lastStatus()['error_code'] ?? null)
? ServerMessages::for(new ServerError($code, 0, $code))
: null,
'deviceLabel' => $license->deviceLabel(),
];
}
}