Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-19353 - 'Dedupe by email' not working 2 #9059

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4299,7 +4299,8 @@ public static function apiQuery(
$count = FALSE,
$skipPermissions = TRUE,
$mode = 1,
$apiEntity = NULL
$apiEntity = NULL,
$groupBy = NULL
) {

$query = new CRM_Contact_BAO_Query(
Expand Down Expand Up @@ -4335,7 +4336,10 @@ public static function apiQuery(
$sql = "$select $from $where $having";

// add group by
if ($query->_useGroupBy) {
if (!empty($groupBy)) {
$sql .= self::getGroupByFromSelectColumns($query->_select, $groupBy);
}
elseif ($query->_useGroupBy) {
$sql .= self::getGroupByFromSelectColumns($query->_select, 'contact_a.id');
}
if (!empty($sort)) {
Expand Down
11 changes: 9 additions & 2 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public static function getRecipients(
$groupBy = $groupJoin = '';
if ($dedupeEmail) {
$groupJoin = " INNER JOIN civicrm_email e ON e.id = i.email_id";
$groupBy = " GROUP BY e.email, i.contact_id ";
$groupBy = " GROUP BY e.email";
}

$sql = "
Expand Down Expand Up @@ -924,11 +924,18 @@ public function getTestRecipients($testParams) {
$senderId = $session->get('userID');
list($aclJoin, $aclWhere) = CRM_ACL_BAO_ACL::buildAcl($senderId);

$m = new CRM_Mailing_DAO_Mailing();
$m->id = $testParams['mailing_id'];
$m->find(TRUE);

$dedupeEmailTest = $m->dedupe_email == 1 ? 'email' : '';

if (array_key_exists($testParams['test_group'], CRM_Core_PseudoConstant::group())) {
$contacts = civicrm_api('contact', 'get', array(
'version' => 3,
'group' => $testParams['test_group'],
'return' => 'id',
'return' => 'id, display_name, email',
'group_by' => $dedupeEmailTest,
'options' => array(
'limit' => 100000000000,
),
Expand Down
7 changes: 6 additions & 1 deletion ang/crmMailing/BlockPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@

scope.previewTestGroup = function(e) {
var $dialog = $(this);
var $groupStr = '';
if (scope.mailing.dedupe_email == 1) {
$groupStr = 'email';
}
$dialog.html('<div class="crm-loading-element"></div>').parent().find('button[data-op=yes]').prop('disabled', true);
$dialog.dialog('option', 'title', ts('Send to %1', {1: _.pluck(_.where(scope.crmMailingConst.groupNames, {id: scope.testGroup.gid}), 'title')[0]}));
CRM.api3('contact', 'get', {
group: scope.testGroup.gid,
options: {limit: 0},
return: 'display_name,email'
return: 'display_name,email',
group_by: $groupStr
}).done(function(data) {
var count = 0,
// Fixme: should this be in a template?
Expand Down
5 changes: 4 additions & 1 deletion api/v3/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ function _civicrm_api3_get_using_query_object($entity, $params, $additional_opti

$skipPermissions = !empty($params['check_permissions']) ? 0 : 1;

$groupBy = isset($params['group_by']) ? $params['group_by'] : '';

list($entities) = CRM_Contact_BAO_Query::apiQuery(
$newParams,
$returnProperties,
Expand All @@ -629,7 +631,8 @@ function _civicrm_api3_get_using_query_object($entity, $params, $additional_opti
$getCount,
$skipPermissions,
$mode,
$entity
$entity,
$groupBy
);

return $entities;
Expand Down