Skip to content

Commit

Permalink
CRM-20789 Fix unsubscribing when link comes from an AB Test
Browse files Browse the repository at this point in the history
CRM-20789 Fix retrieving entity when in AB test context
  • Loading branch information
seamuslee001 committed Jun 29, 2017
1 parent fabb91b commit abf4cee
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions CRM/Mailing/Event/BAO/Unsubscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public static function &unsub_from_mailing($job_id, $queue_id, $hash, $return =
$group = $groupObject->getTableName();
$gcObject = new CRM_Contact_BAO_GroupContact();
$gc = $gcObject->getTableName();
$abObject = new CRM_Mailing_DAO_MailingAB();
$ab = $abObject->getTableName();

//We Need the mailing Id for the hook...
$do->query("SELECT $job.mailing_id as mailing_id
Expand All @@ -157,6 +159,23 @@ public static function &unsub_from_mailing($job_id, $queue_id, $hash, $return =
$do->fetch();
$mailing_id = $do->mailing_id;
$entity = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_MailingGroup', $mailing_id, 'entity_table', 'mailing_id');

// If $entity is null then most likely we are dealing with an AB test
if (empty($entity)) {
$mailing_id_a = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_MailingAB', $mailing_id, 'mailing_id_a', 'mailing_id_b');
$field = 'mailing_id_b';
if (empty($mailing_id_a)) {
$mailing_id_a = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_MailingAB', $mailing_id, 'mailing_id_a', 'mailing_id_c');
$field = 'mailing_id_c';
}
$jobJoin = "INNER JOIN $ab ON $ab.mailing_id_a = $mg.mailing_id
INNER JOIN $job ON $job.mailing_id = $ab.$field";
$entity = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_MailingGroup', $maiing_id_a, 'entity_table', 'mailing_id');
}
else {
$jobJoin = "INNER JOIN $job ON $job.mailing_id = $mg.mailing_id";
}

$groupClause = '';
if ($entity == $group) {
$groupClause = "AND $group.is_hidden = 0";
Expand All @@ -167,8 +186,7 @@ public static function &unsub_from_mailing($job_id, $queue_id, $hash, $return =
$mg.entity_id as entity_id,
$mg.group_type as group_type
FROM $mg
INNER JOIN $job
ON $job.mailing_id = $mg.mailing_id
$jobJoin
INNER JOIN $entity
ON $mg.entity_id = $entity.id
WHERE $job.id = " . CRM_Utils_Type::escape($job_id, 'Integer') . "
Expand Down

0 comments on commit abf4cee

Please sign in to comment.