DeleteAllVariants   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 3 1
A getDescription() 0 3 1
A run() 0 19 3
1
<?php
2
3
namespace Sunnysideup\PerfectCmsImages\Tasks;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\Dev\BuildTask;
8
use SilverStripe\ORM\DB;
9
10
/**
11
 * Class DeleteGeneratedImagesTask.
12
 *
13
 * Hack to allow removing manipulated images
14
 * This is needed occasionally when manipulation functions change
15
 * It isn't directly possible with core so this is a workaround
16
 *
17
 * @see https://github.com/silverstripe/silverstripe-assets/issues/109
18
 * @codeCoverageIgnore
19
 */
20
class DeleteAllVariants extends BuildTask
21
{
22
    public function getTitle(): string
23
    {
24
        return 'Careful: experimental - DELETE ALL IMAGE VARIANTS';
25
    }
26
27
    public function getDescription(): string
28
    {
29
        return 'Delete all the variants';
30
    }
31
32
    /**
33
     * Create test jobs for the purposes of testing.
34
     *
35
     * @param HTTPRequest $request
36
     */
37
    public function run($request) // phpcs:ignore
38
    {
39
        $base = Director::baseFolder();
0 ignored issues
show
Unused Code introduced by
The assignment to $base is dead and can be removed.
Loading history...
40
        $go = $request->getVar('go');
41
        $rm = '-exec rm {} \;';
42
        $find = 'find . -regextype posix-extended -regex \'.*__(Fit|Fill|ResizedImage|Scale|Resampled).*\.(jpg|png|JPG|jpeg)\' ';
43
        if ($go) {
44
            exec($find . ' ' . $rm);
45
            exec($find . ' ' . $rm, $output, $retval);
46
        } else {
47
            exec($find);
48
            exec($find, $output, $retval);
49
        }
50
51
        foreach ($output as $key) {
52
            DB::alteration_message($key);
53
        }
54
55
        echo "Returned with status {$retval}";
56
    }
57
}
58