Commit 63de7b4d authored by eileen's avatar eileen 🎱 Committed by GitHub

Merge pull request #10583 from seamuslee001/CRM-20789

CRM-20789 Fix unsubscribing when link comes from an AB Test
parents 7e7f3d08 b6f5751b
......@@ -149,6 +149,8 @@ WHERE email = %2
$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
......@@ -156,7 +158,26 @@ WHERE email = %2
WHERE $job.id = " . CRM_Utils_Type::escape($job_id, 'Integer'));
$do->fetch();
$mailing_id = $do->mailing_id;
$mailing_type = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailing_id, 'mailing_type', 'id');
$entity = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_MailingGroup', $mailing_id, 'entity_table', 'mailing_id');
// If $entity is null and $mailing_Type is either winner or experiment then we are deailing with an AB test
$abtest_types = array('experiment', 'winner');
if (empty($entity) && in_array($mailing_type, $abtest_types)) {
$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', $mailing_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";
......@@ -167,8 +188,7 @@ WHERE email = %2
$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') . "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment