dev/core#2423 Fix quasi-regression around serialized custom fields
authoreileen <emcnaughton@wikimedia.org>
Mon, 1 Mar 2021 03:18:48 +0000 (16:18 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 1 Mar 2021 06:12:11 +0000 (19:12 +1300)
https://lab.civicrm.org/dev/core/-/issues/2423

CRM/Contact/Form/CustomData.php
CRM/Core/BAO/CustomField.php
CRM/Core/BAO/CustomValueTable.php

index 87849e1b28eb8950ef60d64fe91be3881c91173d..9b0cff46d6d98d30bf707b93f72b9c09ee429aca 100644 (file)
@@ -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);
index 2ca7070c76cb464c25e66bf1e7ae4793cde6f19a..51bfb149a51a15a5b39ed4bf6ce05fea10abd582 100644 (file)
@@ -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}'";
     }
index 8a3b8c228ab787dc3986340c0ed0e5cbdab25ff5..0594d413244bb7cbea103f54f5996b36d2d9108b 100644 (file)
@@ -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,