47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Täglicher Erinnerungslauf (Push + optional E-Mail).
|
|
*
|
|
* Cron-Beispiel (täglich 07:00):
|
|
* 0 7 * * * /usr/bin/php /pfad/zu/drink-it-cold/tools/send_reminders.php
|
|
*
|
|
* Alternativ von außen über den token-geschützten Endpoint:
|
|
* https://…/cron/reminders?token=<cron_token>
|
|
*/
|
|
|
|
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]));
|
|
}
|
|
}
|
|
|
|
$push = push_dispatch_due($lookback);
|
|
$mail = reminder_send_due($lookback);
|
|
|
|
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']
|
|
));
|
|
}
|
|
|
|
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");
|
|
}
|
|
}
|
|
|
|
exit(($mail['errors'] || $push['failed'] > 0) ? 1 : 0);
|