Loheide-eu-mitarbeiterplatt.../app/Http/Controllers/Admin/UpdateController.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

107 lines
3.5 KiB
PHP
Raw Permalink 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\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Support\Audit;
use App\Support\License\ServerError;
use App\Support\License\ServerMessages;
use App\Support\Update\AutoUpdate;
use App\Support\Update\Channels;
use App\Support\Update\Migrations;
use App\Support\Update\UpdateCheck;
use App\Support\Update\UpdateProgress;
use App\Support\Update\Updater;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Throwable;
/**
* Endpunkte der Seite „Aktualisierung“ – nur für Administratoren, CSRF-geschützt.
*/
class UpdateController extends Controller
{
public function check(Request $request, UpdateCheck $check): JsonResponse
{
try {
return response()->json(['ok' => true, 'result' => $check->run()]);
} catch (ServerError $e) {
return $this->serverError($e);
}
}
public function install(Request $request, Updater $updater, UpdateProgress $progress): JsonResponse
{
if ($progress->isRunning()) {
return response()->json(['ok' => false, 'message' => 'Es läuft bereits eine Aktualisierung.'], 409);
}
// Der Ablauf läuft serverseitig zu Ende, auch wenn der Browser die Verbindung trennt.
@set_time_limit(0);
@ignore_user_abort(true);
try {
$result = $updater->installUpdate($request->user()?->id);
return response()->json(['ok' => true, 'result' => $result]);
} catch (ServerError $e) {
return $this->serverError($e);
} catch (Throwable $e) {
return response()->json(['ok' => false, 'message' => $e->getMessage()], 500);
}
}
public function progress(UpdateProgress $progress): JsonResponse
{
return response()->json($progress->get());
}
public function channel(Request $request, Channels $channels): JsonResponse
{
$validated = $request->validate([
'channel' => ['required', 'string', Rule::in(array_keys($channels->all()))],
]);
$channels->setActive($validated['channel']);
Audit::log('update.channel_changed', ['channel' => $validated['channel']]);
return response()->json(['ok' => true, 'channel' => $validated['channel']]);
}
public function auto(Request $request, AutoUpdate $auto): JsonResponse
{
$enabled = $request->boolean('enabled');
$auto->setEnabled($enabled);
Audit::log('update.auto_changed', ['enabled' => $enabled]);
return response()->json(['ok' => true, 'enabled' => $enabled]);
}
public function migrations(Migrations $migrations): JsonResponse
{
@set_time_limit(0);
try {
$count = $migrations->run();
@file_put_contents(storage_path('.migrations-fingerprint'), $migrations->fingerprint());
Audit::log('update.migrations', ['migrations' => $count]);
return response()->json(['ok' => true, 'count' => $count, 'status' => $migrations->status()]);
} catch (Throwable $e) {
Audit::log('update.migrations_failed', ['error' => $e->getMessage()]);
return response()->json(['ok' => false, 'message' => 'Migrationen fehlgeschlagen: '.$e->getMessage()], 500);
}
}
private function serverError(ServerError $e): JsonResponse
{
return response()->json([
'ok' => false,
'code' => $e->errorCode,
'message' => ServerMessages::for($e),
'license_input' => $e->needsLicenseInput(),
], 200);
}
}