Merge pull request #7336 from eileenmcnaughton/CRM-17636
[civicrm-core.git] / api / v3 / Attachment.php
index 5bc789282b5913b44b08b67e6217b532528a1587..1ae66b2651f3df12fda3baad43ce3e7a6f543b4f 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -96,12 +96,11 @@ function _civicrm_api3_attachment_create_spec(&$spec) {
 }
 
 /**
- * Create an attachment.
+ * Create an Attachment.
  *
  * @param array $params
  *
  * @return array
- *   Array of newly created file property values.
  * @throws API_Exception validation errors
  * @see Civi\API\Subscriber\DynamicFKAuthorization
  */
@@ -161,7 +160,10 @@ function civicrm_api3_attachment_create($params) {
     file_put_contents($path, $content);
   }
   elseif (is_string($moveFile)) {
-    rename($moveFile, $path);
+    // CRM-17432 Do not use rename() since it will break file permissions.
+    // Also avoid move_uplaoded_file() because the API can use options.move-file.
+    copy($moveFile, $path);
+    unlink($moveFile);
   }
 
   // Save custom field to entity
@@ -189,7 +191,7 @@ function _civicrm_api3_attachment_get_spec(&$spec) {
 }
 
 /**
- * Get attachment.
+ * Get Attachment.
  *
  * @param array $params
  *
@@ -209,7 +211,7 @@ function civicrm_api3_attachment_get($params) {
 }
 
 /**
- * Adjust metadata for attachment delete action.
+ * Adjust metadata for Attachment delete action.
  *
  * @param $spec
  */
@@ -223,7 +225,7 @@ function _civicrm_api3_attachment_delete_spec(&$spec) {
 }
 
 /**
- * Delete attachment.
+ * Delete Attachment.
  *
  * @param array $params
  *