From 27a267893e3626bffd76e04fe22a341c7a3c2bdf Mon Sep 17 00:00:00 2001 From: torsten Date: Sun, 22 Nov 2026 19:05:40 +0100 Subject: [PATCH] Deploy: DB-Verbindung vor Upload pruefen (falscher DB_HOST brach die App), Warnung beim Anlegen-Formular behoben --- .pi/docs/deploy.md | 5 ++++- westreiche_website/app/pages.php | 2 +- westreiche_website/tools/deploy_app.sh | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.pi/docs/deploy.md b/.pi/docs/deploy.md index 60528fb..ae2e395 100644 --- a/.pi/docs/deploy.md +++ b/.pi/docs/deploy.md @@ -24,7 +24,10 @@ Zugangsdaten stehen in `credentials.txt` im Projektwurzelverzeichnis (per (Spiel-Zusammenfassungen, Zauber-/Liturgie-Summarien, SL-Material) bleiben lokal in `RPG/7-Prep/…` bzw. am bisherigen Ablageort. Nichts davon in `APP_DIRECTORY` verschieben oder umleiten. -- **`DB_HOST`** (`mxzh.your-database.de`, Hetzner Managed MariaDB) + `DB_NAME`, +- **`DB_HOST`** (`mxzh.your-database.de`, Hetzner Managed MariaDB) – **nur +der Alias funktioniert**: `sql400.your-server.de` (bzw. der Webserver selbst) +hat keine Grants und liefert `1045 Access denied`. `deploy_app.sh` prüft die +Verbindung vor dem Upload und bricht sonst ab + `DB_NAME`, `DB_USER`, `DB_PASSWORD` – erreichbar über Port 3306 von außen, DB derzeit ohne Tabellen. **Achtung:** In der Datei steht ein nachgestelltes Leerzeichen, vor Nutzung trimmen (`tr -d '[:space:]'`). Nicht `FTP_URL` als DB-Host nutzen. diff --git a/westreiche_website/app/pages.php b/westreiche_website/app/pages.php index ddcd6d1..7525fa1 100644 --- a/westreiche_website/app/pages.php +++ b/westreiche_website/app/pages.php @@ -548,7 +548,7 @@ function character_form_values(array $source): array )); $values['hp_max'] = max(1, post_int('hp_max', (int) ($source['hp_max'] ?? 1))); $values['hp_current'] = post_int('hp_current', (int) ($source['hp_current'] ?? $values['hp_max'])); - $acRaw = post_string('ac', $source['ac'] === null ? '' : (string) $source['ac']); + $acRaw = post_string('ac', ($source['ac'] ?? null) === null ? '' : (string) $source['ac']); $values['ac'] = $acRaw === '' ? null : max(-10, min(30, (int) $acRaw)); $values['attack_bonus'] = post_int('attack_bonus', (int) ($source['attack_bonus'] ?? 0)); $values['gold_coins'] = post_int('gold_coins', (int) ($source['gold_coins'] ?? 0)); diff --git a/westreiche_website/tools/deploy_app.sh b/westreiche_website/tools/deploy_app.sh index 7dbfa7a..1e07ffd 100755 --- a/westreiche_website/tools/deploy_app.sh +++ b/westreiche_website/tools/deploy_app.sh @@ -99,6 +99,18 @@ return [ open(path, "w", encoding="utf-8").write(content) PY +# Vorab-Check: Akzeptiert der DB-Server diese Zugangsdaten? Sonst würde der +# Upload eine vorher laufende App mit einer toten config.local.php ersetzen. +if command -v mysql >/dev/null 2>&1; then + DB_HOST_CLEAN="$(printf '%s' "${DB_HOST}" | tr -d '[:space:]')" + if ! MYSQL_PWD="${DB_PASSWORD}" mysql -h "${DB_HOST_CLEAN}" -u "${DB_USER}" \ + --connect-timeout=8 -e 'SELECT 1' "${DB_NAME}" >/dev/null 2>&1; then + echo "FEHLER: DB-Verbindung zu ${DB_USER}@${DB_HOST_CLEAN}/${DB_NAME} schlägt fehl." >&2 + echo " DB_HOST in credentials.txt prüfen (richtig ist mxzh.your-database.de)." >&2 + exit 1 + fi +fi + upload() { local src="$1" dst="$2" if [[ ${DRY_RUN} -eq 1 ]]; then