62 lines
1.9 KiB
PHP
62 lines
1.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
if (PHP_SAPI !== 'cli') {
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
header('X-Robots-Tag: noindex, nofollow');
|
|
$remote = (string) ($_SERVER['REMOTE_ADDR'] ?? '');
|
|
if (!in_array($remote, ['127.0.0.1', '::1'], true)) {
|
|
http_response_code(403);
|
|
exit("Forbidden
|
|
");
|
|
}
|
|
}
|
|
|
|
require_once __DIR__ . '/db/config.php';
|
|
require_once __DIR__ . '/includes/DatabaseInstaller.php';
|
|
|
|
$wablasHelperPath = __DIR__ . '/includes/wablas_helper.php';
|
|
if (!is_file($wablasHelperPath)) {
|
|
$message = 'Wablas helper is missing from this deployment: includes/wablas_helper.php';
|
|
@file_put_contents(
|
|
__DIR__ . '/runtime_debug.log',
|
|
date('Y-m-d H:i:s') . " || [cron_wablas_missing_helper] || {$message}" . PHP_EOL,
|
|
FILE_APPEND
|
|
);
|
|
if (PHP_SAPI !== 'cli') {
|
|
http_response_code(503);
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
header('X-Robots-Tag: noindex, nofollow');
|
|
}
|
|
exit($message . PHP_EOL);
|
|
}
|
|
require_once $wablasHelperPath;
|
|
|
|
DatabaseInstaller::ensureCurrentSchema();
|
|
|
|
$now = wablasNow();
|
|
echo '[' . $now->format('Y-m-d H:i:s') . "] Starting Wablas automation run
|
|
";
|
|
|
|
$dailyQueue = wablasQueueDailySummaryIfDue($now);
|
|
if (!empty($dailyQueue['queued'])) {
|
|
echo 'Queued daily summary for ' . (($dailyQueue['scheduled_for'] ?? $now->format('Y-m-d H:i:s'))) . "
|
|
";
|
|
} elseif (!empty($dailyQueue['reason']) && ($dailyQueue['reason'] ?? '') !== 'not_due') {
|
|
echo 'Daily summary: ' . $dailyQueue['reason'] . "
|
|
";
|
|
}
|
|
|
|
$processed = wablasProcessDueDispatches(25);
|
|
echo 'Checked: ' . (int) ($processed['checked'] ?? 0)
|
|
. ' | Sent: ' . (int) ($processed['sent'] ?? 0)
|
|
. ' | Failed: ' . (int) ($processed['failed'] ?? 0)
|
|
. ' | Skipped: ' . (int) ($processed['skipped'] ?? 0)
|
|
. "
|
|
";
|
|
|
|
foreach (($processed['messages'] ?? []) as $message) {
|
|
echo '- ' . $message . "
|
|
";
|
|
}
|