Fix api.File.delete to actually delete the file
authorOlaf Buddenhagen <antrik@digitalcourage.de>
Wed, 6 May 2015 06:31:44 +0000 (08:31 +0200)
committerOlaf Buddenhagen <antrik@digitalcourage.de>
Wed, 6 May 2015 06:39:07 +0000 (08:39 +0200)
The previous implementation used entityFile and File DAOs to remove the
DB entries, but didn't remove the actual file.

Use CRM_Core_BAO_File::deleteEntityFile() instead -- which is not only
much simpler, but also appears to actually Do The Right Thing (TM)...

api/v3/File.php

index 4ea85825003c0aa492f01de72275ea794472bc20..c0309ce5d84ac4f1b8468323099b7e83290f9623 100644 (file)
@@ -133,19 +133,5 @@ 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();
-  }
-
-  $fileDAO = new CRM_Core_DAO_File();
-  $fileDAO->id = $params['id'];
-  if ($fileDAO->find(TRUE)) {
-    $check = $fileDAO->delete();
-  }
-
-  return $check ? NULL : civicrm_api3_create_error('Error while deleting a file.');
+  CRM_Core_BAO_File::deleteEntityFile('*', $params['id']);
 }