From 7b8bc7a1438ddf3e36949c648a12ff58def69f48 Mon Sep 17 00:00:00 2001 From: Sudha Bisht Date: Tue, 16 Jun 2015 11:43:07 +0530 Subject: [PATCH] Code cleanup --- CRM/Core/BAO/File.php | 8 +++++++- api/v3/File.php | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CRM/Core/BAO/File.php b/CRM/Core/BAO/File.php index 673514e18c..e0ccca18db 100644 --- a/CRM/Core/BAO/File.php +++ b/CRM/Core/BAO/File.php @@ -220,10 +220,13 @@ class CRM_Core_BAO_File extends CRM_Core_DAO_File { /** * 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(); @@ -242,6 +245,7 @@ class CRM_Core_BAO_File extends CRM_Core_DAO_File { $cefIDs = implode(',', $cefIDs); $sql = "DELETE FROM civicrm_entity_file where id IN ( $cefIDs )"; CRM_Core_DAO::executeQuery($sql); + $isDeleted = TRUE; } if (!empty($cfIDs)) { @@ -267,7 +271,9 @@ class CRM_Core_BAO_File extends CRM_Core_DAO_File { $sql = "DELETE FROM civicrm_file where id IN ( $deleteFiles )"; CRM_Core_DAO::executeQuery($sql); } + $isDeleted = TRUE; } + return $isDeleted; } /** diff --git a/api/v3/File.php b/api/v3/File.php index c0309ce5d8..feccd430f9 100644 --- a/api/v3/File.php +++ b/api/v3/File.php @@ -127,11 +127,15 @@ function civicrm_api3_file_update($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')); - - 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.'); + } } -- 2.25.1