From 2905e74eb2590e75764c4f6900bf9adfa1085e3d Mon Sep 17 00:00:00 2001 From: MorganDawe Date: Wed, 23 Apr 2014 17:02:10 +0000 Subject: [PATCH] Updated add/delete statements. --- includes/utilities.inc | 50 +++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 6a9675b5..7e09f31c 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -49,19 +49,17 @@ function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) { /** * Add a file as managed if is not already. * - * @param string $file_name - * The given file name. * @param string $file_uri * The given file URI location. */ -function islandora_temp_file_entry($file_name, $file_uri) { - // Check for this file in the file managed table. +function islandora_temp_file_entry($file_uri) { $query = new EntityFieldQuery(); $result = $query ->entityCondition('entity_type', 'file') ->propertyCondition('uri', $file_uri) ->execute(); - if (!isset($result['file'])) { + if (!isset($result['file']) && file_exists($file_uri)) { + $file_name = drupal_basename($file_uri); $file = new stdClass(); $file->uri = $file_uri; $file->filename = $file_name; @@ -82,25 +80,31 @@ function islandora_temp_file_entry($file_name, $file_uri) { * TRUE if success, FALSE if uncessfull and array() if in use. */ function islandora_temp_file_delete($file_uri) { - $query = new EntityFieldQuery(); - $result = $query - ->entityCondition('entity_type', 'file') - ->propertyCondition('uri', $file_uri) - ->execute(); - $arr_keys = array_keys($result['file']); - $file = file_load($arr_keys[0]); - $success = file_delete($file); - if ($success === FALSE) { - watchdog( - 'islandora', - 'Failed to delete temp file %file.', - array( - '%file' => $file_uri, - ), - WATCHDOG_WARNING - ); + // Basic sanity check. + if ($file_uri != FALSE && file_exists($file_uri)) { + $query = new EntityFieldQuery(); + $result = $query + ->entityCondition('entity_type', 'file') + ->propertyCondition('uri', $file_uri) + ->execute(); + if (isset($result['file'])) { + $arr_keys = array_keys($result['file']); + $file = file_load($arr_keys[0]); + $success = file_delete($file); + if ($success === FALSE) { + watchdog( + 'islandora', + 'Failed to delete temp file %file.', + array( + '%file' => $file_uri, + ), + WATCHDOG_WARNING + ); + } + return $success; + } } - return $success; + return $file_uri; } /**