From 2c0e8e6bd25f917f222ca7a10b10b6784d4a04e8 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 16 Mar 2016 11:59:25 +1300 Subject: [PATCH] CRM-18246 Lybunt group clause not being included in temp table due to order of operations --- CRM/Report/Form/Contribute/Lybunt.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CRM/Report/Form/Contribute/Lybunt.php b/CRM/Report/Form/Contribute/Lybunt.php index b5703dcf01..3a3b2b92e9 100644 --- a/CRM/Report/Form/Contribute/Lybunt.php +++ b/CRM/Report/Form/Contribute/Lybunt.php @@ -414,7 +414,13 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { * @return string */ public function whereGroupClause($field, $value, $op) { - if (empty($this->contactTempTable)) { + if ($op == 'notin') { + // We do not have an optimisation for this scenario at this stage. Use + // parent. + return parent::whereGroupClause($field, $value, $op); + } + + if (empty($this->groupTempTable)) { $group = new CRM_Contact_DAO_Group(); $group->is_active = 1; $group->find(); @@ -656,10 +662,13 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { * @return string */ public function buildQuery($applyLimit = TRUE) { + + // Calling where & select before FROM allows us to build temp tables to use in from. + $this->where(); $this->select(); $this->from(); $this->customDataFrom(empty($this->contactTempTable)); - $this->where(); + $this->groupBy(); $this->orderBy(); $this->getPermissionedFTQuery($this); -- 2.25.1