update
This commit is contained in:
@@ -160,6 +160,29 @@ final class AutomationController
|
||||
return Response::redirect('/settings/automation');
|
||||
}
|
||||
|
||||
public function duplicate(Request $request): Response
|
||||
{
|
||||
$error = $this->validateCsrf($request);
|
||||
if ($error !== null) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
$id = (int) $request->input('id', '0');
|
||||
if ($id <= 0) {
|
||||
Flash::set('settings.automation.error', 'Nieprawidlowy identyfikator');
|
||||
return Response::redirect('/settings/automation');
|
||||
}
|
||||
|
||||
try {
|
||||
$this->repository->duplicate($id);
|
||||
Flash::set('settings.automation.success', 'Zadanie zostalo zduplikowane');
|
||||
} catch (Throwable) {
|
||||
Flash::set('settings.automation.error', 'Blad duplikowania zadania');
|
||||
}
|
||||
|
||||
return Response::redirect('/settings/automation');
|
||||
}
|
||||
|
||||
public function toggleStatus(Request $request): Response
|
||||
{
|
||||
$error = $this->validateCsrf($request);
|
||||
|
||||
@@ -126,6 +126,28 @@ final class AutomationRepository
|
||||
$statement->execute(['id' => $id]);
|
||||
}
|
||||
|
||||
public function duplicate(int $id): int
|
||||
{
|
||||
$source = $this->findById($id);
|
||||
if ($source === null) {
|
||||
throw new \RuntimeException('Zadanie nie istnieje');
|
||||
}
|
||||
|
||||
$conditions = array_map(static function (array $c): array {
|
||||
return ['type' => $c['condition_type'], 'value' => $c['condition_value']];
|
||||
}, $source['conditions']);
|
||||
|
||||
$actions = array_map(static function (array $a): array {
|
||||
return ['type' => $a['action_type'], 'config' => $a['action_config']];
|
||||
}, $source['actions']);
|
||||
|
||||
return $this->create(
|
||||
['name' => 'Kopia — ' . $source['name'], 'event_type' => $source['event_type'], 'is_active' => 0],
|
||||
$conditions,
|
||||
$actions
|
||||
);
|
||||
}
|
||||
|
||||
public function toggleActive(int $id): void
|
||||
{
|
||||
$statement = $this->pdo->prepare(
|
||||
|
||||
Reference in New Issue
Block a user