Skip to content

Commit

Permalink
Merge pull request #12910 from monishdeb/dev-core-394
Browse files Browse the repository at this point in the history
(dev/core#394) : Wildcards are ignored in some smart group criteria, when the smart group is directly generated for a mailing
  • Loading branch information
eileenmcnaughton authored Oct 10, 2018
2 parents 36e4d1a + 4f3d62b commit 25a057d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ public static function createHiddenSmartGroup($params) {
//create/update saved search record.
$savedSearch = new CRM_Contact_BAO_SavedSearch();
$savedSearch->id = $ssId;
$savedSearch->form_values = serialize($params['form_values']);
$savedSearch->form_values = serialize(CRM_Contact_BAO_Query::convertFormValues($params['form_values']));
$savedSearch->mapping_id = $mappingId;
$savedSearch->search_custom_id = CRM_Utils_Array::value('search_custom_id', $params);
$savedSearch->save();
Expand Down
4 changes: 3 additions & 1 deletion CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ public static function getRecipients($mailingID) {
->param('#groupIDs', $groupIDs)
->execute();
while ($groupDAO->fetch()) {
if ($groupDAO->cache_date == NULL) {
// hidden smart groups always have a cache date and there is no other way
// we can rebuilt the contact list from UI so consider such smart group
if ($groupDAO->cache_date == NULL || $groupDAO->is_hidden) {
CRM_Contact_BAO_GroupContactCache::load($groupDAO);
}
if ($groupType == 'Include') {
Expand Down
37 changes: 37 additions & 0 deletions tests/phpunit/CRM/Contact/BAO/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,41 @@ public function testGroupUpdateWithOrganization() {
$testUpdate = CRM_Contact_BAO_Group::create($params2);
}

/**
* Ensure that when hidden smart group is created, wildcard string value is not ignored
*/
public function testHiddenSmartGroup() {
$customGroup = $this->customGroupCreate();
$fields = array(
'label' => 'testFld',
'data_type' => 'String',
'html_type' => 'Text',
'custom_group_id' => $customGroup['id'],
);
$customFieldID = CRM_Core_BAO_CustomField::create($fields)->id;

$contactID = $this->individualCreate(['custom_' . $customFieldID => 'abc']);

$hiddenSmartParams = [
'group_type' => ['2' => 1],
'form_values' => ['custom_' . $customFieldID => ['LIKE' => '%a%']],
'saved_search_id' => NULL,
'search_custom_id' => NULL,
'search_context' => 'advanced',
];
list($smartGroupID, $savedSearchID) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams);

$mailingID = $this->callAPISuccess('Mailing', 'create', [])['id'];
$this->callAPISuccess('MailingGroup', 'create', array(
'mailing_id' => $mailingID,
'group_type' => 'Include',
'entity_table' => 'civicrm_group',
'entity_id' => $smartGroupID,
));

CRM_Mailing_BAO_Mailing::getRecipients($mailingID);
$recipients = $this->callAPISuccess('MailingRecipients', 'get', ['mailing_id' => $mailingID]);
$this->assertEquals(1, $recipients['count'], 'Check recipient count');
}

}

0 comments on commit 25a057d

Please sign in to comment.