The "Flush all external images" is not working properly.

The flush only delete images in folder "externals" but what about all the externals images where we apply an image style ?

It could be awesome to transform " $path " in array in the "function imagecache_external_flush_cache" and look for all the "externals" folder in " style/* " folder and then delete the cache images or maybe i'm looking in the wrong way ?

Comments

Alestaan’s picture

Issue summary: View changes
Alestaan’s picture

<?php
function imagecache_external_flush_cache()
{
    $scheme = file_default_scheme();
    $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);

    $var_imagecache_directory = variable_get('imagecache_directory', 'externals');
    $path_all_dir = realpath($wrapper->getDirectoryPath());

    $iter = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($path_all_dir, RecursiveDirectoryIterator::SKIP_DOTS),
        RecursiveIteratorIterator::SELF_FIRST,
        RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
    );

    $paths = array();
    foreach ($iter as $path => $dir) {
        if ($dir->isDir()) {
            $exploded_path = explode('/', $path);
            if (end($exploded_path) === $var_imagecache_directory)
                $paths[] = $path;
        }
    }

    foreach ($paths as $path) {
        if (file_unmanaged_delete_recursive($path)) {
            watchdog('imagecache_external', 'Imagecache caches have been flushed');
            return TRUE;
        }
        return FALSE;
    }

}
?>

Something that way seems working fine for me, any reviews ? could be great :)

Alestaan’s picture

Status: Active » Needs review
BarisW’s picture

Version: 7.x-2.1 » 7.x-2.x-dev
Category: Bug report » Feature request
Priority: Critical » Normal
Status: Needs review » Needs work

Wouldn't it be better to fetch all external images and then call image_path_flush for each image?

Also, how can this be critical?