Loheide-eu-mitarbeiterplatt.../app/Support/Update/AutoUpdate.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

60 lines
1.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Support\Update;
use App\Support\Settings;
use Illuminate\Support\Facades\Log;
use Throwable;
/**
* „Updates automatisch installieren“ – gedacht für Test- und Vorschau-Instanzen, die
* immer den neuesten Stand ihres Kanals zeigen sollen. Läuft als geplante Aufgabe
* (Cron, Web-Cron oder Pseudo-Cron) und nutzt denselben Ablauf wie der Knopf auf
* der Seite „Aktualisierung“. Einen Kanalwechsel zurück installiert es nie selbst.
*/
class AutoUpdate
{
public function __construct(
private readonly Settings $settings,
private readonly UpdateCheck $check,
private readonly UpdateProgress $progress,
) {}
public function enabled(): bool
{
return (bool) $this->settings->get('updates.auto', false);
}
public function setEnabled(bool $enabled): void
{
$this->settings->set('updates.auto', $enabled);
}
/**
* @return array{sha: string, files: int, pending: bool}|null null, wenn nichts installiert wurde
*/
public function run(): ?array
{
if (! $this->enabled() || $this->progress->isRunning()) {
return null;
}
try {
$result = $this->check->run();
} catch (Throwable $e) {
Log::warning('Automatisches Update: Prüfung fehlgeschlagen: '.$e->getMessage());
return null;
}
if (! $result['has_update'] || ($result['channel_switch']['direction'] ?? null) === 'back') {
return null;
}
@set_time_limit(0);
@ignore_user_abort(true);
Log::info('Automatisches Update auf '.($result['version'] ?? $result['latest_short']).' beginnt.');
return app(Updater::class)->installUpdate();
}
}