function file_cron

Implements file_cron()

File

drupal/core/modules/file/file.module, line 712
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

function file_cron() {
  $result = entity_get_controller('file')
    ->retrieveTemporaryFiles();
  foreach ($result as $row) {
    if ($file = file_load($row->fid)) {
      $references = file_usage()
        ->listUsage($file);
      if (empty($references)) {
        if (file_exists($file->uri)) {
          $file
            ->delete();
        }
        else {
          watchdog('file system', 'Could not delete temporary file "%path" during garbage collection', array(
            '%path' => $file->uri,
          ), WATCHDOG_ERROR);
        }
      }
      else {
        watchdog('file system', 'Did not delete temporary file "%path" during garbage collection because it is in use by the following modules: %modules.', array(
          '%path' => $file->uri,
          '%modules' => implode(', ', array_keys($references)),
        ), WATCHDOG_INFO);
      }
    }
  }
}