dev/core#1217 Fix for failure to respect event_id (or any?) criteria in smart groups
authoreileen <emcnaughton@wikimedia.org>
Fri, 17 Jan 2020 03:52:11 +0000 (16:52 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 17 Jan 2020 03:52:43 +0000 (16:52 +1300)
From what I can tell it's possible to create smart groups from Advanced search & other contact searchs & Membership Search & Event search.

Membership search actually just leverages advanced search but Event Search smart group has it's own code & reloads into Event search.

This has been flawed for months but the current iteration is the criteria are not respected. On digging I found the decision was made in
contact search to store the parsed QueryParams (in [field_name, 'IN', [1,2]] format not the formValues. I think this was probably a mistake.

However, by adjusting the event code to do the same & ensuring the defaults are set it starts working again

CRM/Event/Form/Search.php
CRM/Event/Form/Task/SaveSearch.php

index 704d40b3f4f262b3f5fb76b5aa8a865b45f953b4..6c2c7534b428425ab75da77664bfc3a00c489926 100644 (file)
@@ -362,9 +362,9 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
     }
 
     $this->_done = TRUE;
-    $formValues = $this->getFormValues();
+    $this->setFormValues();
 
-    $this->submit($formValues);
+    $this->submit($this->_formValues);
   }
 
   /**
@@ -441,7 +441,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
    *   the default array reference
    */
   public function setDefaultValues() {
-    $this->_defaults = parent::setDefaultValues();
+    $this->_defaults = array_merge(parent::setDefaultValues(), (array) $this->_formValues);
     $event = CRM_Utils_Request::retrieve('event', 'Positive');
     if ($event) {
       $this->_defaults['event_id'] = $event;
index b462cc36a9ba23dd950db75be4b01bc51f9c222f..6f32217a7f1264c1e09842fc3ee26a828b015d8c 100644 (file)
@@ -99,12 +99,10 @@ class CRM_Event_Form_Task_SaveSearch extends CRM_Event_Form_Task {
     // saved search form values
     $formValues = $this->controller->exportValues();
 
-    $session = CRM_Core_Session::singleton();
-
     //save the search
     $savedSearch = new CRM_Contact_BAO_SavedSearch();
     $savedSearch->id = $this->_id;
-    $savedSearch->form_values = serialize($this->get('formValues'));
+    $savedSearch->form_values = serialize($this->get('queryParams'));
     $savedSearch->save();
     $this->set('ssID', $savedSearch->id);
     CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", [1 => $formValues['title']]), ts('Saved'), 'success');