Cleanup following smart group conversions and fix the old name of the relationship...
authorSeamus Lee <seamuslee001@gmail.com>
Tue, 29 Oct 2019 01:33:00 +0000 (12:33 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Tue, 29 Oct 2019 02:50:41 +0000 (13:50 +1100)
CRM/Contact/BAO/SavedSearch.php
CRM/Contact/Form/Search/Criteria.php
CRM/Upgrade/Incremental/SmartGroups.php
tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php
tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php

index dd6e6b36bef1de6b1a0bc5054df517c779a6501b..67a61350bac3712dbfc9abe056201472cee2a54f 100644 (file)
@@ -391,6 +391,7 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_
    *
    * @param array $queryParams
    * @param array $formValues
+   * @deprecated
    */
   public static function saveRelativeDates(&$queryParams, $formValues) {
     // This is required only until all fields are converted to datepicker fields as the new format is truer to the
@@ -398,11 +399,7 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_
     $relativeDates = ['relative_dates' => []];
     $specialDateFields = [
       'event_relative',
-      'participant_relative',
       'log_date_relative',
-      'birth_date_relative',
-      'deceased_date_relative',
-      'relation_date_relative',
       'relation_action_date_relative',
     ];
     foreach ($formValues as $id => $value) {
index 154331dbe0a53fcf613db1095011a11a5cf239c6..298db709dbcb02b27d021db3508878671457c866 100644 (file)
@@ -540,9 +540,6 @@ class CRM_Contact_Form_Search_Criteria {
     }
     CRM_Core_Form_Date::buildDateRange($form, 'relation_active_period_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
 
-    // Add reltionship dates
-    CRM_Core_Form_Date::buildDateRange($form, 'relation_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
-
     // add all the custom  searchable fields
     CRM_Core_BAO_Query::addCustomFormFields($form, ['Relationship']);
   }
index a8d2ab7c49002a288e1ccbef79eacd3ab4310358..a5f61cf42be7b61b931eed0741315e608534137b 100644 (file)
@@ -71,8 +71,8 @@ class CRM_Upgrade_Incremental_SmartGroups {
       'case_start_date' => 'case_from',
       'case_end_date' => 'case_to',
       'mailing_job_start_date' => 'mailing_date',
-      'relationship_start_date' => 'relation_start_date',
-      'relationship_end_date' => 'relation_end_date',
+      'relationship_start_date' => 'relation_start',
+      'relationship_end_date' => 'relation_end',
     ];
 
     foreach ($fields as $field) {
index 01b45fc6f0fff87cbbc3e9f3ef2a8e43db740efc..74aa271e705c21194b87e679e71c17bc6a3adb96 100644 (file)
@@ -183,7 +183,6 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase {
     $formValues = [
       'operator' => 'AND',
       'event_relative' => 'this.month',
-      'participant_relative' => 'today',
       'participant_test' => 0,
       'title' => 'testsmart',
       'radio_ts' => 'ts_all',
@@ -197,7 +196,6 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase {
     $result = CRM_Contact_BAO_SavedSearch::getFormValues(CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'));
     $expectedResult = [
       'event' => 'this.month',
-      'participant' => 'today',
     ];
     $this->checkArrayEquals($result['relative_dates'], $expectedResult);
   }
index be60f5ff4c2364b3a2d9ccd69a2093e70bce18e8..0bbc8303baf214034ae5ad08c6bddf44a81268ea 100644 (file)
@@ -156,6 +156,35 @@ class CRM_Upgrade_Incremental_BaseTest extends CiviUnitTestCase {
     $this->assertEquals('this.week', $savedSearch['form_values'][8][2]);
   }
 
+  /**
+   * Test converting relationship fields
+   */
+  public function testSmartGroupRelationshipDateConversions() {
+    $this->callAPISuccess('SavedSearch', 'create', [
+      'form_values' => [
+        ['relationship_start_date_low', '=', '20191001000000'],
+        ['relationship_start_date_high', '=', '20191031235959'],
+        ['relationship_end_date_low', '=', '20191001000000'],
+        ['relationship_end_date_high', '=', '20191031235959'],
+        'relative_dates' => [
+          'relation_start' => 'this.month',
+          'relation_end' => 'this.month',
+        ],
+      ],
+    ]);
+    $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups();
+    $smartGroupConversionObject->updateGroups([
+      'datepickerConversion' => [
+        'relationship_start_date',
+        'relationship_end_date',
+      ],
+    ]);
+    $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []);
+    $this->assertEquals([], $savedSearch['form_values']['relative_dates']);
+    $this->assertEquals(['relationship_start_date_relative', '=', 'this.month'], $savedSearch['form_values'][4]);
+    $this->assertEquals(['relationship_end_date_relative', '=', 'this.month'], $savedSearch['form_values'][5]);
+  }
+
   /**
    * Test conversion of on hold group.
    */