2009-05-18 00:06:59 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Remove all cached/generated images that have been created as the result of a manipulation method being called on a
|
|
|
|
* {@link Image} object
|
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-05-18 00:06:59 +02:00
|
|
|
* @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')) {
|
2009-09-10 04:00:42 +02:00
|
|
|
return Security::permissionFailure();
|
2009-05-18 00:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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.";
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|