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-19662 - Fix remaining full group by clause #9428

Merged
merged 1 commit into from
Dec 14, 2016
Merged
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
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public function mergeContactIdsByHousehold() {
$today = date('Ymd');
$relationActive = " AND (crel.is_active = 1 AND ( crel.end_date is NULL OR crel.end_date >= {$today} ) )";
$relationWhere = " WHERE contact_household.is_deleted = 0 AND crel.{$contactA} IN ( {$relID} ) {$relationActive}";
$relationGroupBy = " GROUP BY crel.{$contactA}";
$relationGroupBy = " GROUP BY crel.{$contactA}, contact_household.id";
$relationQueryString = "$relationSelect $relationFrom $relationWhere $relationGroupBy";

$householdsDAO = CRM_Core_DAO::executeQuery($relationQueryString);
Expand Down
3 changes: 1 addition & 2 deletions CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,7 @@ public static function getSubscriptionDetails($entityID, $entity = 'recur') {
FROM civicrm_contribution_recur rec
LEFT JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id )
LEFT JOIN civicrm_membership_payment mp ON ( mp.contribution_id = con.id )
WHERE rec.id = %1
GROUP BY rec.id";
WHERE rec.id = %1";
}
elseif ($entity == 'contribution') {
$sql .= "
Expand Down
4 changes: 2 additions & 2 deletions CRM/Event/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public function eventFee() {
FROM civicrm_price_field_value cv
LEFT JOIN civicrm_price_field cf ON cv.price_field_id = cf.id
LEFT JOIN civicrm_price_set_entity ce ON ce.price_set_id = cf.price_set_id
WHERE ce.entity_table = 'civicrm_event' AND {$whereClause}
GROUP BY cv.label";
WHERE ce.entity_table = 'civicrm_event' AND {$whereClause}";

$dao = CRM_Core_DAO::executeQuery($query);
$results = array();
while ($dao->fetch()) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ public static function exportComponents(
$today = date('Ymd');
$relationActive = " AND (crel.is_active = 1 AND ( crel.end_date is NULL OR crel.end_date >= {$today} ) )";
$relationWhere = " WHERE contact_a.is_deleted = 0 {$relationshipClause} {$relationActive}";
$relationGroupBy = " GROUP BY crel.{$contactA}";
$relationGroupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($relationQuery[$rel]->_select, "crel.{$contactA}");
$relationSelect = "{$relationSelect}, {$contactA} as refContact ";
$relationQueryString = "$relationSelect $relationFrom $relationWhere $relationHaving $relationGroupBy";

Expand Down
9 changes: 7 additions & 2 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,23 +538,28 @@ public static function getRecipients(
$params = array(1 => array($mailing_id, 'Integer'));
CRM_Core_DAO::executeQuery($sql, $params);

$selectClause = array('%1', 'i.contact_id', "i.{$tempColumn}");
$select = "SELECT " . implode(', ', $selectClause);
// CRM-3975
$groupBy = $groupJoin = '';
$orderBy = "i.contact_id, i.{$tempColumn}";
if ($dedupeEmail) {
$orderBy = "MIN(i.contact_id), MIN(i.{$tempColumn})";
$groupJoin = " INNER JOIN civicrm_email e ON e.id = i.email_id";
$groupBy = " GROUP BY e.email ";
$select = CRM_Contact_BAO_Query::appendAnyValueToSelect($selectClause, 'e.email');
}

$sql = "
INSERT INTO civicrm_mailing_recipients ( mailing_id, contact_id, {$tempColumn} )
SELECT %1, i.contact_id, i.{$tempColumn}
{$select}
FROM civicrm_contact contact_a
INNER JOIN I_$job_id i ON contact_a.id = i.contact_id
$groupJoin
{$aclFrom}
{$aclWhere}
$groupBy
ORDER BY i.contact_id, i.{$tempColumn}
ORDER BY {$orderBy}
";

CRM_Core_DAO::executeQuery($sql, $params);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Event/BAO/Bounce.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static function &getRows(
}

if ($is_distinct) {
$query .= " GROUP BY $queue.id ";
$query .= " GROUP BY $queue.id, $bounce.time_stamp, $bounce.bounce_reason, $bounceType.name ";
}

$orderBy = "sort_name ASC, {$bounce}.time_stamp DESC";
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Event/BAO/Delivered.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static function &getRows(
}

if ($is_distinct) {
$query .= " GROUP BY $queue.id ";
$query .= " GROUP BY $queue.id, $delivered.id";
}

$orderBy = "sort_name ASC, {$delivered}.time_stamp DESC";
Expand Down
4 changes: 2 additions & 2 deletions CRM/Mailing/Event/BAO/Forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ public static function &getRows(
}

if ($is_distinct) {
$query .= " GROUP BY $queue.id ";
$query .= " GROUP BY $queue.id, dest_contact.id, dest_email.email, $forward.time_stamp ";
}

$orderBy = "sort_name ASC, {$forward}.time_stamp DESC";
$orderBy = "$contact.sort_name ASC, {$forward}.time_stamp DESC";
if ($sort) {
if (is_string($sort)) {
$sort = CRM_Utils_Type::escape($sort, 'String');
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Event/BAO/Opened.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public static function &getRows(
}

if ($is_distinct) {
$query .= " GROUP BY $queue.id ";
$query .= " GROUP BY $queue.id, $open.time_stamp ";
}

$orderBy = "sort_name ASC, {$open}.time_stamp DESC";
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Event/BAO/Reply.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public static function &getRows(
}

if ($is_distinct) {
$query .= " GROUP BY $queue.id ";
$query .= " GROUP BY $queue.id, $contact.id, $reply.time_stamp ";
}

$orderBy = "sort_name ASC, {$reply}.time_stamp DESC";
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Event/BAO/TrackableURLOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public static function &getRows(
}

if ($is_distinct) {
$query .= " GROUP BY $queue.id ";
$query .= " GROUP BY $queue.id, $click.time_stamp, $url.url ";
}

$orderBy = "sort_name ASC, {$click}.time_stamp DESC";
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Event/BAO/Unsubscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public static function &getRows(
}

if ($is_distinct) {
$query .= " GROUP BY $queue.id ";
$query .= " GROUP BY $queue.id, $unsub.time_stamp, $unsub.org_unsubscribe";
}

$orderBy = "sort_name ASC, {$unsub}.time_stamp DESC";
Expand Down