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(
|
||||
|
||||
@@ -196,6 +196,29 @@ final class EmailTemplateController
|
||||
}
|
||||
}
|
||||
|
||||
public function duplicate(Request $request): Response
|
||||
{
|
||||
if (!Csrf::validate((string) $request->input('_token', ''))) {
|
||||
Flash::set('settings.email_templates.error', 'Nieprawidlowy token CSRF');
|
||||
return Response::redirect('/settings/email-templates');
|
||||
}
|
||||
|
||||
$id = (int) $request->input('id', '0');
|
||||
if ($id <= 0) {
|
||||
Flash::set('settings.email_templates.error', 'Nieprawidlowy identyfikator szablonu');
|
||||
return Response::redirect('/settings/email-templates');
|
||||
}
|
||||
|
||||
try {
|
||||
$this->repository->duplicate($id);
|
||||
Flash::set('settings.email_templates.success', 'Szablon zostal zduplikowany');
|
||||
} catch (Throwable) {
|
||||
Flash::set('settings.email_templates.error', 'Blad duplikowania szablonu');
|
||||
}
|
||||
|
||||
return Response::redirect('/settings/email-templates');
|
||||
}
|
||||
|
||||
public function preview(Request $request): Response
|
||||
{
|
||||
if (!Csrf::validate((string) $request->input('_token', ''))) {
|
||||
|
||||
@@ -119,4 +119,24 @@ final class EmailTemplateRepository
|
||||
);
|
||||
$statement->execute(['id' => $id]);
|
||||
}
|
||||
|
||||
public function duplicate(int $id): void
|
||||
{
|
||||
$source = $this->findById($id);
|
||||
if ($source === null) {
|
||||
throw new \RuntimeException('Szablon nie istnieje');
|
||||
}
|
||||
|
||||
$statement = $this->pdo->prepare(
|
||||
'INSERT INTO email_templates (name, subject, body_html, mailbox_id, attachment_1, is_active)
|
||||
VALUES (:name, :subject, :body_html, :mailbox_id, :attachment_1, 0)'
|
||||
);
|
||||
$statement->execute([
|
||||
'name' => 'Kopia — ' . $source['name'],
|
||||
'subject' => $source['subject'],
|
||||
'body_html' => $source['body_html'],
|
||||
'mailbox_id' => $source['mailbox_id'],
|
||||
'attachment_1' => $source['attachment_1'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user