CRM_Core_DAO::executeQuery($query, $queryParams);
}
- $rgDao = new CRM_Dedupe_DAO_DedupeRuleGroup();
- if ($this->_action & CRM_Core_Action::UPDATE) {
- $rgDao->id = $this->_rgid;
- }
-
- $rgDao->title = $values['title'];
- $rgDao->is_reserved = CRM_Utils_Array::value('is_reserved', $values, FALSE);
- $rgDao->used = $values['used'];
- $rgDao->contact_type = $this->_contactType;
- $rgDao->threshold = $values['threshold'];
- $rgDao->save();
-
- // make sure name is set only during insert
- if ($this->_action & CRM_Core_Action::ADD) {
- // generate name based on title
- $rgDao->name = CRM_Utils_String::titleToVar($values['title']) . "_{$rgDao->id}";
- $rgDao->save();
- }
+ $rgDao = CRM_Dedupe_BAO_DedupeRuleGroup::writeRecord([
+ 'id' => $this->_rgid,
+ 'contact_type' => $this->_contactType,
+ 'title' => $values['title'],
+ 'is_reserved' => $values['is_reserved'] ?? FALSE,
+ 'used' => $values['used'],
+ 'threshold' => $values['threshold'],
+ ]);
// lets skip updating of fields for reserved dedupe group
if (!empty($this->_defaults['is_reserved'])) {
$values = array_intersect_key($record, $fields);
$instance->copyValues($values);
if (empty($values[$idField]) && array_key_exists('name', $fields) && empty($values['name'])) {
- $instance->makeNameFromLabel(!empty($fields['name']['required']));
+ $instance->makeNameFromLabel();
}
$instance->save();
* create a unique, clean name derived from the label.
*
* Note: this function does nothing unless a unique index exists for "name" column.
- *
- * @var bool $isRequired
*/
- private function makeNameFromLabel(bool $isRequired): void {
+ private function makeNameFromLabel(): void {
$indexNameWith = NULL;
// Look for a unique index which includes the "name" field
if (method_exists($this, 'indices')) {
*
* Generated from xml/schema/CRM/Dedupe/DedupeRuleGroup.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:7bcb6791c8bff662caa873128c101da8)
+ * (GenCodeChecksum:dc8957103d3accc4eb60eb94a3ee2282)
*/
/**
public $used;
/**
- * Name of the rule group
+ * Unique name of rule group
*
* @var string|null
- * (SQL type: varchar(64))
+ * (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
public $name;
'name' => 'name',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Name'),
- 'description' => ts('Name of the rule group'),
- 'maxlength' => 64,
- 'size' => CRM_Utils_Type::BIG,
+ 'description' => ts('Unique name of rule group'),
+ 'maxlength' => 255,
+ 'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_dedupe_rule_group.name',
'table_name' => 'civicrm_dedupe_rule_group',
'entity' => 'DedupeRuleGroup',
* @return array
*/
public static function indices($localize = TRUE) {
- $indices = [];
+ $indices = [
+ 'UI_name' => [
+ 'name' => 'UI_name',
+ 'field' => [
+ 0 => 'name',
+ ],
+ 'localizable' => FALSE,
+ 'unique' => TRUE,
+ 'sig' => 'civicrm_dedupe_rule_group::1::name',
+ ],
+ ];
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
public function upgrade_5_54_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Add "created_id" column to "civicrm_participant"', 'addCreatedIDColumnToParticipant');
+ $this->addTask('Increase field length of civicrm_dedupe_rule_group.name', 'alterDedupeRuleGroupName');
+ $this->addTask('Add index civicrm_dedupe_rule_group.UI_name', 'addIndex', 'civicrm_dedupe_rule_group', 'name', 'UI');
$this->addTask('Install Elavon Payment Processor Extension as needed', 'installElavonPaymentProcessorExtension');
}
return TRUE;
}
+ /**
+ * @param \CRM_Queue_TaskContext $ctx
+ *
+ * @return bool
+ */
+ public static function alterDedupeRuleGroupName(CRM_Queue_TaskContext $ctx) {
+ CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_dedupe_rule_group` CHANGE COLUMN `name` `name` varchar(255) COMMENT 'Unique name of rule group'", [], TRUE, NULL, FALSE, FALSE);
+ CRM_Core_DAO::executeQuery("UPDATE `civicrm_dedupe_rule_group` g1, `civicrm_dedupe_rule_group` g2 SET g1.name = CONCAT(g1.name, '_', g1.id) WHERE g1.name = g2.name AND g1.id > g2.id", [], TRUE, NULL, FALSE, FALSE);
+ return TRUE;
+ }
+
/**
* @param CRM_Queue_TaskContext $ctx
* @return bool
* API result array
*/
function civicrm_api3_rule_group_create($params) {
+ civicrm_api3_verify_one_mandatory($params, NULL, ['title', 'name']);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'DedupeRuleGroup');
}
$params['contact_type']['api.required'] = TRUE;
$params['threshold']['api.required'] = TRUE;
$params['used']['api.required'] = TRUE;
- $params['name']['api.required'] = TRUE;
}
/**
'contact_type' => 'Individual',
'threshold' => 10,
'used' => 'General',
- 'name' => 'TestRule',
'title' => 'TestRule',
'is_reserved' => 0,
]);
'contact_type' => 'Individual',
'threshold' => 8,
'used' => 'General',
- 'name' => 'TestRule',
'title' => 'TestRule',
'is_reserved' => 0,
]);
'contact_type' => $contactType,
'threshold' => $threshold,
'used' => $used,
- 'name' => $name,
+ 'title' => $name,
'is_reserved' => $isReserved,
]);
$this->callAPISuccess('Job', 'process_batch_merge', ['rule_group_id' => $ruleGroup['id']]);
<name>name</name>
<title>Name</title>
<type>varchar</type>
- <length>64</length>
- <comment>Name of the rule group</comment>
+ <length>255</length>
+ <comment>Unique name of rule group</comment>
<add>2.1</add>
</field>
+ <index>
+ <name>UI_name</name>
+ <fieldName>name</fieldName>
+ <unique>true</unique>
+ <add>5.54</add>
+ </index>
<field>
<name>title</name>
<title>Title</title>