mirror of
https://github.com/silverstripe/doc.silverstripe.org
synced 2024-10-22 17:05:50 +02:00
7ecbf49ac9
git-svn-id: http://svn.silverstripe.com/projects/ss2doc/branches/v2@117896 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.";
|
|
}
|
|
|
|
} |