| @@ -12,10 +12,13 @@ | ||
| 12 | 12 | trait Actions |
| 13 | 13 | { |
| 14 | 14 | public function duplicate(): void |
| 15 | 15 | { |
| 16 | - $campaignsSelected = acym_getVar('int', 'elements_checked'); | |
| 16 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 17 | 17 | |
| 18 | + //We get the id of campaign checked | |
| 19 | + $campaignsSelected = acym_getVar('array', 'elements_checked', []); | |
| 20 | + | |
| 18 | 21 | $campaignClass = new CampaignClass(); |
| 19 | 22 | $mailClass = new MailClass(); |
| 20 | 23 | $campaignId = 0; |
| 21 | 24 | |
| @@ -23,10 +26,12 @@ | ||
| 23 | 26 | $campaignClass->onlyManageableCampaigns($campaignsSelected); |
| 24 | 27 | } |
| 25 | 28 | |
| 26 | 29 | foreach ($campaignsSelected as $campaignSelected) { |
| 30 | + //we get the campaign | |
| 27 | 31 | $campaign = $campaignClass->getOneById($campaignSelected); |
| 28 | 32 | |
| 33 | + //remove id and set to draft and not sent | |
| 29 | 34 | unset($campaign->id); |
| 30 | 35 | unset($campaign->sending_date); |
| 31 | 36 | $campaign->draft = 1; |
| 32 | 37 | $campaign->sent = 0; |
| @@ -34,8 +39,9 @@ | ||
| 34 | 39 | if (!empty($campaign->sending_params['resendTarget'])) { |
| 35 | 40 | unset($campaign->sending_params['resendTarget']); |
| 36 | 41 | } |
| 37 | 42 | |
| 43 | + //We get the mail to duplicate it | |
| 38 | 44 | $mail = $mailClass->getOneById($campaign->mail_id); |
| 39 | 45 | $oldMailId = $mail->id; |
| 40 | 46 | unset($mail->id); |
| 41 | 47 | $mail->creation_date = acym_date('now', 'Y-m-d H:i:s', false); |
| @@ -43,8 +49,11 @@ | ||
| 43 | 49 | $mail->creator_id = acym_currentUserId(); |
| 44 | 50 | $idNewMail = $mailClass->save($mail); |
| 45 | 51 | |
| 46 | 52 | if (isset($campaign->sending_params['abtest']) && !empty($campaign->sending_params['abtest']['B'])) { |
| 53 | + unset($campaign->sending_params['abtest']['abtest_finished']); | |
| 54 | + unset($campaign->sending_params['abtest']['final']); | |
| 55 | + | |
| 47 | 56 | $mailVersion = $mailClass->getOneById($campaign->sending_params['abtest']['B']); |
| 48 | 57 | if (!empty($mailVersion)) { |
| 49 | 58 | unset($mailVersion->id); |
| 50 | 59 | $mailVersion->creation_date = acym_date('now', 'Y-m-d H:i:s', false); |
| @@ -63,11 +72,13 @@ | ||
| 63 | 72 | $mailClass->save($oneTranslation); |
| 64 | 73 | } |
| 65 | 74 | } |
| 66 | 75 | |
| 76 | + //we set the new mail id and save campaign | |
| 67 | 77 | $campaign->mail_id = $idNewMail; |
| 68 | 78 | $campaignId = $campaignClass->save($campaign); |
| 69 | 79 | |
| 80 | + //We get the lists | |
| 70 | 81 | $allLists = $campaignClass->getListsByMailId($oldMailId); |
| 71 | 82 | |
| 72 | 83 | $campaignClass->manageListsToCampaign($allLists, $idNewMail); |
| 73 | 84 | } |
| @@ -73,9 +84,9 @@ | ||
| 73 | 84 | } |
| 74 | 85 | |
| 75 | 86 | acym_enqueueMessage(acym_translation('ACYM_CAMPAIGN_DUPLICATED_SUCCESS')); |
| 76 | 87 | |
| 77 | - if (count($campaignsSelected) == 1 && acym_getVar('string', 'step', '') == 'summary') { | |
| 88 | + if (count($campaignsSelected) == 1 && acym_getVar('string', 'step', '') === 'summary') { | |
| 78 | 89 | acym_setVar('campaignId', $campaignId); |
| 79 | 90 | $this->editEmail(); |
| 80 | 91 | } else { |
| 81 | 92 | $this->listing(); |
| @@ -83,15 +94,19 @@ | ||
| 83 | 94 | } |
| 84 | 95 | |
| 85 | 96 | public function duplicateFollowup(): void |
| 86 | 97 | { |
| 87 | - $followupsSelected = acym_getVar('int', 'elements_checked'); | |
| 98 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 88 | 99 | |
| 100 | + //We get the id of follow-ups checked | |
| 101 | + $followupsSelected = acym_getVar('array', 'elements_checked', []); | |
| 102 | + | |
| 89 | 103 | $followupClass = new FollowupClass(); |
| 90 | 104 | $mailClass = new MailClass(); |
| 91 | 105 | |
| 92 | - foreach ($followupsSelected as $oneFollowup) { | |
| 93 | - $followUp = $followupClass->getOneByIdWithMails($oneFollowup); | |
| 106 | + foreach ($followupsSelected as $oneFollowupId) { | |
| 107 | + // Duplicate the follow-up + list associated | |
| 108 | + $followUp = $followupClass->getOneByIdWithMails($oneFollowupId); | |
| 94 | 109 | $followupEmails = $followUp->mails; |
| 95 | 110 | |
| 96 | 111 | unset($followUp->id, $followUp->creation_date, $followUp->list_id, $followUp->mails); |
| 97 | 112 | $followUp->name .= '_copy'; |
| @@ -105,8 +120,9 @@ | ||
| 105 | 120 | return; |
| 106 | 121 | } |
| 107 | 122 | $followUp->id = $newFollowUpId; |
| 108 | 123 | |
| 124 | + // Duplicate emails of the follow-up and attach them to the new followup | |
| 109 | 125 | foreach ($followupEmails as $oneEmail) { |
| 110 | 126 | $mail = $mailClass->getOneById($oneEmail->id); |
| 111 | 127 | unset($mail->id, $mail->creation_date, $mail->creator_id, $mail->autosave); |
| 112 | 128 | $newMailId = $mailClass->save($mail); |
| @@ -134,9 +150,13 @@ | ||
| 134 | 150 | |
| 135 | 151 | return; |
| 136 | 152 | } |
| 137 | 153 | |
| 138 | - acym_redirect(acym_completeLink('queue', false, true).'&task=playPauseSending&acym__queue__play_pause__active__new_value=1&acym__queue__play_pause__campaign_id='.$id); | |
| 154 | + acym_redirect( | |
| 155 | + acym_completeLink('queue', false, true) | |
| 156 | + .'&task=playPauseSending&acym__queue__play_pause__active__new_value=1&acym__queue__play_pause__campaign_id='.$id | |
| 157 | + .'&'.acym_getFormToken() | |
| 158 | + ); | |
| 139 | 159 | } |
| 140 | 160 | |
| 141 | 161 | public function stopSending(): void |
| 142 | 162 | { |
| @@ -149,9 +169,9 @@ | ||
| 149 | 169 | } |
| 150 | 170 | |
| 151 | 171 | private function stopAction(string $action): void |
| 152 | 172 | { |
| 153 | - acym_checkToken(); | |
| 173 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 154 | 174 | |
| 155 | 175 | $campaignID = acym_getVar('int', $action); |
| 156 | 176 | $campaignClass = new CampaignClass(); |
| 157 | 177 | |
| @@ -179,8 +199,10 @@ | ||
| 179 | 199 | } |
| 180 | 200 | |
| 181 | 201 | public function confirmCampaign(): void |
| 182 | 202 | { |
| 203 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 204 | + | |
| 183 | 205 | $this->updateOpenAcymailerPopup(); |
| 184 | 206 | $campaignId = acym_getVar('int', 'campaignId'); |
| 185 | 207 | $campaignSendingDate = acym_getVar('string', 'sending_date'); |
| 186 | 208 | $resendTarget = acym_getVar('cmd', 'resend_target', ''); |
| @@ -204,9 +226,9 @@ | ||
| 204 | 226 | } |
| 205 | 227 | |
| 206 | 228 | $resultSave = $campaignClass->save($campaign); |
| 207 | 229 | |
| 208 | - if ($resultSave) { | |
| 230 | + if (!empty($resultSave)) { | |
| 209 | 231 | acym_enqueueMessage(acym_translationSprintf('ACYM_CONFIRMED_CAMPAIGN', acym_date($campaignSendingDate, 'j F Y H:i'))); |
| 210 | 232 | } else { |
| 211 | 233 | acym_enqueueMessage(acym_translation('ACYM_CANT_CONFIRM_CAMPAIGN').' : '.end($campaignClass->errors), 'error'); |
| 212 | 234 | } |
| @@ -215,8 +237,10 @@ | ||
| 215 | 237 | } |
| 216 | 238 | |
| 217 | 239 | public function activeAutoCampaign(): void |
| 218 | 240 | { |
| 241 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 242 | + | |
| 219 | 243 | $this->updateOpenAcymailerPopup(); |
| 220 | 244 | $campaignId = acym_getVar('int', 'campaignId'); |
| 221 | 245 | $campaignClass = new CampaignClass(); |
| 222 | 246 | |
| @@ -227,9 +251,9 @@ | ||
| 227 | 251 | $campaign->sent = 0; |
| 228 | 252 | |
| 229 | 253 | $resultSave = $campaignClass->save($campaign); |
| 230 | 254 | |
| 231 | - if ($resultSave) { | |
| 255 | + if (!empty($resultSave)) { | |
| 232 | 256 | acym_enqueueMessage(acym_translation('ACYM_CAMPAIGN_IS_ACTIVE')); |
| 233 | 257 | } else { |
| 234 | 258 | acym_enqueueMessage(acym_translation('ACYM_ERROR_SAVING'), 'error'); |
| 235 | 259 | } |
| @@ -238,8 +262,10 @@ | ||
| 238 | 262 | } |
| 239 | 263 | |
| 240 | 264 | public function saveAsDraftCampaign(): void |
| 241 | 265 | { |
| 266 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 267 | + | |
| 242 | 268 | $campaignId = acym_getVar('int', 'campaignId'); |
| 243 | 269 | $campaignClass = new CampaignClass(); |
| 244 | 270 | |
| 245 | 271 | if (!$campaignClass->hasUserAccess($campaignId)) { |
| @@ -252,9 +278,9 @@ | ||
| 252 | 278 | $campaign->active = 0; |
| 253 | 279 | |
| 254 | 280 | $resultSave = $campaignClass->save($campaign); |
| 255 | 281 | |
| 256 | - if ($resultSave) { | |
| 282 | + if (!empty($resultSave)) { | |
| 257 | 283 | acym_enqueueMessage(acym_translation('ACYM_CAMPAIGN_SUCCESSFULLY_SAVE_AS_DRAFT')); |
| 258 | 284 | } else { |
| 259 | 285 | acym_enqueueMessage(acym_translation('ACYM_CAMPAIGN_CANT_BE_SAVED').' : '.end($campaignClass->errors), 'error'); |
| 260 | 286 | } |
| @@ -263,8 +289,9 @@ | ||
| 263 | 289 | } |
| 264 | 290 | |
| 265 | 291 | public function toggleActivateColumnCampaign(): void |
| 266 | 292 | { |
| 293 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 267 | 294 | |
| 268 | 295 | $campaignId = acym_getVar('int', 'campaignId'); |
| 269 | 296 | $campaignClass = new CampaignClass(); |
| 270 | 297 | |
| @@ -277,8 +304,9 @@ | ||
| 277 | 304 | } |
| 278 | 305 | |
| 279 | 306 | $campaign->active = empty($campaign->active) ? 1 : 0; |
| 280 | 307 | |
| 308 | + // Remove the next trigger when disabling the automatic campaign. It will be calculated again properly if reactivated | |
| 281 | 309 | if ($campaign->active === 0 && $campaign->sending_type === CampaignClass::SENDING_TYPE_AUTO) { |
| 282 | 310 | $campaign->next_trigger = null; |
| 283 | 311 | } |
| 284 | 312 | |
| @@ -283,9 +311,9 @@ | ||
| 283 | 311 | } |
| 284 | 312 | |
| 285 | 313 | $resultSave = $campaignClass->save($campaign); |
| 286 | 314 | |
| 287 | - if ($resultSave) { | |
| 315 | + if (!empty($resultSave)) { | |
| 288 | 316 | acym_enqueueMessage(acym_translation('ACYM_CAMPAIGN_SUCCESSFULLY_SAVE_AS_DRAFT')); |
| 289 | 317 | } else { |
| 290 | 318 | acym_enqueueMessage(acym_translation('ACYM_CAMPAIGN_CANT_BE_SAVED').' : '.end($campaignClass->errors), 'error'); |
| 291 | 319 | } |
| @@ -294,9 +322,9 @@ | ||
| 294 | 322 | } |
| 295 | 323 | |
| 296 | 324 | public function addQueue(): void |
| 297 | 325 | { |
| 298 | - acym_checkToken(); | |
| 326 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 299 | 327 | $this->updateOpenAcymailerPopup(); |
| 300 | 328 | |
| 301 | 329 | $campaignClass = new CampaignClass(); |
| 302 | 330 | $campaignID = acym_getVar('int', 'campaignId', 0); |
| @@ -319,9 +347,9 @@ | ||
| 319 | 347 | |
| 320 | 348 | $status = $campaignClass->send($campaignID); |
| 321 | 349 | |
| 322 | 350 | if ($status) { |
| 323 | - acym_enqueueMessage(acym_translationSprintf('ACYM_CAMPAIGN_ADDED_TO_QUEUE', $campaign->name), 'info'); | |
| 351 | + acym_enqueueMessage(acym_translationSprintf('ACYM_CAMPAIGN_ADDED_TO_QUEUE', $campaign->name, 'info')); | |
| 324 | 352 | } else { |
| 325 | 353 | if (empty($campaignClass->errors)) { |
| 326 | 354 | $notification = [ |
| 327 | 355 | 'name' => 'queue_campaign_error', |
| @@ -333,12 +361,12 @@ | ||
| 333 | 361 | } |
| 334 | 362 | } |
| 335 | 363 | } |
| 336 | 364 | |
| 337 | - $this->_redirectAfterQueued(); | |
| 365 | + $this->redirectAfterQueued(); | |
| 338 | 366 | } |
| 339 | 367 | |
| 340 | - private function _redirectAfterQueued(): void | |
| 368 | + private function redirectAfterQueued(): void | |
| 341 | 369 | { |
| 342 | 370 | if (acym_isAdmin() && (!acym_level(ACYM_ESSENTIAL) || $this->config->get('cron_last', 0) < (time() - 43200))) { |
| 343 | 371 | acym_redirect(acym_completeLink('queue&task=campaigns', false, true)); |
| 344 | 372 | } else { |
| @@ -348,14 +376,16 @@ | ||
| 348 | 376 | |
| 349 | 377 | private function updateOpenAcymailerPopup(): void |
| 350 | 378 | { |
| 351 | 379 | if (acym_isAdmin() && $this->config->get('mailer_method') === 'acymailer' && intval($this->config->get('acymailer_popup', 0)) === 0) { |
| 352 | - $this->config->save(['acymailer_popup' => '1']); | |
| 380 | + $this->config->saveConfig(['acymailer_popup' => '1']); | |
| 353 | 381 | } |
| 354 | 382 | } |
| 355 | 383 | |
| 356 | 384 | public function updateArchive(): void |
| 357 | 385 | { |
| 386 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 387 | + | |
| 358 | 388 | $campaignId = acym_getVar('int', 'campaignId', 0); |
| 359 | 389 | if (empty($campaignId)) { |
| 360 | 390 | acym_sendAjaxResponse('', [], false); |
| 361 | 391 | } |
| @@ -368,9 +398,9 @@ | ||
| 368 | 398 | |
| 369 | 399 | $mailArchiveClass = new MailArchiveClass(); |
| 370 | 400 | $archive = $mailArchiveClass->getOneByMailId($campaign->mail_id); |
| 371 | 401 | if (!empty($archive)) { |
| 372 | - $mailArchiveClass->delete($archive->id); | |
| 402 | + $mailArchiveClass->delete([$archive->id]); | |
| 373 | 403 | } |
| 374 | 404 | |
| 375 | 405 | acym_sendAjaxResponse(); |
| 376 | 406 | } |