Copying activity file custom data doesn't copy mime type
Steps to reproduce:
- Create custom data set for Activities
- Create custom field of type File
- Create any type of new activity such as Phone Call
- Upload an image in the custom field
- Create another activity without any custom data
- Note the id's of the 2 activities
- In your custom extension, run the following code to copy custom fields from 1st activity to the 2nd
$params = array(
'activityID' => $first_activity_id,
'mainActivityId' => $second_activity_id,
);
CRM_Activity_BAO_Activity::copyExtendedActivityData($params);
- Inspect civicrm_file table
- The new entry doesn't have mime_type set
Issue
- In
copyExtendedActivityData()
method in CRM/Activity/BAO/Activity.php 'path' should be renamed to 'type' in the following coding block
$customParams["custom_{$key}_-1"] = array(
'name' => $fileValues[0],
'path' => $fileValues[1],
);
- This is because in
formatCustomField()
method in CRM/Core/BAO/CustomField.php, the mimeType variable uses 'type' not path
// If we are already passing the file id as a value then retrieve and set the file data
if (CRM_Utils_Rule::integer($value)) {
$fileDAO = new CRM_Core_DAO_File();
$fileDAO->id = $value;
$fileDAO->find(TRUE);
if ($fileDAO->N) {
$fileID = $value;
$fName = $fileDAO->uri;
$mimeType = $fileDAO->mime_type;
}
} else {
$fName = $value['name'];
$mimeType = $value['type'];
}
- Furthermore the
path()
method in CRM/Core/BAO/File.php which is used by copyExtendedActivityData()
return path and mime type