Delete leftover temp files.

Return value

int Count of the number of files removed

2 calls to advagg_remove_temp_files()
advagg_admin_cleanup_temp_files_button in ./advagg.admin.inc
Delete leftover temp files.
advagg_cron in ./advagg.module
Implements hook_cron().

File

./advagg.cache.inc, line 701

Code

function advagg_remove_temp_files() {
    // Make sure advagg_get_root_files_dir() is available.
    drupal_load('module', 'advagg');
    // Make sure advagg_install_delete_empty_file_if_stale() is available.
    module_load_include('install', 'advagg', 'advagg');
    // Get the advagg paths.
    $advagg_path = advagg_get_root_files_dir();
    $total_count = 0;
    // Get the top level path.
    $top_level = substr($advagg_path[0][0], 0, strpos($advagg_path[0][0], 'advagg_css'));
    // Remove empty temp files from public://.
    $files = file_scan_directory($top_level, '/(?!files$)file.*|fil.*\\.tmp/', array(
        'recurse' => FALSE,
        'callback' => 'advagg_install_delete_empty_file_if_stale',
    ));
    foreach ($files as $key => $file) {
        if (file_exists($file->uri)) {
            unset($files[$key]);
        }
    }
    $total_count += count($files);
    // Remove empty temp files from public://advagg_css.
    $files = file_scan_directory($advagg_path[0][0], '/file.*|fil.*\\.tmp/', array(
        'recurse' => FALSE,
        'callback' => 'advagg_install_delete_empty_file_if_stale',
    ));
    foreach ($files as $key => $file) {
        if (file_exists($file->uri)) {
            unset($files[$key]);
        }
    }
    $total_count += count($files);
    // Remove empty temp files from public://advagg_js.
    $files = file_scan_directory($advagg_path[1][0], '/file.*|fil.*\\.tmp/', array(
        'recurse' => FALSE,
        'callback' => 'advagg_install_delete_empty_file_if_stale',
    ));
    foreach ($files as $key => $file) {
        if (file_exists($file->uri)) {
            unset($files[$key]);
        }
    }
    $total_count += count($files);
    // Remove empty temp files from public://.
    $files = file_scan_directory($top_level, '/file_advagg_.*/', array(
        'recurse' => FALSE,
        'callback' => 'advagg_delete_temp_file_if_stale',
    ));
    foreach ($files as $key => $file) {
        if (file_exists($file->uri)) {
            unset($files[$key]);
        }
    }
    $total_count += count($files);
    // Remove empty temp files from public://advagg_css.
    $files = file_scan_directory($advagg_path[0][0], '/file_advagg_.*/', array(
        'recurse' => FALSE,
        'callback' => 'advagg_delete_temp_file_if_stale',
    ));
    foreach ($files as $key => $file) {
        if (file_exists($file->uri)) {
            unset($files[$key]);
        }
    }
    $total_count += count($files);
    // Remove empty temp files from public://advagg_js.
    $files = file_scan_directory($advagg_path[1][0], '/file_advagg_.*/', array(
        'recurse' => FALSE,
        'callback' => 'advagg_delete_temp_file_if_stale',
    ));
    foreach ($files as $key => $file) {
        if (file_exists($file->uri)) {
            unset($files[$key]);
        }
    }
    $total_count += count($files);
    // Remove empty temp files from public://.
    $files = file_scan_directory($top_level, '/advagg_file_.*/', array(
        'recurse' => FALSE,
        'callback' => 'advagg_delete_temp_file_if_stale',
    ));
    foreach ($files as $key => $file) {
        if (file_exists($file->uri)) {
            unset($files[$key]);
        }
    }
    $total_count += count($files);
    // Remove empty temp files from public://advagg_css.
    $files = file_scan_directory($advagg_path[0][0], '/advagg_file_.*/', array(
        'recurse' => FALSE,
        'callback' => 'advagg_delete_temp_file_if_stale',
    ));
    foreach ($files as $key => $file) {
        if (file_exists($file->uri)) {
            unset($files[$key]);
        }
    }
    $total_count += count($files);
    // Remove empty temp files from public://advagg_js.
    $files = file_scan_directory($advagg_path[1][0], '/advagg_file_.*/', array(
        'recurse' => FALSE,
        'callback' => 'advagg_delete_temp_file_if_stale',
    ));
    foreach ($files as $key => $file) {
        if (file_exists($file->uri)) {
            unset($files[$key]);
        }
    }
    $total_count += count($files);
    // Output info.
    return $total_count;
}