'imagecache_drush_preset_flush', 'description' => dt('Flush an imagecache preset.'), 'examples' => array( 'drush imagecache flush foobar' => dt('Flush the ImageCache preset "foobar".'), ), 'aliases' => array('icf'), ); return $items; } /** * Implementation of hook_drush_help(). */ function imagecache_drush_help($section) { switch ($section) { case 'drush:imagecache-flush': return dt('Flush a given preset.'); } } /** * Drush callback to perform actual imagecache preset flush. */ function imagecache_drush_preset_flush() { $args = func_get_args(); if (empty($args)) { foreach (imagecache_presets(TRUE) as $preset) { $preset_names[] = $preset['presetname']; } drush_set_error(dt('You must specify a preset name to flush or specify "all".'. "\n".'Presets are: ').implode($preset_names,' ')); } else { // Implement 'all' if (count($args) == 1 && $args[0] == 'all') { $args = array(); foreach (imagecache_presets(TRUE) as $preset) { $args[] = $preset['presetname']; } } foreach ($args as $arg) { // Load preset. if ($preset = imagecache_preset_by_name($arg)) { // This mimics the logic inside of the function // imagecache_preset_flush(), but without the access check. $presetdir = DRUPAL_ROOT . base_path() . file_directory_path() .'/imagecache/'. $preset['presetname']; if (is_dir($presetdir)) { _imagecache_recursive_delete($presetdir); drush_log(dt('Flushed "@preset" preset.', array('@preset' => $arg)), 'ok'); } else { drush_log(dt('Cache for preset "@preset" was already empty.', array('@preset' => $arg)), 'ok'); } } else { drush_log(dt('Preset "@preset" not found.', array('@preset' => $arg)), 'error'); } } } return TRUE; }