LuminaWebsite/map_install_action.php
Maaxxs 444969f8dc Karte: don't fail with HTTP 500 when the map tables are missing
An installation that predates the map update has none of the four map
tables, so the first query threw an uncaught PDOException and the page
answered 500 with an empty body - no hint what was wrong.

map.php now checks for the tables up front and shows a setup page instead:
it names the missing tables and, for accounts with roles.manage, offers a
button that creates them. The statements are extracted from
sql/schema.sql at runtime, so the schema file stays the single source of
truth and cannot drift from what gets created. They are all CREATE TABLE IF
NOT EXISTS, so running it twice is harmless, and doing it by hand in
phpMyAdmin remains equivalent.

Reproduced against a database built from the pre-update schema: map.php
returned 500, now returns 200 with the setup page, the button creates all
four tables, and the map renders afterwards.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 14:39:55 +02:00

33 lines
1,015 B
PHP

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/map.php';
// Struktur der Datenbank zu aendern ist eine Administratoren-Aufgabe - deshalb nicht an
// map.manage haengen, sondern an dieselbe Berechtigung wie die Rechteverwaltung.
require_permission('roles.manage');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/map.php');
}
verify_csrf();
$missing = map_missing_tables();
if (empty($missing)) {
set_flash('success', 'Die Kartentabellen sind bereits vorhanden.');
redirect('/map.php');
}
try {
map_create_tables();
$stillMissing = map_missing_tables();
if (!empty($stillMissing)) {
set_flash('error', 'Diese Tabellen konnten nicht angelegt werden: ' . implode(', ', $stillMissing));
} else {
set_flash('success', 'Die Kartentabellen wurden angelegt. Die Karte ist jetzt einsatzbereit.');
}
} catch (Throwable $e) {
set_flash('error', 'Anlegen fehlgeschlagen: ' . $e->getMessage());
}
redirect('/map.php');