From d532d0cff9492319ae7565ec7cf97f4ac010f896 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 1 Mar 2021 16:18:48 +1300 Subject: [PATCH] dev/core#2423 Fix quasi-regression around serialized custom fields https://lab.civicrm.org/dev/core/-/issues/2423 --- CRM/Contact/Form/CustomData.php | 2 +- CRM/Core/BAO/CustomField.php | 9 ++++----- CRM/Core/BAO/CustomValueTable.php | 6 ++++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CRM/Contact/Form/CustomData.php b/CRM/Contact/Form/CustomData.php index 87849e1b28..9b0cff46d6 100644 --- a/CRM/Contact/Form/CustomData.php +++ b/CRM/Contact/Form/CustomData.php @@ -104,7 +104,7 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID); $mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $hasReachedMax = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($this->_groupID, $this->_tableID); - if ($hasReachedMax && $mode == 'add') { + if ($hasReachedMax && $mode === 'add') { CRM_Core_Error::statusBounce(ts('The maximum record limit is reached')); } $this->_copyValueId = CRM_Utils_Request::retrieve('copyValueId', 'Positive', $this); diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 2ca7070c76..51bfb149a5 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -2687,16 +2687,15 @@ WHERE cf.id = %1 AND cg.is_multiple = 1"; ]; if (isset($fkFields[$field->data_type])) { // Serialized fields store value-separated strings which are incompatible with FK constraints - if ($field->serialize) { - $params['type'] = 'varchar(255)'; - } - else { + if (!$field->serialize) { $params['fk_table_name'] = $fkFields[$field->data_type]; $params['fk_field_name'] = 'id'; $params['fk_attributes'] = 'ON DELETE SET NULL'; } } - + if ($field->serialize) { + $params['type'] = 'varchar(255)'; + } if (isset($field->default_value)) { $params['default'] = "'{$field->default_value}'"; } diff --git a/CRM/Core/BAO/CustomValueTable.php b/CRM/Core/BAO/CustomValueTable.php index 8a3b8c228a..0594d41324 100644 --- a/CRM/Core/BAO/CustomValueTable.php +++ b/CRM/Core/BAO/CustomValueTable.php @@ -227,7 +227,9 @@ class CRM_Core_BAO_CustomValueTable { } else { $set[$field['column_name']] = "%{$count}"; - $params[$count] = [$value, $type]; + // The second parameter is the type of the db field, which + // would be 'String' for a concatenated set of integers. + $params[$count] = [$value, $field['is_multiple'] ? 'String' : $type]; $count++; } @@ -266,7 +268,7 @@ class CRM_Core_BAO_CustomValueTable { else { $query = "$sqlOP SET $setClause $where"; } - $dao = CRM_Core_DAO::executeQuery($query, $params); + CRM_Core_DAO::executeQuery($query, $params); CRM_Utils_Hook::custom($hookOP, $hookID, -- 2.25.1