version fixes
[civicrm-core.git] / api / v3 / File.php
index 682775b1e7e9d156feae2558a53583ee88826543..cc9b35ed91366096fe92a52bd560faffa1006e6d 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.                                    |
  |                                                                    |
  */
 
 /**
+ * This api is a simple wrapper of the CiviCRM file DAO.
  *
- * Definition of the Tag of the CRM API.
- * More detailed documentation can be found
- * {@link http://objectledge.org/confluence/display/CRM/CRM+v1.0+Public+APIs
- * here}
+ * Creating and updating files is a complex process and this api is usually insufficient.
+ * Use the "Attachment" api instead for more robust file handling.
  *
+ * @fixme no unit tests
  * @package CiviCRM_APIv3
- * @subpackage API_File
- * @copyright CiviCRM LLC (c) 2004-2014
- * $Id: $
  */
 
 /**
- * Create a file.
+ * Create a file record.
+ * @note This is only one of several steps needed to create a file in CiviCRM.
+ * Use the "Attachment" api to better handle all steps.
  *
  * @param array $params
  *   Array per getfields metadata.
  *
  * @return array
- *   Array of newly created file property values.
  */
 function civicrm_api3_file_create($params) {
 
@@ -77,11 +75,11 @@ function civicrm_api3_file_create($params) {
   $file = array();
   _civicrm_api3_object_to_array($fileDAO, $file);
 
-  return civicrm_api3_create_success($file, $params, 'file', 'create', $fileDAO);
+  return civicrm_api3_create_success($file, $params, 'File', 'create', $fileDAO);
 }
 
 /**
- * Get a file.
+ * Get a File.
  *
  * @param array $params
  *   Array per getfields metadata.
@@ -95,7 +93,7 @@ function civicrm_api3_file_get($params) {
 }
 
 /**
- * Update an existing file.
+ * Update an existing File.
  *
  * @param array $params
  *   Array per getfields metadata.
@@ -123,31 +121,21 @@ function civicrm_api3_file_update($params) {
 }
 
 /**
- * Delete an existing file.
+ * Delete an existing File.
  *
  * @param array $params
  *   Array per getfields metadata.
  *
  * @return array
- *   API result array
+ *   API Result Array
  */
 function civicrm_api3_file_delete($params) {
 
   civicrm_api3_verify_mandatory($params, NULL, array('id'));
-
-  $check = FALSE;
-
-  $entityFileDAO = new CRM_Core_DAO_EntityFile();
-  $entityFileDAO->file_id = $params['id'];
-  if ($entityFileDAO->find()) {
-    $check = $entityFileDAO->delete();
+  if (CRM_Core_BAO_File::deleteEntityFile('*', $params['id'])) {
+    return civicrm_api3_create_success();
   }
-
-  $fileDAO = new CRM_Core_DAO_File();
-  $fileDAO->id = $params['id'];
-  if ($fileDAO->find(TRUE)) {
-    $check = $fileDAO->delete();
+  else {
+    throw new API_Exception('Error while deleting a file.');
   }
-
-  return $check ? NULL : civicrm_api3_create_error('Error while deleting a file.');
 }