Merge pull request #20119 from civicrm/5.37
[civicrm-core.git] / CRM / Core / BAO / CustomField.php
index 3057d18153f164b3be6f6c9ca4506a1db4fa52de..ab42c14cc520755a183589a5e3a35e9d83d7585f 100644 (file)
@@ -1551,6 +1551,13 @@ SELECT id
           $mimeType = $fileDAO->mime_type;
         }
       }
+      elseif (empty($value['name'])) {
+        // Happens when calling the API to update custom fields values, but the filename
+        // is empty, for an existing entity (in a specific case, was from a d7-webform
+        // that was updating a relationship with a File customfield, so $value['id'] was
+        // not empty, but the filename was empty.
+        return;
+      }
       else {
         $fName = $value['name'];
         $mimeType = $value['type'];
@@ -1994,6 +2001,11 @@ WHERE  id IN ( %1, %2 )
       }
     }
 
+    // Remove option group IDs from fields changed to Text html_type.
+    if ($htmlType == 'Text') {
+      $params['option_group_id'] = '';
+    }
+
     // check for orphan option groups
     if (!empty($params['option_group_id'])) {
       if (!empty($params['id'])) {
@@ -2687,16 +2699,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}'";
     }