CRM-18246 Lybunt group clause not being included in temp table due to order of operations
authoreileen <emcnaughton@wikimedia.org>
Tue, 15 Mar 2016 22:59:25 +0000 (11:59 +1300)
committereileen <emcnaughton@wikimedia.org>
Wed, 16 Mar 2016 00:52:33 +0000 (13:52 +1300)
CRM/Report/Form/Contribute/Lybunt.php

index b5703dcf01a1edcb2c70d79fd2b5d65f3ceab58a..3a3b2b92e927c75dd14e855afb976ee86b38140b 100644 (file)
@@ -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);