Skip to content

Commit

Permalink
[#2] fixed for test mail, merged 'dev_2'
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Mar 13, 2019
2 parents 92d2e30 + eaf39ee commit 505a13e
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions CRM/Mailingtools/AnonymousOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,20 @@ public static function getEventQueueID($mid, $default_contact_setting = NULL) {
2 => [$mid, 'Integer']]);

if (empty($event_queue_id)) {
// no real (is_test = 0) job found? Ok, let's take the test one...
$event_queue_id = CRM_Core_DAO::singleValueQuery("
SELECT MIN(queue.id)
FROM civicrm_mailing_event_queue queue
LEFT JOIN civicrm_mailing_job job ON queue.job_id = job.id
WHERE queue.contact_id = %1
AND job.mailing_id = %2", [
1 => [$preferred_contact_id, 'Integer'],
2 => [$mid, 'Integer']]);
// maybe no real (is_test = 0) job found...?
$mailing_is_live = self::isMailingLive($mid);
if (!$mailing_is_live) {
// ...ah, the mailing is not live yet!
// In that case it's ok to use the test job...
$event_queue_id = CRM_Core_DAO::singleValueQuery("
SELECT MIN(queue.id)
FROM civicrm_mailing_event_queue queue
LEFT JOIN civicrm_mailing_job job ON queue.job_id = job.id
WHERE queue.contact_id = %1
AND job.mailing_id = %2", [
1 => [$preferred_contact_id, 'Integer'],
2 => [$mid, 'Integer']]);
}
}

if (empty($event_queue_id)) {
Expand Down Expand Up @@ -195,6 +200,21 @@ public static function getQueueID2MailingID($queue_ids) {
return $queue_id_to_mailing_id;
}

/**
* Check if the given mailing is LIVE, i.e. has jobs with is_test=0
*
* @param $mid integer mailing ID
*
* @return bool is the mailing LIVE?
*/
public static function isMailingLive($mid) {
$mid = (int) $mid;
return (bool) CRM_Core_DAO::singleValueQuery("
SELECT COUNT(*)
FROM civicrm_mailing_job
WHERE mailing_id = {$mid}
AND is_test = 0;");
}

/**
* Create a new (fake) queue item for the given contact
Expand Down

0 comments on commit 505a13e

Please sign in to comment.