Browse Source

Changing the file entry to return a file for a given uri, and using file_delete() instead of custom implementation.

pull/476/head
MorganDawe 11 years ago
parent
commit
b43c4fa27a
  1. 98
      includes/utilities.inc

98
includes/utilities.inc

@ -53,6 +53,7 @@ function islandora_convert_bytes_to_human_readable($bytes, $precision = 2) {
* The given file URI location. * The given file URI location.
*/ */
function islandora_temp_file_entry($file_uri) { function islandora_temp_file_entry($file_uri) {
$return = NULL;
$query = new EntityFieldQuery(); $query = new EntityFieldQuery();
$result = $query $result = $query
->entityCondition('entity_type', 'file') ->entityCondition('entity_type', 'file')
@ -66,58 +67,59 @@ function islandora_temp_file_entry($file_uri) {
// Temporary. // Temporary.
$file->status = 0; $file->status = 0;
// Save the temp file to be cleaned up later via cron. // Save the temp file to be cleaned up later via cron.
file_save($file); $return = file_save($file);
} }
return $return;
} }
/** // /**
* Delete a managed file by URI. // * Delete a managed file by URI.
* // *
* @param string $file_uri // * @param string $file_uri
* The files URI. // * The files URI.
* // *
* @return bool // * @return bool
* TRUE if success, FALSE if uncessfull and array() if in use. // * TRUE if success, FALSE if uncessfull and array() if in use.
*/ // */
function islandora_temp_file_delete($file_uri) { // function islandora_temp_file_delete($file_uri) {
// Basic sanity check. // // Basic sanity check.
if ($file_uri != FALSE && file_exists($file_uri)) { // if ($file_uri != FALSE && file_exists($file_uri)) {
$query = new EntityFieldQuery(); // $query = new EntityFieldQuery();
$result = $query // $result = $query
->entityCondition('entity_type', 'file') // ->entityCondition('entity_type', 'file')
->propertyCondition('uri', $file_uri) // ->propertyCondition('uri', $file_uri)
->execute(); // ->execute();
if (isset($result['file'])) { // if (isset($result['file'])) {
$arr_keys = array_keys($result['file']); // $arr_keys = array_keys($result['file']);
$file = file_load($arr_keys[0]); // $file = file_load($arr_keys[0]);
$success = file_delete($file); // $success = file_delete($file);
if ($success === FALSE) { // if ($success === FALSE) {
watchdog( // watchdog(
'islandora', // 'islandora',
'Failed to delete temp file %file.', // 'Failed to delete temp file %file.',
array( // array(
'%file' => $file_uri, // '%file' => $file_uri,
), // ),
WATCHDOG_WARNING // WATCHDOG_WARNING
); // );
} // }
return $success; // return $success;
} // }
} // }
return $file_uri; // return $file_uri;
} // }
/** // /**
* Delete temp files by URI, in an array. // * Delete temp files by URI, in an array.
* // *
* @param array $file_uri_array // * @param array $file_uri_array
* An arry of file URI's to delete. // * An arry of file URI's to delete.
*/ // */
function islandora_temp_file_delete_multi($file_uri_array) { // function islandora_temp_file_delete_multi($file_uri_array) {
foreach ($file_uri_array as $key => $value) { // foreach ($file_uri_array as $key => $value) {
islandora_temp_file_delete($value); // islandora_temp_file_delete($value);
} // }
} // }
/** /**
* Creates a label for control group symbols. * Creates a label for control group symbols.

Loading…
Cancel
Save