feat: add UI for CRON Scheduler

This commit is contained in:
2025-12-06 23:49:17 +03:00
parent 65973d2d79
commit 7372b9c330
5 changed files with 155 additions and 0 deletions

View File

@@ -69,10 +69,19 @@ class SettingsHandler
'sliders',
'mainpage_blocks',
'pulse',
'cron',
]);
if (!isset($data['cron']['mode'])) {
$data['cron']['mode'] = 'disabled';
}
$data['forms'] = [];
// Add CRON system details (read-only)
$data['cron']['cli_path'] = realpath(DIR_SYSTEM . '../cli.php');
$data['cron']['last_run'] = $this->getLastCronRunDate();
$forms = $this->builder->newQuery()
->from('telecart_forms')
->get();
@@ -103,6 +112,12 @@ class SettingsHandler
$this->validate($input);
// Remove dynamic properties before saving
if (isset($input['cron'])) {
unset($input['cron']['cli_path']);
unset($input['cron']['last_run']);
}
$this->settingsUpdateService->update(
Arr::getWithKeys($input, [
'app',
@@ -114,6 +129,7 @@ class SettingsHandler
'sliders',
'mainpage_blocks',
'pulse',
'cron',
]),
);
@@ -145,4 +161,25 @@ class SettingsHandler
return new JsonResponse([], Response::HTTP_ACCEPTED);
}
private function getLastCronRunDate(): ?string
{
try {
// Since we are in SettingsHandler, we already have access to container or we can inject SchedulerService
// But SettingsHandler is constructed via DI. Let's add SchedulerService to constructor.
// For now, let's use global retrieval via cache if possible, or assume it's injected.
// But wait, getLastCronRunDate logic was in controller.
// SchedulerService stores last run in cache. We have $this->cache here.
$lastRunTimestamp = $this->cache->get("scheduler.global_last_run");
if ($lastRunTimestamp) {
return date('d.m.Y H:i:s', (int)$lastRunTimestamp);
}
return null;
} catch (Exception $e) {
return null;
}
}
}