64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
require_once dirname(dirname(__DIR__)) . '/bootstrap.php';
|
||
|
|
|
||
|
|
$auth = TaskCertAuthContext::fromGlobals();
|
||
|
|
$isCli = PHP_SAPI === 'cli';
|
||
|
|
|
||
|
|
if (!$isCli && !TaskCertRequest::isPost()) {
|
||
|
|
TaskCertResponse::error('Methode nicht erlaubt', 405);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!$isCli) {
|
||
|
|
if (!$auth->hasPermission('r-task-cert-admin')) {
|
||
|
|
TaskCertResponse::error('Keine Berechtigung', 403);
|
||
|
|
}
|
||
|
|
|
||
|
|
TaskCertCsrf::assertValidFromRequest(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
try {
|
||
|
|
$services = task_cert_services();
|
||
|
|
$apply = true;
|
||
|
|
$taskId = null;
|
||
|
|
|
||
|
|
if ($isCli) {
|
||
|
|
$options = getopt('', ['task_id::', 'apply', 'dry-run']);
|
||
|
|
if ($options !== false) {
|
||
|
|
if (isset($options['task_id']) && !is_array($options['task_id'])) {
|
||
|
|
$parsedTaskId = (int) $options['task_id'];
|
||
|
|
if ($parsedTaskId > 0) {
|
||
|
|
$taskId = $parsedTaskId;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($options['dry-run'])) {
|
||
|
|
$apply = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($options['apply'])) {
|
||
|
|
$apply = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$summary = $services['escalationService']->recalculateEscalationsDetailed($apply, $taskId);
|
||
|
|
$changed = (int) ($summary['changed_assignments'] ?? 0);
|
||
|
|
|
||
|
|
if ($apply) {
|
||
|
|
CronHeartbeat::record('recalculate_escalations', ['changed' => $changed]);
|
||
|
|
}
|
||
|
|
|
||
|
|
TaskCertResponse::json([
|
||
|
|
'success' => true,
|
||
|
|
'changed' => $changed,
|
||
|
|
'summary' => $summary,
|
||
|
|
]);
|
||
|
|
} catch (Throwable $throwable) {
|
||
|
|
TaskCertResponse::json([
|
||
|
|
'success' => false,
|
||
|
|
'error' => $throwable->getMessage(),
|
||
|
|
], 400);
|
||
|
|
}
|