/**
* Delete all the files and associated object associated with this
* combination
+ * @return bool
+ * Was file deleted?
*/
public static function deleteEntityFile($entityTable, $entityID, $fileTypeID = NULL, $fileID = NULL) {
+ $isDeleted = FALSE;
if (empty($entityTable) || empty($entityID)) {
- return;
+ return $isDeleted;
}
$config = CRM_Core_Config::singleton();
$cefIDs = implode(',', $cefIDs);
$sql = "DELETE FROM civicrm_entity_file where id IN ( $cefIDs )";
CRM_Core_DAO::executeQuery($sql);
+ $isDeleted = TRUE;
}
if (!empty($cfIDs)) {
$sql = "DELETE FROM civicrm_file where id IN ( $deleteFiles )";
CRM_Core_DAO::executeQuery($sql);
}
+ $isDeleted = TRUE;
}
+ return $isDeleted;
}
/**
* 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'));
-
- CRM_Core_BAO_File::deleteEntityFile('*', $params['id']);
+ if (CRM_Core_BAO_File::deleteEntityFile('*', $params['id'])) {
+ return civicrm_api3_create_success();
+ }
+ else {
+ throw new API_Exception('Error while deleting a file.');
+ }
}