61 lines
1.8 KiB
PHP
61 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
require_once __DIR__ . '/CronRuntime.php';
|
||
|
|
|
||
|
|
$usage = <<<TXT
|
||
|
|
Usage:
|
||
|
|
php cli/task_cert_recalculate_escalations.php [--apply|--dry-run] [--task_id=<id>] [--no-lock] [--json]
|
||
|
|
|
||
|
|
Options:
|
||
|
|
--apply Mutierender Lauf (Status/Eskalationslevel schreiben)
|
||
|
|
--dry-run Nur Vorschau, keine DB-Änderungen
|
||
|
|
--task_id Optional: nur eine Aufgabe verarbeiten
|
||
|
|
--no-lock Locking deaktivieren (nur Debug)
|
||
|
|
--json JSON-Ausgabe zusätzlich auf stdout
|
||
|
|
--help Diese Hilfe anzeigen
|
||
|
|
TXT;
|
||
|
|
|
||
|
|
try {
|
||
|
|
$options = TaskCertCronRuntime::parseOptions($argv, true);
|
||
|
|
} catch (InvalidArgumentException $exception) {
|
||
|
|
TaskCertCronRuntime::printOptionError($exception->getMessage(), $usage);
|
||
|
|
exit(2);
|
||
|
|
}
|
||
|
|
|
||
|
|
if ((bool) ($options['help'] ?? false)) {
|
||
|
|
TaskCertCronRuntime::printUsage($usage);
|
||
|
|
exit(0);
|
||
|
|
}
|
||
|
|
|
||
|
|
$exitCode = TaskCertCronRuntime::runWithHandling(
|
||
|
|
'recalculate_escalations',
|
||
|
|
$options,
|
||
|
|
static function () use ($options): array {
|
||
|
|
require_once dirname(__DIR__) . '/bootstrap.php';
|
||
|
|
$services = task_cert_services();
|
||
|
|
$escalationService = $services['escalationService'] ?? null;
|
||
|
|
if (!$escalationService instanceof EscalationService) {
|
||
|
|
throw new RuntimeException('EscalationService nicht verfügbar.');
|
||
|
|
}
|
||
|
|
|
||
|
|
$apply = (bool) ($options['apply'] ?? false);
|
||
|
|
$taskId = (int) ($options['task_id'] ?? 0);
|
||
|
|
|
||
|
|
$summary = $escalationService->recalculateEscalationsDetailed(
|
||
|
|
$apply,
|
||
|
|
$taskId > 0 ? $taskId : null
|
||
|
|
);
|
||
|
|
|
||
|
|
if ($apply) {
|
||
|
|
CronHeartbeat::record('recalculate_escalations', [
|
||
|
|
'changed' => (int) ($summary['changed_assignments'] ?? 0),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $summary;
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
exit($exitCode);
|