-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpicture.drush.inc
71 lines (63 loc) · 2.12 KB
/
picture.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* @file
* Drush integration for the Picture module.
*/
/**
* Implements hook_drush_command().
*/
function picture_drush_command() {
$items['picture-mapping-flush'] = array(
'description' => 'Flush all derived images for a given picture mapping.',
'arguments' => array(
'name' => 'A picture mapping machine name. If not provided, user may choose from a list of names.',
),
'examples' => array(
'drush picture-mapping-flush' => 'Pick a picture mapping and then delete its image derivatives.',
'drush picture-mapping-flush example_mapping' => 'Delete all image derivatives used by the example_mapping picture mapping.',
),
'aliases' => array('pmf'),
);
return $items;
}
function drush_picture_mapping_flush($name = NULL) {
if (empty($name)) {
$choices = backdrop_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)));
}
}