Ergänze sichere WebP-Bestandsmigration
Zeigt bei älteren Upload-Bildern automatisch einen geschützten Migrationsbutton im Adminbereich an und aktualisiert die JSON-Verweise transaktionssicher. Ergänzt außerdem einen Server-Updater, der Datenbank, Uploads und Konfiguration beim Wechsel von älteren Versionen sichert und wiederherstellt.
This commit is contained in:
@@ -26,8 +26,32 @@ if (isset($_GET['logout'])) {
|
||||
}
|
||||
|
||||
if ($loggedIn) {
|
||||
if (empty($_SESSION['migration_csrf'])) {
|
||||
$_SESSION['migration_csrf'] = bin2hex(random_bytes(32));
|
||||
}
|
||||
$migrationCsrf = (string)$_SESSION['migration_csrf'];
|
||||
$migrationNotice = $_SESSION['migration_notice'] ?? null;
|
||||
$migrationError = null;
|
||||
unset($_SESSION['migration_notice']);
|
||||
|
||||
// BESTANDS-UPLOADS NACH WEBP MIGRIEREN
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['migrate_uploads'])) {
|
||||
$submittedToken = (string)($_POST['migration_csrf'] ?? '');
|
||||
if (!hash_equals($migrationCsrf, $submittedToken)) {
|
||||
$migrationError = 'Die Migrationsanfrage ist abgelaufen. Bitte Seite neu laden und erneut versuchen.';
|
||||
} else {
|
||||
try {
|
||||
$_SESSION['migration_notice'] = migrate_uploads_to_webp();
|
||||
header('Location: admin.php?migration=done');
|
||||
exit;
|
||||
} catch (Throwable $e) {
|
||||
$migrationError = 'Migration fehlgeschlagen: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CREATE/UPDATE
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_event'])) {
|
||||
elseif ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_event'])) {
|
||||
$events = load_events();
|
||||
$id = $_POST['id'] ?: 'evt_' . bin2hex(random_bytes(6));
|
||||
$title = sanitize_text($_POST['title'] ?? '');
|
||||
@@ -121,6 +145,13 @@ if ($loggedIn) {
|
||||
if ($e['id'] === $id) { $editEvent = $e; break; }
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$nonWebpUploads = find_non_webp_uploads();
|
||||
} catch (Throwable $e) {
|
||||
$nonWebpUploads = [];
|
||||
$migrationError = 'Upload-Prüfung fehlgeschlagen: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
@@ -191,6 +222,43 @@ if ($loggedIn) {
|
||||
<?php if (isset($_GET['deleted'])): ?><span class="badge text-bg-warning">Gelöscht</span><?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($migrationError)): ?>
|
||||
<div class="alert alert-danger" role="alert"><?= h($migrationError) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (is_array($migrationNotice)): ?>
|
||||
<?php if (!empty($migrationNotice['remaining'])): ?>
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<?= (int)$migrationNotice['processed'] ?> Bild(er) wurden konvertiert und
|
||||
<?= (int)$migrationNotice['references'] ?> Datenbank-Verweis(e) aktualisiert.
|
||||
<?= count($migrationNotice['remaining']) ?> Originaldatei(en) konnten nicht entfernt werden und werden erneut angeboten.
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-success" role="alert">
|
||||
Migration abgeschlossen: <?= (int)$migrationNotice['processed'] ?> Bild(er) konvertiert und
|
||||
<?= (int)$migrationNotice['references'] ?> Datenbank-Verweis(e) aktualisiert.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($nonWebpUploads)): ?>
|
||||
<div class="alert alert-warning d-md-flex justify-content-between align-items-center gap-3" role="alert">
|
||||
<div class="mb-3 mb-md-0">
|
||||
<div class="fw-semibold">WebP-Migration verfügbar</div>
|
||||
<div class="small">
|
||||
<?= count($nonWebpUploads) ?> vorhandene(s) Upload-Bild(er) sind noch nicht als WebP gespeichert.
|
||||
Die Veranstaltungseinträge werden automatisch aktualisiert.
|
||||
</div>
|
||||
</div>
|
||||
<form method="post" onsubmit="return confirm('Alle erkannten Bestandsbilder jetzt nach WebP konvertieren?');">
|
||||
<input type="hidden" name="migration_csrf" value="<?= h($migrationCsrf) ?>">
|
||||
<button class="btn btn-warning text-nowrap" type="submit" name="migrate_uploads" value="1">
|
||||
In WebP konvertieren
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row g-4">
|
||||
<div class="col-lg-5">
|
||||
<div class="card shadow-sm">
|
||||
|
||||
Reference in New Issue
Block a user