asdds
All checks were successful
Deploy / deploy-staging (push) Successful in 26s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-06-24 23:50:41 +02:00
parent d121f74bd0
commit 46111d8988
4 changed files with 231 additions and 18 deletions

View File

@@ -155,6 +155,7 @@ final class CronManagementService
foreach ($definitions as $jobKey => $definition) {
$config = $this->jobConfig($jobKey, $definition, $settings);
$state = is_array($states[$jobKey] ?? null) ? $states[$jobKey] : [];
$configured = is_array($settings['jobs'][$jobKey] ?? null);
$timezone = $this->safeTimezone((string) ($config['timezone'] ?? $settings['default_timezone']));
$expression = trim((string) ($config['cron_expression'] ?? ''));
$parseError = null;
@@ -181,6 +182,7 @@ final class CronManagementService
'job_key' => $jobKey,
'config' => $config,
'state' => $state,
'configured' => $configured,
'state_local' => [
'last_started_at' => $this->formatLocal((string) ($state['last_started_at'] ?? ''), $timezone),
'last_finished_at' => $this->formatLocal((string) ($state['last_finished_at'] ?? ''), $timezone),
@@ -189,6 +191,7 @@ final class CronManagementService
],
'enabled' => !empty($config['enabled']),
'cron_expression' => $expression,
'cron_human' => $this->humanizeCronExpression($expression),
'timezone' => $timezone->getName(),
'parse_error' => $parseError,
'is_due' => $isDue,
@@ -373,6 +376,73 @@ final class CronManagementService
return $parsed?->setTimezone($timezone)->format('d.m.Y H:i');
}
private function humanizeCronExpression(string $expression): string
{
$parts = preg_split('/\s+/', trim($expression)) ?: [];
if (count($parts) !== 5) {
return 'Benutzerdefinierter Cron-Ausdruck';
}
[$minute, $hour, $day, $month, $weekday] = $parts;
$time = null;
if (ctype_digit($minute) && ctype_digit($hour)) {
$time = sprintf('%02d:%02d', (int) $hour, (int) $minute);
}
if ($minute === '*' && $hour === '*' && $day === '*' && $month === '*' && $weekday === '*') {
return 'Jede Minute';
}
if (preg_match('/^\*\/(\d+)$/', $minute, $matches) === 1 && $hour === '*' && $day === '*' && $month === '*' && $weekday === '*') {
return 'Alle ' . (int) $matches[1] . ' Minuten';
}
if (ctype_digit($minute) && $hour === '*' && $day === '*' && $month === '*' && $weekday === '*') {
return 'Stuendlich um Minute ' . (int) $minute;
}
if (ctype_digit($minute) && preg_match('/^\*\/(\d+)$/', $hour, $matches) === 1 && $day === '*' && $month === '*' && $weekday === '*') {
return 'Alle ' . (int) $matches[1] . ' Stunden um ' . sprintf('%02d', (int) $minute) . ' Minuten nach voller Stunde';
}
if ($time !== null && $day === '*' && $month === '*' && $weekday === '*') {
return 'Taeglich um ' . $time;
}
if ($time !== null && $day === '*' && $month === '*' && $weekday === '1-5') {
return 'Montag bis Freitag um ' . $time;
}
if ($time !== null && $day === '*' && $month === '*' && preg_match('/^[0-7](,[0-7])*$/', $weekday) === 1) {
$days = array_map([$this, 'weekdayLabel'], explode(',', $weekday));
return implode(', ', array_filter($days)) . ' um ' . $time;
}
if ($time !== null && ctype_digit($day) && $month === '*' && $weekday === '*') {
return 'Monatlich am ' . (int) $day . '. um ' . $time;
}
if ($time !== null && ctype_digit($day) && ctype_digit($month) && $weekday === '*') {
return 'Jaehrlich am ' . (int) $day . '.' . sprintf('%02d', (int) $month) . ' um ' . $time;
}
return 'Benutzerdefiniert: ' . $expression;
}
private function weekdayLabel(string $value): string
{
return match ((int) trim($value)) {
0, 7 => 'Sonntag',
1 => 'Montag',
2 => 'Dienstag',
3 => 'Mittwoch',
4 => 'Donnerstag',
5 => 'Freitag',
6 => 'Samstag',
default => '',
};
}
private function absoluteUrl(string $baseUrl, string $endpointPath): string
{
$baseUrl = rtrim(trim($baseUrl), '/');