2013-04-06 12:48:00 +02:00
|
|
|
<?php
|
2016-06-15 06:03:16 +02:00
|
|
|
|
|
|
|
use SilverStripe\ORM\DataObject;
|
2013-04-06 12:48:00 +02:00
|
|
|
/**
|
|
|
|
* Regenerate all cached images that have been created as the result of a manipulation method being called on a
|
|
|
|
* {@link Image} object
|
|
|
|
*
|
|
|
|
* @package framework
|
|
|
|
* @subpackage filesystem
|
|
|
|
*/
|
|
|
|
class RegenerateCachedImagesTask extends BuildTask {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-06 12:48:00 +02:00
|
|
|
protected $title = 'Regenerate Cached Images Task';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-06 12:48:00 +02:00
|
|
|
protected $description = 'Regenerate all cached images created as the result of an image manipulation';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-06 12:48:00 +02:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-06 12:48:00 +02:00
|
|
|
parent::init();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-06 12:48:00 +02:00
|
|
|
/**
|
|
|
|
* Actually regenerate all the images
|
|
|
|
*/
|
|
|
|
public function run($request) {
|
|
|
|
$processedImages = 0;
|
|
|
|
$regeneratedImages = 0;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-06 12:48:00 +02:00
|
|
|
if($images = DataObject::get('Image')) foreach($images as $image) {
|
|
|
|
if($generated = $image->regenerateFormattedImages()) {
|
|
|
|
$regeneratedImages += $generated;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-06 12:48:00 +02:00
|
|
|
$processedImages++;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-06 12:48:00 +02:00
|
|
|
echo "Regenerated $regeneratedImages cached images from $processedImages Image objects stored in the Database.";
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-06 12:48:00 +02:00
|
|
|
}
|