Skip to content
Snippets Groups Projects
Unverified Commit 0862a728 authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #18809 from colemanw/savedSearchName

SavedSearch - Add name and label columns
parents 7dc9cb42 53b13ffe
Branches
Tags
No related merge requests found
......@@ -503,23 +503,23 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
/**
* Defines a new smart group.
* Takes a sloppy mismash of params and creates two entities: a Group and a SavedSearch
* Currently only used by unit tests.
*
* @param array $params
* Associative array of parameters.
*
* @return CRM_Contact_BAO_Group|NULL
* The new group BAO (if created)
* @deprecated
*/
public static function createSmartGroup(&$params) {
public static function createSmartGroup($params) {
if (!empty($params['formValues'])) {
$ssParams = $params;
unset($ssParams['id']);
if (isset($ssParams['saved_search_id'])) {
$ssParams['id'] = $ssParams['saved_search_id'];
// Remove group parameters from sloppy mismash
unset($ssParams['id'], $ssParams['name'], $ssParams['title'], $ssParams['formValues'], $ssParams['saved_search_id']);
if (isset($params['saved_search_id'])) {
$ssParams['id'] = $params['saved_search_id'];
}
$params['form_values'] = $params['formValues'];
$savedSearch = CRM_Contact_BAO_SavedSearch::create($params);
$ssParams['form_values'] = $params['formValues'];
$savedSearch = CRM_Contact_BAO_SavedSearch::create($ssParams);
$params['saved_search_id'] = $savedSearch->id;
}
......
......@@ -335,18 +335,28 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_
}
/**
* Create a smart group from normalised values.
* Create or update SavedSearch record.
*
* @param array $params
*
* @return \CRM_Contact_DAO_SavedSearch
*/
public static function create(&$params) {
$savedSearch = new CRM_Contact_DAO_SavedSearch();
$savedSearch->copyValues($params);
$savedSearch->save();
// Auto-create unique name from label if supplied
if (empty($params['id']) && empty($params['name']) && !empty($params['label'])) {
$name = CRM_Utils_String::munge($params['label']);
$existing = Civi\Api4\SavedSearch::get(FALSE)
->addWhere('name', 'LIKE', $name . '%')
->addSelect('name')
->execute()->column('name');
$suffix = '';
while (in_array($name . $suffix, $existing)) {
$suffix = '_' . (1 + str_replace('_', '', $suffix));
}
$params['name'] = $name . $suffix;
}
return $savedSearch;
return self::writeRecord($params);
}
/**
......
......@@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Contact/SavedSearch.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:d863f8b0b8659633bc84578e1d6cbf10)
* (GenCodeChecksum:2a23a737d07cbfc49ce1d60a642fee3e)
*/
/**
......@@ -37,6 +37,20 @@ class CRM_Contact_DAO_SavedSearch extends CRM_Core_DAO {
*/
public $id;
/**
* Unique name of saved search
*
* @var string
*/
public $name;
/**
* Administrative label for search
*
* @var string
*/
public $label;
/**
* Submitted form values for this search
*
......@@ -126,6 +140,42 @@ class CRM_Contact_DAO_SavedSearch extends CRM_Core_DAO {
'localizable' => 0,
'add' => '1.1',
],
'name' => [
'name' => 'name',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Saved Search Name'),
'description' => ts('Unique name of saved search'),
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_saved_search.name',
'default' => 'NULL',
'table_name' => 'civicrm_saved_search',
'entity' => 'SavedSearch',
'bao' => 'CRM_Contact_BAO_SavedSearch',
'localizable' => 0,
'html' => [
'type' => 'Text',
],
'add' => '1.0',
],
'label' => [
'name' => 'label',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Saved Search Label'),
'description' => ts('Administrative label for search'),
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_saved_search.label',
'default' => 'NULL',
'table_name' => 'civicrm_saved_search',
'entity' => 'SavedSearch',
'bao' => 'CRM_Contact_BAO_SavedSearch',
'localizable' => 0,
'html' => [
'type' => 'Text',
],
'add' => '5.32',
],
'form_values' => [
'name' => 'form_values',
'type' => CRM_Utils_Type::T_TEXT,
......@@ -262,7 +312,17 @@ class CRM_Contact_DAO_SavedSearch extends CRM_Core_DAO {
* @return array
*/
public static function indices($localize = TRUE) {
$indices = [];
$indices = [
'UI_name' => [
'name' => 'UI_name',
'field' => [
0 => 'name',
],
'localizable' => FALSE,
'unique' => TRUE,
'sig' => 'civicrm_saved_search::1::name',
],
];
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
......
......@@ -10,7 +10,8 @@
*/
/**
* Upgrade logic for FiveThirtyTwo */
* Upgrade logic for FiveThirtyTwo
*/
class CRM_Upgrade_Incremental_php_FiveThirtyTwo extends CRM_Upgrade_Incremental_Base {
/**
......@@ -46,27 +47,15 @@ class CRM_Upgrade_Incremental_php_FiveThirtyTwo extends CRM_Upgrade_Incremental_
// }
}
/*
* Important! All upgrade functions MUST add a 'runSql' task.
* Uncomment and use the following template for a new upgrade version
* (change the x in the function name):
/**
* Upgrade function.
*
* @param string $rev
*/
// /**
// * Upgrade function.
// *
// * @param string $rev
// */
// public function upgrade_5_0_x($rev) {
// $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
// $this->addTask('Do the foo change', 'taskFoo', ...);
// // Additional tasks here...
// // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
// // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
// }
// public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
// return TRUE;
// }
public function upgrade_5_32_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Add column civicrm_saved_search.name', 'addColumn', 'civicrm_saved_search', 'name', "varchar(255) DEFAULT NULL COMMENT 'Unique name of saved search'");
$this->addTask('Add column civicrm_saved_search.label', 'addColumn', 'civicrm_saved_search', 'label', "varchar(255) DEFAULT NULL COMMENT 'Administrative label for search'");
}
}
......@@ -18,6 +18,39 @@
<name>id</name>
<autoincrement>false</autoincrement>
</primaryKey>
<field>
<name>name</name>
<title>Saved Search Name</title>
<type>varchar</type>
<length>255</length>
<default>NULL</default>
<comment>Unique name of saved search</comment>
<html>
<type>Text</type>
</html>
<add>1.0</add>
</field>
<index>
<name>UI_name</name>
<fieldName>name</fieldName>
<unique>true</unique>
<add>5.32</add>
</index>
<field>
<name>label</name>
<title>Saved Search Label</title>
<type>varchar</type>
<length>255</length>
<default>NULL</default>
<comment>Administrative label for search</comment>
<html>
<type>Text</type>
</html>
<add>5.32</add>
</field>
<field>
<name>form_values</name>
<title>Submitted Form Values</title>
......@@ -27,6 +60,7 @@
<serialize>PHP</serialize>
<add>1.1</add>
</field>
<field>
<name>mapping_id</name>
<type>int unsigned</type>
......@@ -41,6 +75,7 @@
<onDelete>SET NULL</onDelete>
<add>1.5</add>
</foreignKey>
<field>
<name>search_custom_id</name>
<type>int unsigned</type>
......@@ -48,6 +83,7 @@
<comment>Foreign key to civicrm_option value table used for saved custom searches.</comment>
<add>2.0</add>
</field>
<field>
<name>where_clause</name>
<type>text</type>
......@@ -56,6 +92,7 @@
<add>1.6</add>
<drop>5.24</drop>
</field>
<field>
<name>select_tables</name>
<type>text</type>
......@@ -65,6 +102,7 @@
<add>1.6</add>
<drop>5.24</drop>
</field>
<field>
<name>where_tables</name>
<type>text</type>
......@@ -74,6 +112,7 @@
<add>1.6</add>
<drop>5.24</drop>
</field>
<field>
<name>api_entity</name>
<type>varchar</type>
......@@ -82,6 +121,7 @@
<comment>Entity name for API based search</comment>
<add>5.24</add>
</field>
<field>
<name>api_params</name>
<type>text</type>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment