|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\PerfectCmsImages\Tasks; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use SilverStripe\Dev\BuildTask; |
|
7
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
8
|
|
|
use SilverStripe\Control\Director; |
|
9
|
|
|
use SilverStripe\Control\HTTPRequest; |
|
10
|
|
|
use SilverStripe\Security\Permission; |
|
11
|
|
|
use SilverStripe\Assets\Image; |
|
12
|
|
|
use SilverStripe\ORM\DataObject; |
|
13
|
|
|
use SilverStripe\Assets\Flysystem\FlysystemAssetStore; |
|
14
|
|
|
use ReflectionMethod; |
|
15
|
|
|
|
|
16
|
|
|
use SilverStripe\ORM\DB; |
|
17
|
|
|
use SilverStripe\Assets\Storage\AssetStore; |
|
18
|
|
|
use League\Flysystem\Filesystem; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class DeleteGeneratedImagesTask |
|
22
|
|
|
* |
|
23
|
|
|
* Hack to allow removing manipulated images |
|
24
|
|
|
* This is needed occasionally when manipulation functions change |
|
25
|
|
|
* It isn't directly possible with core so this is a workaround |
|
26
|
|
|
* |
|
27
|
|
|
* @see https://github.com/silverstripe/silverstripe-assets/issues/109 |
|
28
|
|
|
* @package App\Tasks |
|
29
|
|
|
* @codeCoverageIgnore |
|
30
|
|
|
*/ |
|
31
|
|
|
class DeleteAllVariants extends BuildTask |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
public function getTitle(): string |
|
35
|
|
|
{ |
|
36
|
|
|
return 'Careful: experimental - DELETE ALL IMAGE VARIANTS'; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getDescription(): string |
|
40
|
|
|
{ |
|
41
|
|
|
return 'Delete all the variants'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Create test jobs for the purposes of testing. |
|
46
|
|
|
* |
|
47
|
|
|
* @param HTTPRequest $request |
|
48
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
|
49
|
|
|
*/ |
|
50
|
|
|
public function run($request) // phpcs:ignore |
|
51
|
|
|
{ |
|
52
|
|
|
$base = Director::baseFolder(); |
|
|
|
|
|
|
53
|
|
|
$go = $request->getVar('go'); |
|
54
|
|
|
$rm = '-exec rm {} \;'; |
|
55
|
|
|
$find = 'find . -regextype posix-extended -regex \'.*__(Fit|Fill|ResizedImage|Scale|Resampled).*\.(jpg|png|JPG|jpeg)\' '; |
|
56
|
|
|
if($go) { |
|
57
|
|
|
exec($find . ' '.$rm); |
|
58
|
|
|
exec($find . ' '.$rm, $output, $retval); |
|
59
|
|
|
} else { |
|
60
|
|
|
exec($find); |
|
61
|
|
|
exec($find, $output, $retval); |
|
62
|
|
|
} |
|
63
|
|
|
foreach($output as $key) { |
|
64
|
|
|
DB::alteration_message($key); |
|
65
|
|
|
} |
|
66
|
|
|
echo "Returned with status $retval"; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|