You are here

function file_delete_multiple in File Entity (fieldable files) 7.3

Same name and namespace in other branches
  1. 7.2 file_entity.file_api.inc \file_delete_multiple()

Delete multiple files.

Unlike core's file_delete(), this function does not care about file usage or skip on invalid URIs. Just deletes the damn file like it should.

Parameters

array $fids: An array of file IDs.

4 calls to file_delete_multiple()
file_entity_delete_form_submit in ./file_entity.pages.inc
Form submission handler for file_entity_delete_form().
file_entity_generate_file_batch_delete in ./file_entity.devel_generate.inc
Implements hook_batch_delete().
file_entity_multiple_delete_confirm_submit in ./file_entity.admin.inc
Submit handler for delete confirmation.
file_entity_multiple_delete_form_submit in ./file_entity.pages.inc
Form submission handler for file_entity_multiple_delete_form().

File

./file_entity.file_api.inc, line 780
API extensions of Drupal core's file.inc.

Code

function file_delete_multiple(array $fids) {
  $transaction = db_transaction();
  if (!empty($fids) && ($files = file_load_multiple($fids))) {
    try {
      foreach ($files as $fid => $file) {
        module_invoke_all('file_delete', $file);
        module_invoke_all('entity_delete', $file, 'file');

        // Skip calling field_attach_delete as file_entity_file_delete()
        // does this.
        // field_attach_delete('file', $file);
        // Remove this file from the search index if needed.
        // This code is implemented in file_entity module rather than in search
        // module, because node module is implementing search module's API,
        // not the other way around.
        if (module_exists('search')) {
          search_reindex($fid, '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_valid_uri($file->uri)) {
          file_unmanaged_delete($file->uri);
        }
      }
      db_delete('file_managed')
        ->condition('fid', $fids, 'IN')
        ->execute();
      db_delete('file_usage')
        ->condition('fid', $fids, 'IN')
        ->execute();
    } catch (Exception $e) {
      $transaction
        ->rollback();
      watchdog_exception('file', $e);
      throw $e;
    }

    // Clear the page and block and file_load_multiple caches.
    entity_get_controller('file')
      ->resetCache();
  }
}