CRM-16210 fix backporting to 4.6
authordeb.monish <monish.deb@webaccessglobal.com>
Fri, 18 Mar 2016 07:16:23 +0000 (12:46 +0530)
committerdeb.monish <monish.deb@webaccessglobal.com>
Fri, 18 Mar 2016 07:16:23 +0000 (12:46 +0530)
CRM/Case/Form/Activity.php
CRM/Core/BAO/CustomField.php

index 336a835658c1469a1fa206c4aaee46385c54c5b9..5d71b1fa39843bf93377fb0116f4d54abbf15d11 100644 (file)
@@ -445,6 +445,10 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
     // format activity custom data
     if (!empty($params['hidden_custom'])) {
       if ($this->_activityId) {
+        // retrieve and include the custom data of old Activity
+        $oldActivity = civicrm_api3('Activity', 'getsingle', array('id' => $this->_activityId));
+        $params = array_merge($params, $oldActivity);
+
         // unset custom fields-id from params since we want custom
         // fields to be saved for new activity.
         foreach ($params as $key => $value) {
index b2eaed029af07a428960403cc417c275abda213a..785ff96a552d9fc2a544eaf32ebfecf32e3f9964 100644 (file)
@@ -1721,14 +1721,27 @@ SELECT id
       $fName = $value['name'];
       $mimeType = $value['type'];
 
+      // 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;
+        }
+      }
+
       $filename = pathinfo($fName, PATHINFO_BASENAME);
 
-      // rename this file to go into the secure directory
-      if (!rename($fName, $config->customFileUploadDir . $filename)) {
+      // rename this file to go into the secure directory only if
+      // user has uploaded new file not existing verfied on the basis of $fileID
+      if (empty($fileID) && !rename($fName, $config->customFileUploadDir . $filename)) {
         CRM_Core_Error::statusBounce(ts('Could not move custom file to custom upload directory'));
       }
 
-      if ($customValueId) {
+      if ($customValueId && empty($fileID)) {
         $query = "
 SELECT $columnName
   FROM $tableName