You are here

function field_file_delete in FileField 6.2

Same name and namespace in other branches
  1. 6.3 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
Update an field item file. Delete marked items if neccessary and set new items as permamant.
filefield_field in ./filefield.module
Implementation of CCK's hook_field().
filefield_file_edit_delete in ./filefield.widget.inc
Update the form state so that the file for the given field and delta is marked as deleted.

File

./field_file.inc, line 148
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;
}