From e34642c964513be1999ff0e1c9f3b7faad02b2fd Mon Sep 17 00:00:00 2001 From: monishdeb Date: Mon, 28 Sep 2015 18:19:49 +0530 Subject: [PATCH] legacy support for group and tag --- CRM/Contact/BAO/Query.php | 22 +++++++++++++++++++ .../CRM/Contact/BAO/QueryTestDataProvider.php | 20 ++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index c24fe198e0..ed780c0970 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1485,6 +1485,9 @@ class CRM_Contact_BAO_Query { } foreach ($formValues as $id => $values) { + + self::legacyConvertFormValues($id, $values); + if (self::isAlreadyProcessedForQueryFormat($values)) { $params[] = $values; continue; @@ -1562,6 +1565,25 @@ class CRM_Contact_BAO_Query { return $params; } + /** + * Function to support legacy format for groups and tags. + * + * @param string $id + * @param array|int $values + * + */ + public static function legacyConvertFormValues($id, &$values) { + if (in_array($id, array('group', 'tag')) && is_array($values)) { + // prior to 4.7, formValues for some attributes (e.g. group, tag) are stored in array(id1 => 1, id2 => 1), + // as per the recent Search fixes $values need to be in standard array(id1, id2) format + $ids = array_keys($values, 1); + if (count($ids) > 1 || (count($ids) == 1 && key($values) > 1)) { + $values = $ids; + } + } + } + + /** * Fix values from query from/to something no-one cared enough to document. * diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php b/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php index ca44aaa6c9..1d6104dd96 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php @@ -95,6 +95,24 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { '24', ), ), + // Include static groups 3 and 5 in legacy format + array( + 'fv' => array('group' => array('3' => 1, '5' => 1)), + 'id' => array( + '13', + '14', + '15', + '16', + '17', + '18', + '19', + '20', + '21', + '22', + '23', + '24', + ), + ), // Include tag 7 array( 'fv' => array('tag' => '7'), @@ -111,7 +129,7 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator { ), // Include tag 9 array( - 'fv' => array('tag' => '9'), + 'fv' => array('tag' => array('9' => 1)), 'id' => array( '10', '12', -- 2.25.1