93 lines
3.3 KiB
PHP
93 lines
3.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Deploy-Selbsttest — NUR CLI. Prüft alles, was nach dem Hochladen stimmen muss,
|
||
|
|
* bevor die Seite Besucher sieht: Konfiguration, Secrets, Schreibrechte,
|
||
|
|
* Composer-Abhängigkeiten, PHP-Version, Datenstände.
|
||
|
|
*
|
||
|
|
* Prüft NICHT den SMTP-Login (Netzwerkzugriff) — dafür: php bin/smtp-test.php
|
||
|
|
*
|
||
|
|
* Aufruf: php bin/preflight.php (Exit 0 = startklar, 1 = Fehler offen)
|
||
|
|
*/
|
||
|
|
if (PHP_SAPI !== 'cli') {
|
||
|
|
exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
require dirname(__DIR__) . '/app/bootstrap.php';
|
||
|
|
|
||
|
|
$errors = [];
|
||
|
|
$warnings = [];
|
||
|
|
|
||
|
|
// --- Konfiguration & Secrets (dieselbe Prüfung, die auch die Formular-Actions macht) ---
|
||
|
|
foreach (config_problems() as $problem) {
|
||
|
|
$errors[] = $problem;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((string) config('env') !== 'production') {
|
||
|
|
$errors[] = "env steht auf '" . (string) config('env') . "' — in Produktion 'production' (sonst zeigt die Seite PHP-Fehler).";
|
||
|
|
}
|
||
|
|
|
||
|
|
$baseUrl = (string) config('base_url');
|
||
|
|
if (!str_starts_with($baseUrl, 'https://')) {
|
||
|
|
$errors[] = "base_url ist nicht https ({$baseUrl}) — Canonical, OG und Sitemap wären falsch.";
|
||
|
|
}
|
||
|
|
if (str_ends_with($baseUrl, '/')) {
|
||
|
|
$warnings[] = 'base_url endet auf "/" — abs_url() erzeugt dann doppelte Slashes.';
|
||
|
|
}
|
||
|
|
|
||
|
|
// --- Abhängigkeiten ---
|
||
|
|
if (!is_file(ROOT_PATH . '/vendor/autoload.php')) {
|
||
|
|
$errors[] = 'vendor/ fehlt — auf dem Server "composer install --no-dev --optimize-autoloader" laufen lassen.';
|
||
|
|
} elseif (!class_exists(PHPMailer\PHPMailer\PHPMailer::class)) {
|
||
|
|
$errors[] = 'PHPMailer ist nicht ladbar — vendor/ unvollständig?';
|
||
|
|
}
|
||
|
|
|
||
|
|
if (version_compare(PHP_VERSION, '8.1', '<')) {
|
||
|
|
$errors[] = 'PHP ' . PHP_VERSION . ' ist zu alt — mindestens 8.1 (der Code nutzt never-Return-Types und enums-Syntax).';
|
||
|
|
}
|
||
|
|
|
||
|
|
// --- Schreibrechte (Logs, Rate-Limit-Zähler, Sync-Caches) ---
|
||
|
|
foreach (['logs', 'ratelimit', 'cache'] as $dir) {
|
||
|
|
$path = STORAGE_PATH . '/' . $dir;
|
||
|
|
if (!is_dir($path)) {
|
||
|
|
$errors[] = "storage/{$dir}/ fehlt.";
|
||
|
|
} elseif (!is_writable($path)) {
|
||
|
|
$errors[] = "storage/{$dir}/ ist nicht beschreibbar (Rate-Limiting und Logging fielen sonst still aus).";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
foreach (['img/instagram', 'img/crests'] as $dir) {
|
||
|
|
$path = PUBLIC_PATH . '/assets/' . $dir;
|
||
|
|
if (!is_dir($path) || !is_writable($path)) {
|
||
|
|
$warnings[] = "public/assets/{$dir}/ fehlt oder ist nicht beschreibbar — der Sync kann dort keine Bilder ablegen.";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// --- Datenstände der Cron-Skripte (fehlen nur beim Erstlauf) ---
|
||
|
|
foreach (['instagram' => 'bin/instagram-sync.php', 'matchcenter' => 'bin/matchcenter-sync.php'] as $name => $script) {
|
||
|
|
$file = DATA_PATH . '/' . $name . '.json';
|
||
|
|
if (!is_file($file)) {
|
||
|
|
$warnings[] = "data/{$name}.json fehlt — einmal \"php {$script}\" von Hand anstoßen.";
|
||
|
|
} elseif (filemtime($file) < time() - 3 * 86400) {
|
||
|
|
$warnings[] = "data/{$name}.json ist älter als 3 Tage — läuft der Cron für {$script}?";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// --- Ausgabe ---
|
||
|
|
foreach ($warnings as $w) {
|
||
|
|
echo "WARNUNG {$w}\n";
|
||
|
|
}
|
||
|
|
foreach ($errors as $e) {
|
||
|
|
echo "FEHLER {$e}\n";
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($errors === []) {
|
||
|
|
echo $warnings === [] ? "Alles startklar.\n" : "Keine Fehler — nur die Warnungen oben prüfen.\n";
|
||
|
|
echo "Nächster Schritt: php bin/smtp-test.php (Login testen) und je eine Testmail über die drei Formulare.\n";
|
||
|
|
exit(0);
|
||
|
|
}
|
||
|
|
|
||
|
|
echo "\n" . count($errors) . " Fehler offen — noch nicht live gehen.\n";
|
||
|
|
exit(1);
|