You are here

function field_file_delete in FileField 6.3

Same name and namespace in other branches
  1. 6.2 field_file.inc \field_file_delete()

Delete a field file and its database record.

Parameters

$path: A file object.

$force: Force File Deletion ignoring reference counting.

Return value

mixed TRUE for success, Array for reference count block, or FALSE in the event of an error.

3 calls to field_file_delete()
field_file_save in ./field_file.inc
Save a node file. Delete items if necessary and set new items as permanent.
filefield_field_delete_file in ./filefield_field.inc
Check that FileField controls a file before attempting to deleting it.
filefield_widget_process in ./filefield_widget.inc
An element #process callback for the filefield_widget field type.

File

./field_file.inc, line 252
Common functionality for file handling CCK field modules.

Code

function field_file_delete($file, $force = FALSE) {
  $file = (object) $file;

  // If any module returns a value from the reference hook, the
  // file will not be deleted from Drupal, but file_delete will
  // return a populated array that tests as TRUE.
  if (!$force && ($references = module_invoke_all('file_references', $file))) {
    $references = array_filter($references);

    // only keep positive values
    if (!empty($references)) {
      return $references;
    }
  }

  // Let other modules clean up on delete.
  module_invoke_all('file_delete', $file);

  // Make sure the file is deleted before removing its row from the
  // database, so UIs can still find the file in the database.
  if (file_delete($file->filepath)) {
    db_query('DELETE FROM {files} WHERE fid = %d', $file->fid);
    _field_file_cache(NULL, $file);

    // delete the file from the cache
    return TRUE;
  }
  return FALSE;
}