23 lines
1.1 KiB
PHP
23 lines
1.1 KiB
PHP
<?php
|
|
// Direkter Web-Zugriff wird geblockt (nur CLI oder Einbindung aus dem Backend/Pseudo-Cron).
|
|
if (php_sapi_name() !== 'cli' && !defined('DESKHUB_CRON_RUNNER')) { http_response_code(403); exit('Kein Web-Zugriff.'); }
|
|
/**
|
|
* cron/send_report_schedules.php
|
|
*
|
|
* Versendet gespeicherte Berichte nach Zeitplan per E-Mail (Bericht-Baukasten → „Versand per E-Mail“). Läuft alle paar Minuten, z. B.:
|
|
* * /5 * * * * /usr/bin/php /pfad/zu/deskhub/cron/send_report_schedules.php
|
|
*/
|
|
require_once __DIR__ . '/../includes/bootstrap.php';
|
|
|
|
/** @return array{sent:int, failed:int, log:string[]} */
|
|
function run_send_report_schedules(PDO $pdo, bool $verbose = false): array
|
|
{
|
|
$r = report_schedules_run_due($pdo);
|
|
set_setting('cron_send_report_schedules_last_run', db_now());
|
|
return $r + ['log' => ['[' . date('Y-m-d H:i:s') . "] Berichte per E-Mail: {$r['sent']} gesendet, {$r['failed']} fehlgeschlagen."]];
|
|
}
|
|
|
|
if (php_sapi_name() === 'cli' && realpath($_SERVER['SCRIPT_FILENAME'] ?? '') === __FILE__) {
|
|
foreach (run_send_report_schedules(get_db(), true)['log'] as $line) echo $line . "\n";
|
|
}
|