2026-11-13 00:35:39 +01:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
/**
|
2026-11-13 01:03:54 +01:00
|
|
|
* Täglicher Erinnerungslauf (Push + optional E-Mail).
|
2026-11-13 00:35:39 +01:00
|
|
|
*
|
|
|
|
|
* Cron-Beispiel (täglich 07:00):
|
|
|
|
|
* 0 7 * * * /usr/bin/php /pfad/zu/drink-it-cold/tools/send_reminders.php
|
|
|
|
|
*
|
2026-11-13 01:03:54 +01:00
|
|
|
* Alternativ von außen über den token-geschützten Endpoint:
|
|
|
|
|
* https://…/cron/reminders?token=<cron_token>
|
2026-11-13 00:35:39 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
require __DIR__ . '/../app/bootstrap.php';
|
|
|
|
|
|
|
|
|
|
$lookback = 7;
|
|
|
|
|
foreach ($argv ?? [] as $arg) {
|
|
|
|
|
if (preg_match('/^--lookback=(\d+)$/', $arg, $m)) {
|
|
|
|
|
$lookback = max(1, min(60, (int) $m[1]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-18 20:59:17 +01:00
|
|
|
$cleanup = privacy_cleanup();
|
2026-11-13 01:03:54 +01:00
|
|
|
$push = push_dispatch_due($lookback);
|
|
|
|
|
$mail = reminder_send_due($lookback);
|
2026-11-13 00:35:39 +01:00
|
|
|
|
2026-11-18 20:59:17 +01:00
|
|
|
fwrite(STDOUT, sprintf(
|
2026-11-18 22:20:37 +01:00
|
|
|
"Aufräumen: %d Login-Fehlversuche, %d Tokens, %d Einladungen, %d E-Mail-Protokolle, %d Push-Protokolle entfernt%s.\n",
|
|
|
|
|
$cleanup['login_attempts'], $cleanup['auth_tokens'], $cleanup['user_invites'],
|
|
|
|
|
$cleanup['reminder_mail_log'],
|
2026-11-18 20:59:17 +01:00
|
|
|
$cleanup['reminder_push_log'], $cleanup['log_rotated'] ? ', Fehlerprotokoll rotiert' : ''
|
|
|
|
|
));
|
|
|
|
|
|
2026-11-13 01:03:54 +01:00
|
|
|
if (!push_is_configured()) {
|
|
|
|
|
fwrite(STDOUT, "Push: nicht konfiguriert (VAPID-Schlüssel fehlen).\n");
|
|
|
|
|
} else {
|
|
|
|
|
fwrite(STDOUT, sprintf(
|
|
|
|
|
"Push: %d gesendet, %d fehlgeschlagen, %d abgelaufene Abos entfernt, %d ohne Abo.\n",
|
|
|
|
|
$push['sent'], $push['failed'], $push['removed'], $push['skipped_no_subscription']
|
|
|
|
|
));
|
2026-11-13 00:35:39 +01:00
|
|
|
}
|
|
|
|
|
|
2026-11-13 01:03:54 +01:00
|
|
|
if (!$mail['enabled']) {
|
|
|
|
|
fwrite(STDOUT, "E-Mail: deaktiviert.\n");
|
|
|
|
|
} else {
|
|
|
|
|
fwrite(STDOUT, sprintf("E-Mail: %d versendet, %d übersprungen.\n", $mail['sent'], $mail['skipped']));
|
|
|
|
|
foreach ($mail['details'] as $detail) {
|
|
|
|
|
fwrite(STDOUT, ' ' . $detail . "\n");
|
|
|
|
|
}
|
|
|
|
|
foreach ($mail['errors'] as $error) {
|
|
|
|
|
fwrite(STDERR, ' Fehler: ' . $error . "\n");
|
|
|
|
|
}
|
2026-11-13 00:35:39 +01:00
|
|
|
}
|
2026-11-13 01:03:54 +01:00
|
|
|
|
|
|
|
|
exit(($mail['errors'] || $push['failed'] > 0) ? 1 : 0);
|