3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
11 namespace Civi\FlexMailer\Listener
;
13 use Civi\FlexMailer\Event\WalkBatchesEvent
;
14 use Civi\FlexMailer\FlexMailerTask
;
16 class DefaultBatcher
extends BaseListener
{
19 * Given a MailingJob (`$e->getJob()`), enumerate the recipients as
20 * a batch of FlexMailerTasks and visit each batch (`$e->visit($tasks)`).
22 * @param \Civi\FlexMailer\Event\WalkBatchesEvent $e
24 public function onWalk(WalkBatchesEvent
$e) {
25 if (!$this->isActive()) {
29 $e->stopPropagation();
34 // This handles the edge case scenario where all the mails
35 // have been delivered in prior jobs.
38 // make sure that there's no more than $mailerBatchLimit mails processed in a run
39 $mailerBatchLimit = \CRM_Core_Config
::singleton()->mailerBatchLimit
;
41 $eq = \CRM_Mailing_BAO_MailingJob
::findPendingTasks($job->id
, 'email');
43 while ($eq->fetch()) {
44 if ($mailerBatchLimit > 0 && \CRM_Mailing_BAO_MailingJob
::$mailsProcessed >= $mailerBatchLimit) {
49 $e->setCompleted(FALSE);
52 \CRM_Mailing_BAO_MailingJob
::$mailsProcessed++
;
54 // FIXME: To support SMS, the address should be $eq->phone instead of $eq->email
55 $tasks[] = new FlexMailerTask($eq->id
, $eq->contact_id
, $eq->hash
,
57 if (count($tasks) == \CRM_Mailing_BAO_MailingJob
::MAX_CONTACTS_TO_PROCESS
) {
58 $isDelivered = $e->visit($tasks);
61 $e->setCompleted($isDelivered);
71 $isDelivered = $e->visit($tasks);
73 $e->setCompleted($isDelivered);