mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-27 21:15:40 +02:00
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@86008 467b73ca-7a2a-4603-9d3b-597d59a354a9
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
/**
|
|
* Remove all cached/generated images that have been created as the result of a manipulation method being called on a
|
|
* {@link Image} object
|
|
*
|
|
* @package sapphire
|
|
* @subpackage filesystem
|
|
*/
|
|
class FlushGeneratedImagesTask extends BuildTask {
|
|
|
|
protected $title = 'Flush Generated Images Task';
|
|
|
|
protected $description = 'Remove all cached/generated images created as the result of an image manipulation';
|
|
|
|
/**
|
|
* Check that the user has appropriate permissions to execute this task
|
|
*/
|
|
public function init() {
|
|
if(!Director::is_cli() && !Director::isDev() && !Permission::check('ADMIN')) {
|
|
return Security::permissionFailure();
|
|
}
|
|
|
|
parent::init();
|
|
}
|
|
|
|
/**
|
|
* Actually clear out all the images
|
|
*/
|
|
public function run($request) {
|
|
$processedImages = 0;
|
|
$removedItems = 0;
|
|
|
|
if($images = DataObject::get('Image')) foreach($images as $image) {
|
|
if($deleted = $image->deleteFormattedImages()) {
|
|
$removedItems += $deleted;
|
|
}
|
|
|
|
$processedImages++;
|
|
}
|
|
|
|
echo "Removed $removedItems generated images from $processedImages Image objects stored in the Database.";
|
|
}
|
|
|
|
} |