| @@ -6,15 +6,14 @@ | ||
| 6 | 6 | use AcyMailing\Classes\AutomationClass; |
| 7 | 7 | use AcyMailing\Classes\ConditionClass; |
| 8 | 8 | use AcyMailing\Classes\MailClass; |
| 9 | 9 | use AcyMailing\Classes\StepClass; |
| 10 | -use AcyMailing\Classes\TagClass; | |
| 11 | 10 | use AcyMailing\Helpers\PaginationHelper; |
| 12 | 11 | use AcyMailing\Helpers\ToolbarHelper; |
| 13 | 12 | |
| 14 | 13 | trait Listing |
| 15 | 14 | { |
| 16 | - public function listing() | |
| 15 | + public function listing(): void | |
| 17 | 16 | { |
| 18 | 17 | if (!acym_level(ACYM_ENTERPRISE)) { |
| 19 | 18 | acym_redirect(acym_completeLink('dashboard&task=upgrade&version=enterprise', false, true)); |
| 20 | 19 | } |
| @@ -20,9 +19,9 @@ | ||
| 20 | 19 | } |
| 21 | 20 | |
| 22 | 21 | } |
| 23 | 22 | |
| 24 | - public function prepareToolbar(&$data) | |
| 23 | + public function prepareToolbar(array &$data): void | |
| 25 | 24 | { |
| 26 | 25 | $toolbarHelper = new ToolbarHelper(); |
| 27 | 26 | $toolbarHelper->addSearchBar($data['search'], 'automation_search', 'ACYM_SEARCH'); |
| 28 | 27 | $toolbarHelper->addButton(acym_translation('ACYM_NEW_MASS_ACTION'), ['data-task' => 'edit', 'data-step' => 'action'], 'cog'); |
| @@ -30,13 +29,13 @@ | ||
| 30 | 29 | |
| 31 | 30 | $data['toolbar'] = $toolbarHelper; |
| 32 | 31 | } |
| 33 | 32 | |
| 34 | - public function duplicate() | |
| 33 | + public function duplicate(): void | |
| 35 | 34 | { |
| 36 | - acym_checkToken(); | |
| 35 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 37 | 36 | |
| 38 | - $automations = acym_getVar('int', 'elements_checked'); | |
| 37 | + $automations = acym_getVar('array', 'elements_checked', []); | |
| 39 | 38 | |
| 40 | 39 | if (empty($automations)) { |
| 41 | 40 | $this->listing(); |
| 42 | 41 | |
| @@ -77,9 +76,9 @@ | ||
| 77 | 76 | $action->condition_id = $newConditionId; |
| 78 | 77 | if (!empty($action->actions) && strpos($action->actions, 'acy_add_queue') !== false) { |
| 79 | 78 | $action->actions = json_decode($action->actions, true); |
| 80 | 79 | $mailClass = new MailClass(); |
| 81 | - foreach ($action->actions as &$oneAction) { | |
| 80 | + foreach ($action->actions as & $oneAction) { | |
| 82 | 81 | if (!empty($oneAction['acy_add_queue']['mail_id'])) { |
| 83 | 82 | $newMail = $mailClass->duplicateMail($oneAction['acy_add_queue']['mail_id'], MailClass::TYPE_AUTOMATION); |
| 84 | 83 | if (!empty($newMail)) { |
| 85 | 84 | $oneAction['acy_add_queue']['mail_id'] = $newMail->id; |
| @@ -93,6 +92,47 @@ | ||
| 93 | 92 | } |
| 94 | 93 | } |
| 95 | 94 | |
| 96 | 95 | $this->listing(); |
| 96 | + } | |
| 97 | + | |
| 98 | + public function triggerAutomation(): void | |
| 99 | + { | |
| 100 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 101 | + | |
| 102 | + $automationIds = acym_getVar('array', 'elements_checked', []); | |
| 103 | + | |
| 104 | + if (empty($automationIds)) { | |
| 105 | + $this->listing(); | |
| 106 | + | |
| 107 | + return; | |
| 108 | + } | |
| 109 | + | |
| 110 | + $automationClass = new AutomationClass(); | |
| 111 | + $result = $automationClass->triggerManual($automationIds); | |
| 112 | + | |
| 113 | + if ($result['executed'] > 0) { | |
| 114 | + acym_enqueueMessage(acym_translationSprintf('ACYM_X_AUTOMATIONS_TRIGGERED', $result['executed']), 'info'); | |
| 115 | + } | |
| 116 | + | |
| 117 | + if ($result['skipped'] > 0) { | |
| 118 | + acym_enqueueMessage(acym_translationSprintf('ACYM_X_SKIPPED_USER_AUTOMATIONS', $result['skipped']), 'warning'); | |
| 119 | + } | |
| 120 | + | |
| 121 | + $this->listing(); | |
| 122 | + } | |
| 123 | + | |
| 124 | + public function ajaxSetOrdering(): void | |
| 125 | + { | |
| 126 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 127 | + | |
| 128 | + $order = json_decode(acym_getVar('string', 'order') ?? '[]', true); | |
| 129 | + | |
| 130 | + $error = false; | |
| 131 | + foreach ($order as $index => $automationId) { | |
| 132 | + $query = 'UPDATE #__acym_automation SET `ordering` = '.intval($index + 1).' WHERE `id` = '.intval($automationId); | |
| 133 | + $error = acym_query($query) < 0 || $error; | |
| 134 | + } | |
| 135 | + | |
| 136 | + acym_sendAjaxResponse('', [], !$error); | |
| 97 | 137 | } |
| 98 | 138 | } |