Implements file_cron()
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);
}
}
}
}