← All changes
|
back/dynamics/subscription/SubscriptionAutomationActions.php
+25
-23
10.1.4
→
11.1.0
View file →
| @@ -4,10 +4,19 @@ | ||
| 4 | 4 | use AcyMailing\Classes\ListClass; |
| 5 | 5 | |
| 6 | 6 | trait SubscriptionAutomationActions |
| 7 | 7 | { |
| 8 | - public function onAcymDeclareActions(&$actions) | |
| 8 | + protected function initAutomationActions(): void | |
| 9 | 9 | { |
| 10 | + $this->automationActions = [ | |
| 11 | + 'acy_list' => acym_translation('ACYM_ACYMAILING_LIST'), | |
| 12 | + 'subscribe_followup' => acym_translation('ACYM_SUBSCRIBE_FOLLOW_UP'), | |
| 13 | + 'unsubscribe_followup' => acym_translation('ACYM_UNSUBSCRIBE_FOLLOW_UP'), | |
| 14 | + ]; | |
| 15 | + } | |
| 16 | + | |
| 17 | + public function displayActionOptions_acy_list(): void | |
| 18 | + { | |
| 10 | 19 | $listClass = new ListClass(); |
| 11 | 20 | |
| 12 | 21 | $listActions = [ |
| 13 | 22 | 'sub' => acym_translation('ACYM_SUBSCRIBE_USERS_TO'), |
| @@ -15,32 +24,25 @@ | ||
| 15 | 24 | 'unsub' => acym_translation('ACYM_UNSUBSCRIBE_USERS_TO'), |
| 16 | 25 | ]; |
| 17 | 26 | $lists = $listClass->getAllForSelect(); |
| 18 | 27 | |
| 19 | - $actions['acy_list'] = new stdClass(); | |
| 20 | - $actions['acy_list']->name = acym_translation('ACYM_ACYMAILING_LIST'); | |
| 21 | - ob_start(); | |
| 22 | 28 | include acym_getPartial('actions', 'acy_list'); |
| 23 | - $actions['acy_list']->option = ob_get_clean(); | |
| 29 | + } | |
| 24 | 30 | |
| 31 | + public function displayActionOptions_subscribe_followup(): void | |
| 32 | + { | |
| 25 | 33 | $followupClass = new FollowupClass(); |
| 26 | 34 | $allListFollowups = $followupClass->getAll(); |
| 27 | - $actions['subscribe_followup'] = new stdClass(); | |
| 28 | - $actions['subscribe_followup']->name = acym_translation('ACYM_SUBSCRIBE_FOLLOW_UP'); | |
| 29 | - ob_start(); | |
| 35 | + | |
| 30 | 36 | include acym_getPartial('actions', 'subscribe_followup'); |
| 31 | - $actions['subscribe_followup']->option = ob_get_clean(); | |
| 32 | - | |
| 33 | - $actions['unsubscribe_followup'] = new stdClass(); | |
| 34 | - $actions['unsubscribe_followup']->name = acym_translation('ACYM_UNSUBSCRIBE_FOLLOW_UP'); | |
| 35 | - ob_start(); | |
| 36 | - include acym_getPartial('actions', 'unsubscribe_followup'); | |
| 37 | - $actions['unsubscribe_followup']->option = ob_get_clean(); | |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | - public function onAcymDeclareActionsScenario(&$actions) | |
| 39 | + public function displayActionOptions_unsubscribe_followup(): void | |
| 41 | 40 | { |
| 42 | - $this->onAcymDeclareActions($actions); | |
| 41 | + $followupClass = new FollowupClass(); | |
| 42 | + $allListFollowups = $followupClass->getAll(); | |
| 43 | + | |
| 44 | + include acym_getPartial('actions', 'unsubscribe_followup'); | |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | public function onAcymProcessAction_acy_list(&$query, $action) |
| 46 | 48 | { |
| @@ -47,9 +49,9 @@ | ||
| 47 | 49 | if ($action['list_actions'] === 'sub') { |
| 48 | 50 | $queryToProcess = 'INSERT IGNORE #__acym_user_has_list (`user_id`, `list_id`, `status`, `subscription_date`) ('.$query->getQuery( |
| 49 | 51 | [ |
| 50 | 52 | 'user.id', |
| 51 | - $action['list_id'], | |
| 53 | + intval($action['list_id']), | |
| 52 | 54 | '1', |
| 53 | 55 | acym_escapeDB(acym_date(time(), 'Y-m-d H:i:s')), |
| 54 | 56 | ] |
| 55 | 57 | ).') ON DUPLICATE KEY UPDATE status = 1'; |
| @@ -55,9 +57,9 @@ | ||
| 55 | 57 | ).') ON DUPLICATE KEY UPDATE status = 1'; |
| 56 | 58 | } elseif ($action['list_actions'] === 'remove') { |
| 57 | 59 | $queryToProcess = 'DELETE FROM #__acym_user_has_list WHERE list_id = '.intval($action['list_id']).' AND user_id IN ('.$query->getQuery(['user.id']).')'; |
| 58 | 60 | } elseif ($action['list_actions'] === 'unsub') { |
| 59 | - $queryToProcess = 'UPDATE #__acym_user_has_list SET status = 0 WHERE list_id = '.intval($action['list_id']).' AND user_id IN ('.$query->getQuery(['user.id']).')'; | |
| 61 | + $queryToProcess = 'UPDATE #__acym_user_has_list SET status = 0, `unsubscribe_date` = '.acym_escapeDB(gmdate('Y-m-d H:i:s', time())).' WHERE list_id = '.intval($action['list_id']).' AND user_id IN ('.$query->getQuery(['user.id']).')'; | |
| 60 | 62 | } |
| 61 | 63 | |
| 62 | 64 | $nbAffected = acym_query($queryToProcess); |
| 63 | 65 | |
| @@ -82,9 +84,9 @@ | ||
| 82 | 84 | ).') ON DUPLICATE KEY UPDATE status = 1'; |
| 83 | 85 | |
| 84 | 86 | $nbAffected = acym_query($queryToProcess); |
| 85 | 87 | |
| 86 | - $followups = $followupClass->getFollowupsWithMailsInfoByIds($action['followup_id']); | |
| 88 | + $followups = $followupClass->getFollowupsWithMailsInfoByIds([$action['followup_id']]); | |
| 87 | 89 | foreach ($followups as $mails) { |
| 88 | 90 | foreach ($mails as $mail) { |
| 89 | 91 | $sendDate = time() + (intval($mail->delay) * intval($mail->delay_unit)); |
| 90 | 92 | $sendDate = acym_escapeDB(acym_date($sendDate, 'Y-m-d H:i:s', false)); |
| @@ -112,9 +114,9 @@ | ||
| 112 | 114 | if (empty($followup)) { |
| 113 | 115 | return ''; |
| 114 | 116 | } |
| 115 | 117 | |
| 116 | - $mailIds = $followupClass->getEmailsByIds($action['followup_id']); | |
| 118 | + $mailIds = $followupClass->getEmailsByIds([$action['followup_id']]); | |
| 117 | 119 | if (!empty($mailIds)) { |
| 118 | 120 | acym_query( |
| 119 | 121 | 'DELETE FROM #__acym_queue |
| 120 | 122 | WHERE user_id IN ('.$query->getQuery(['user.id']).') |
| @@ -121,9 +123,9 @@ | ||
| 121 | 123 | AND mail_id IN ('.implode(',', $mailIds).')' |
| 122 | 124 | ); |
| 123 | 125 | } |
| 124 | 126 | |
| 125 | - $unsubscribeDate = date('Y-m-d H:i:s', time() - date('Z')); | |
| 127 | + $unsubscribeDate = gmdate('Y-m-d H:i:s', time()); | |
| 126 | 128 | $nbAffected = acym_query( |
| 127 | 129 | 'UPDATE #__acym_user_has_list |
| 128 | 130 | SET `status` = 0, `unsubscribe_date` = '.acym_escapeDB($unsubscribeDate).' |
| 129 | 131 | WHERE list_id = '.intval($followup->list_id).' |
| @@ -136,9 +138,9 @@ | ||
| 136 | 138 | public function onAcymDeclareSummary_actions(&$automationAction) |
| 137 | 139 | { |
| 138 | 140 | if (!empty($automationAction['acy_list'])) { |
| 139 | 141 | $listClass = new ListClass(); |
| 140 | - $list = $listClass->getOneById($automationAction['acy_list']['list_id']); | |
| 142 | + $list = $listClass->getOneById($automationAction['acy_list']['list_id'] ? : 0); | |
| 141 | 143 | if ($automationAction['acy_list']['list_actions'] == 'sub') $automationAction['acy_list']['list_actions'] = 'ACYM_SUBSCRIBED_TO'; |
| 142 | 144 | if ($automationAction['acy_list']['list_actions'] == 'unsub') $automationAction['acy_list']['list_actions'] = 'ACYM_UNSUBSCRIBE_FROM'; |
| 143 | 145 | if ($automationAction['acy_list']['list_actions'] == 'remove') $automationAction['acy_list']['list_actions'] = 'ACYM_REMOVE_FROM'; |
| 144 | 146 | if (empty($list)) { |