| @@ -1,0 +1,80 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace AcyMailing\Controllers; | |
| 4 | + | |
| 5 | +use AcyMailing\Classes\QueueClass; | |
| 6 | +use AcyMailing\Helpers\QueueHelper; | |
| 7 | +use AcyMailing\Core\AcymController; | |
| 8 | +use AcyMailing\Controllers\Queue\Campaigns; | |
| 9 | +use AcyMailing\Controllers\Queue\Scheduled; | |
| 10 | +use AcyMailing\Controllers\Queue\Detailed; | |
| 11 | + | |
| 12 | +class QueueController extends AcymController | |
| 13 | +{ | |
| 14 | + use Campaigns; | |
| 15 | + use Scheduled; | |
| 16 | + use Detailed; | |
| 17 | + | |
| 18 | + public function __construct() | |
| 19 | + { | |
| 20 | + parent::__construct(); | |
| 21 | + | |
| 22 | + $this->breadcrumb[acym_translation('ACYM_QUEUE')] = acym_completeLink('queue'); | |
| 23 | + $this->setDefaultTask('campaigns'); | |
| 24 | + } | |
| 25 | + | |
| 26 | + public function scheduleReady(): void | |
| 27 | + { | |
| 28 | + $queueClass = new QueueClass(); | |
| 29 | + $queueClass->scheduleReady(); | |
| 30 | + } | |
| 31 | + | |
| 32 | + public function continuesend(): void | |
| 33 | + { | |
| 34 | + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token'); | |
| 35 | + | |
| 36 | + //Are we configured to use the automatic send process only? | |
| 37 | + //If so, we don't allow the user to access this feature! | |
| 38 | + if ($this->config->get('queue_type') === 'onlyauto') { | |
| 39 | + acym_setNoTemplate(); | |
| 40 | + acym_display(acym_translation('ACYM_ONLYAUTOPROCESS'), 'warning'); | |
| 41 | + | |
| 42 | + exit; | |
| 43 | + } | |
| 44 | + | |
| 45 | + //we move the next cron task so that we won't have problem with double send process | |
| 46 | + $newCronTime = time() + 120; | |
| 47 | + if ($this->config->get('cron_next') < $newCronTime) { | |
| 48 | + $this->config->saveConfig(['cron_next' => $newCronTime]); | |
| 49 | + } | |
| 50 | + | |
| 51 | + $mailid = acym_getCID('id'); | |
| 52 | + | |
| 53 | + $totalSend = acym_getVar('int', 'totalsend', 0); | |
| 54 | + if (empty($totalSend)) { | |
| 55 | + $query = 'SELECT COUNT(queue.user_id) FROM #__acym_queue AS queue LEFT JOIN #__acym_campaign AS campaign ON queue.mail_id = campaign.mail_id WHERE (campaign.id IS NULL OR campaign.active = 1) AND queue.sending_date < '.acym_escapeDB( | |
| 56 | + acym_date('now', 'Y-m-d H:i:s', false) | |
| 57 | + ); | |
| 58 | + if (!empty($mailid)) { | |
| 59 | + $query .= ' AND queue.mail_id = '.intval($mailid); | |
| 60 | + } | |
| 61 | + $totalSend = acym_loadResult($query); | |
| 62 | + } | |
| 63 | + | |
| 64 | + $alreadySent = acym_getVar('int', 'alreadysent', 0); | |
| 65 | + | |
| 66 | + $queueHelper = new QueueHelper(); | |
| 67 | + $queueHelper->id = $mailid; | |
| 68 | + $queueHelper->report = true; | |
| 69 | + $queueHelper->total = (int)$totalSend; | |
| 70 | + $queueHelper->start = $alreadySent; | |
| 71 | + $queueHelper->pause = (int)$this->config->get('queue_pause', 0); | |
| 72 | + // ->Process will exit the current page if it needs to be continued | |
| 73 | + $queueHelper->fromManual = true; | |
| 74 | + $queueHelper->process(); | |
| 75 | + | |
| 76 | + //We should never be there... but if the user tries to resume the send process and the messages are not ready to be sent then it will land here... | |
| 77 | + acym_setNoTemplate(); | |
| 78 | + exit; | |
| 79 | + } | |
| 80 | +} | |