Browse Source

Updated add/delete statements.

pull/476/head
MorganDawe 12 years ago
parent
commit
2905e74eb2
  1. 50
      includes/utilities.inc

50
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. * Add a file as managed if is not already.
* *
* @param string $file_name
* The given file name.
* @param string $file_uri * @param string $file_uri
* The given file URI location. * The given file URI location.
*/ */
function islandora_temp_file_entry($file_name, $file_uri) { function islandora_temp_file_entry($file_uri) {
// Check for this file in the file managed table.
$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']) && file_exists($file_uri)) {
$file_name = drupal_basename($file_uri);
$file = new stdClass(); $file = new stdClass();
$file->uri = $file_uri; $file->uri = $file_uri;
$file->filename = $file_name; $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. * 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) {
$query = new EntityFieldQuery(); // Basic sanity check.
$result = $query if ($file_uri != FALSE && file_exists($file_uri)) {
->entityCondition('entity_type', 'file') $query = new EntityFieldQuery();
->propertyCondition('uri', $file_uri) $result = $query
->execute(); ->entityCondition('entity_type', 'file')
$arr_keys = array_keys($result['file']); ->propertyCondition('uri', $file_uri)
$file = file_load($arr_keys[0]); ->execute();
$success = file_delete($file); if (isset($result['file'])) {
if ($success === FALSE) { $arr_keys = array_keys($result['file']);
watchdog( $file = file_load($arr_keys[0]);
'islandora', $success = file_delete($file);
'Failed to delete temp file %file.', if ($success === FALSE) {
array( watchdog(
'%file' => $file_uri, 'islandora',
), 'Failed to delete temp file %file.',
WATCHDOG_WARNING array(
); '%file' => $file_uri,
),
WATCHDOG_WARNING
);
}
return $success;
}
} }
return $success; return $file_uri;
} }
/** /**

Loading…
Cancel
Save