function drush_picture_mapping_flush in Picture 7.2
File
- ./
picture.drush.inc, line 27 - Drush integration for the Picture module.
Code
function drush_picture_mapping_flush($name = NULL) {
if (empty($name)) {
$choices = drupal_map_assoc(array_keys(picture_get_mapping_options()));
if ($choice = drush_choice($choices, dt("Choose a picture mapping to flush."))) {
$name = $choice;
}
else {
return;
}
}
/** @var PictureMapping $mapping */
$mapping = picture_mapping_load($name);
if (!$mapping) {
return drush_set_error(dt('Picture mapping !name not recognized.', array(
'!name' => $name,
)));
}
$image_styles = array();
foreach ($mapping
->getMappings() as $breakpoint_name => $multipliers) {
$breakpoint = breakpoints_breakpoint_load_by_fullkey($breakpoint_name);
if ($breakpoint) {
foreach ($multipliers as $multiplier => $mapping_definition) {
switch ($mapping_definition['mapping_type']) {
case 'sizes':
$image_styles = array_merge($image_styles, array_filter($mapping_definition['sizes_image_styles']));
break;
case 'image_style':
$image_styles[] = $mapping_definition['image_style'];
break;
}
}
}
}
if (!empty($image_styles)) {
$image_styles = array_unique($image_styles);
foreach ($image_styles as $image_style) {
drush_invoke('image-flush', array(
$image_style,
));
}
}
else {
drush_log(dt('No image styles found for picture mapping !name', array(
'!name' => $name,
)));
}
}