| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Hooks\Scheduler; |
| 4 |
|
| 5 |
use FluentBooking\App\Modules\MCP\Support\WriteGuard; |
| 6 |
use FluentBooking\App\Services\SummaryReportService; |
| 7 |
|
| 8 |
class DailyScheduler |
| 9 |
{ |
| 10 |
public function register() |
| 11 |
{ |
| 12 |
add_action('fluent_booking/daily_tasks', [$this, 'handleDailyTasks']); |
| 13 |
} |
| 14 |
|
| 15 |
public function handleDailyTasks() |
| 16 |
{ |
| 17 |
// The purge runs first, and in its own try: MCP confirm-token and |
| 18 |
// idempotency records live in options rather than transients (they |
| 19 |
// need an atomic claim and must survive a cache flush), so nothing |
| 20 |
// else expires them — and behind the summary, a slow or throwing |
| 21 |
// summary would starve them out of the tick indefinitely. |
| 22 |
try { |
| 23 |
WriteGuard::purgeExpired(); |
| 24 |
} catch (\Throwable $e) { |
| 25 |
if (defined('FLUENT_BOOKING_DEBUG') && FLUENT_BOOKING_DEBUG) { |
| 26 |
error_log('FluentBooking MCP purge failed: ' . $e->getMessage()); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
SummaryReportService::maybeSendSummary(); |
| 31 |
} |
| 32 |
} |