Author: caefer
Date: 2010-04-06 21:34:58 +0200 (Tue, 06 Apr 2010)
New Revision: 29015
Modified:
plugins/sfImageTransformExtraPlugin/trunk/lib/task/sfImageTransformRemovalTask.class.php
Log:
implemented removal task for generated images
Modified:
plugins/sfImageTransformExtraPlugin/trunk/lib/task/sfImageTransformRemovalTask.class.php
===================================================================
---
plugins/sfImageTransformExtraPlugin/trunk/lib/task/sfImageTransformRemovalTask.class.php
2010-04-06 19:22:26 UTC (rev 29014)
+++
plugins/sfImageTransformExtraPlugin/trunk/lib/task/sfImageTransformRemovalTask.class.php
2010-04-06 19:34:58 UTC (rev 29015)
@@ -31,13 +31,8 @@
protected function configure()
{
$this->addArgument('application', sfCommandArgument::REQUIRED, 'The
application name');
+ $this->addArgument('route', sfCommandArgument::REQUIRED, 'The sf_image
route that generated the image(s) you want to remove');
- $this->addOption('env', null, sfCommandOption::PARAMETER_OPTIONAL, 'The
environment', 'prod');
- $this->addOption('type', null, sfCommandOption::PARAMETER_OPTIONAL,
'Limits the removal to a single type. Defaults to all.', '*');
- $this->addOption('format', null, sfCommandOption::PARAMETER_OPTIONAL,
'Limits the removal to a single format. Defaults to all.', '*');
- $this->addOption('id', null, sfCommandOption::PARAMETER_OPTIONAL, 'Limits
the removal to a single ID. Defaults to all.', '*');
- $this->addOption('no-confirmation', null,
sfCommandOption::PARAMETER_OPTIONAL, 'No confirmation before removal.', false);
-
$this->aliases = array(
'remove-thumbnails'
);
@@ -47,26 +42,36 @@
$this->detailedDescription = <<<EOF
Removes thumbnails generated by sfImageTransformExtraPlugin.
-
- [./symfony transforms:remove <appname> |INFO]
- Removes all (!) generated thumbnails.
-
- [./symfony transforms:remove <appname> --type=Model |INFO]
- Removes all thumbnails that originate from an image that belongs to a model
"Model".
-
- [./symfony transforms:remove <appname> --format=rounded_corners |INFO]
- Removes all thumbnails of the format 'rounded_corners'.
-
- [./symfony transforms:remove <appname> --id=123 |INFO]
- Removes all thumbnails that originate from an image with the ID '123'.
-
-All above filter options default to '*' (all). They can be combined in every
combination.
-
- [./symfony transforms:remove <appname> --format=rounded_corners --id=123
|INFO]
- Removes the 'rounded_corners' thumbnail for image ID '123'.
-
EOF;
+ }
+ protected function process(sfCommandManager $commandManager, $options)
+ {
+ $commandManager->process($options);
+ if(array_key_exists('application', $commandManager->getArgumentValues())
&& array_key_exists('route', $commandManager->getArgumentValues()))
+ {
+ $application = $commandManager->getArgumentValue('application');
+ $route = $commandManager->getArgumentValue('route');
+ $configuration = $this->createConfiguration($application, 'prod');
+ $routing =
sfRoutingConfigHandler::getConfiguration($configuration->getConfigPaths('config/routing.yml'));
+ $route = $routing[$route];
+ $className = $route['class'];
+ $this->route = new $className($route['url'], $route['param'],
$route['requirements'], $route['options']);
+ $routeVariables = array_keys($this->route->getVariables());
+ $this->options = array();
+ $optionSet = new sfCommandOptionSet();
+ foreach($commandManager->getErrors() as $error)
+ {
+ if(preg_match('/"--([\w-_]+)"/', $error, $matches) &&
in_array($matches[1], $routeVariables))
+ {
+ $option = new sfCommandOption($matches[1], null,
sfCommandOption::PARAMETER_OPTIONAL, '', null);
+ $this->options[] = $option;
+ $optionSet->addOption($option);
+ }
+ }
+ $commandManager->setOptionSet($optionSet);
+ }
+ return parent::process($commandManager, $options);
}
/**
@@ -80,35 +85,12 @@
*/
protected function execute($arguments = array() , $options = array())
{
- if ('*' == $options['format'])
+ if(count($options) || $this->askConfirmation('Do you really want to delete
all generated images?', 'QUESTION', false))
{
- if ('*' == $options['id'])
- {
- $question = 'Are you sure you want to remove all thumbnails?';
- }
- else
- {
- $question = 'Are you sure you want to remove thumbnails for image #' .
$options['id'] . '?';
- }
+ $cache = sfImageTransformExtraPluginConfiguration::getCache();
+ $this->route->preassemblePattern($options);
+ $cache->removePattern($this->route);
+ $this->logSection('files-', 'Generated images removed.');
}
- else
- {
- if ('*' == $options['id'])
- {
- $question = 'Are you sure you want to remove "' . $options['format'] .
'" thumbnails?';
- }
- else
- {
- $question = 'Are you sure you want to remove "' . $options['format'] .
'" thumbnails for image #' . $options['id'] . '?';
- }
- }
-
- $pattern = sprintf('*:%s:%s:**:*-%s.*',
- $options['type'],
- $options['format'],
- $options['id']
- );
-
-
sfImageTransformExtraPluginConfiguration::getCache()->removePattern($pattern);
}
}
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.