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

Cleanup following smart group conversions and fix the old name of the… #15648

Merged
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
5 changes: 1 addition & 4 deletions CRM/Contact/BAO/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,15 @@ protected function assignTestValue($fieldName, &$fieldDef, $counter) {
*
* @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
// form format and simply saves (e.g) custom_3_relative => "this.year"
$relativeDates = ['relative_dates' => []];
$specialDateFields = [
'event_relative',
'participant_relative',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this list (now of only 3 fields) is the list of legacy fields

'log_date_relative',
'birth_date_relative',
'deceased_date_relative',
'relation_date_relative',
'relation_action_date_relative',
];
foreach ($formValues as $id => $value) {
Expand Down
3 changes: 0 additions & 3 deletions CRM/Contact/Form/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,6 @@ public static function relationship(&$form) {
}
CRM_Core_Form_Date::buildDateRange($form, 'relation_active_period_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);

// Add reltionship dates
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't see this field exposed at all on the form so lets bin it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton looks like this is when the relation_date field was stripped off the form ad68213#diff-0ac8fd8c66c6d1e69b6dafa540ecddbf

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']);
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Upgrade/Incremental/SmartGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function datePickerConversion($fields) {
'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) {
Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public function testRelativeDateValues() {
$formValues = [
'operator' => 'AND',
'event_relative' => 'this.month',
'participant_relative' => 'today',
'participant_test' => 0,
'title' => 'testsmart',
'radio_ts' => 'ts_all',
Expand All @@ -197,7 +196,6 @@ public function testRelativeDateValues() {
$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);
}
Expand Down
29 changes: 29 additions & 0 deletions tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,35 @@ public function testSmartGroupMultipleRelatvieDateConversions() {
$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.
*/
Expand Down