Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitLab issue 652 Copying activity file custom data doesn't copy mime … #13427

Merged
merged 1 commit into from
Jan 21, 2019
Merged

GitLab issue 652 Copying activity file custom data doesn't copy mime … #13427

merged 1 commit into from
Jan 21, 2019

Conversation

chamilwijesooriya
Copy link
Contributor

Overview

GitLab Issue 652 Copying activity file custom data doesn't copy mime type

Before

  1. Create custom data set for Activities
  2. Create custom field of type File
  3. Create any type of new activity such as Phone Call
  4. Upload an image in the custom field
  5. Create another activity without any custom data
  6. Note the id's of the 2 activities
  7. 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);
  1. Inspect civicrm_file table
  2. The new entry doesn't have mime_type set

After

  • In copyExtendedActivityData() method in CRM/Activity/BAO/Activity.php 'path' was renamed to 'type' in the following coding block
$customParams["custom_{$key}_-1"] = array(
    'name' => $fileValues[0],
    'path' => $fileValues[1],
);
  • Mime type is getting set after the change

Technical Details

  • 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],
);

activity

  • 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'];
}

customfield

  • Furthermore the path() method in CRM/Core/BAO/File.php which is used by copyExtendedActivityData() returns path and mime type

file

Comments

@civibot
Copy link

civibot bot commented Jan 9, 2019

(Standard links)

@civibot civibot bot added the master label Jan 9, 2019
@eileenmcnaughton
Copy link
Contributor

@mattwire do we have a generic api action for this sort of thing - feels familiar & we shouldn't be encouraging supporting extensions to call non-api methods directly

@chamilwijesooriya
Copy link
Contributor Author

@eileenmcnaughton this method is called in roughly 3 places, case merge being one. (CRM_Case_BAO_Case::mergeCases())

@mattwire
Copy link
Contributor

@eileenmcnaughton The api would be at a higher level and this function is being used in various case activity functions (I don't think it affects non-case activities). For example when activities are "filed on case" or a case start date is modified.

I think @chamilwijesooriya is calling the function from extension just to isolate and show the issue? The analysis looks correct as does the fix.
@lcdservices Do you have time to r-run this and confirm the issues exists before / is fixed after?

@chamilwijesooriya
Copy link
Contributor Author

@mattwire yep

@colemanw
Copy link
Member

I've tested this out - reproduced the bug and confirmed the fix. Thanks @chamilwijesooriya!

@colemanw colemanw merged commit 03b996d into civicrm:master Jan 21, 2019
@chamilwijesooriya
Copy link
Contributor Author

@colemanw cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants