From 47bc54501942929aea5d5ac72ef48cac2146be3f Mon Sep 17 00:00:00 2001 From: franck Date: Thu, 15 Aug 2013 11:44:46 +0200 Subject: [PATCH] Added image processing actgion and loop --- core/lib/Thelia/Action/BaseAction.php | 1 - core/lib/Thelia/Core/Event/TheliaEvents.php | 6 ++ .../Thelia/Core/Template/Element/BaseLoop.php | 10 ++-- .../Thelia/Core/Template/Loop/Category.php | 6 +- .../lib/Thelia/Core/Template/Loop/Content.php | 4 +- .../lib/Thelia/Core/Template/Loop/Feature.php | 4 +- .../Core/Template/Loop/FeatureAvailable.php | 4 +- .../Core/Template/Loop/FeatureValue.php | 4 +- core/lib/Thelia/Core/Template/Loop/Folder.php | 4 +- .../lib/Thelia/Core/Template/Loop/Product.php | 4 +- .../Thelia/Tests/Command/CacheClearTest.php | 58 +++++++++++-------- install/INSTALL-TODO.txt | 2 + install/insert.sql | 5 ++ local/config/database.yml.sample | 6 -- 14 files changed, 66 insertions(+), 52 deletions(-) delete mode 100755 local/config/database.yml.sample diff --git a/core/lib/Thelia/Action/BaseAction.php b/core/lib/Thelia/Action/BaseAction.php index fde3607c8..bef57b30d 100644 --- a/core/lib/Thelia/Action/BaseAction.php +++ b/core/lib/Thelia/Action/BaseAction.php @@ -30,7 +30,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class BaseAction { - /** * @var The container */ diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index ac3306c6a..0f512fab3 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -134,4 +134,10 @@ final class TheliaEvents const CART_CHANGEITEM = "action.changeArticle"; const CART_DELETEITEM = "action.deleteArticle"; + + /** + * Sent on image processing + */ + const IMAGE_PROCESS = "action.processImage"; + } diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index bcc7837dc..b5ee03955 100755 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -163,7 +163,7 @@ abstract class BaseLoop * @throws \InvalidArgumentException if argument is not found in loop argument list * @return Argument the loop argument. */ - public function getArg($argumentName) + protected function getArg($argumentName) { $arg = $this->args->get($argumentName); @@ -181,7 +181,7 @@ abstract class BaseLoop * @throws \InvalidArgumentException if argument is not found in loop argument list * @return Argument the loop argument. */ - public function getArgValue($argumentName) + protected function getArgValue($argumentName) { return $this->getArg($argumentName)->getValue(); } @@ -192,7 +192,7 @@ abstract class BaseLoop * * @return array|mixed|\PropelModelPager|\PropelObjectCollection */ - public function search(ModelCriteria $search, &$pagination = null) + protected function search(ModelCriteria $search, &$pagination = null) { if ($this->getArgValue('page') !== null) { return $this->searchWithPagination($search, $pagination); @@ -206,7 +206,7 @@ abstract class BaseLoop * * @return array|mixed|\PropelObjectCollection */ - public function searchWithOffset(ModelCriteria $search) + protected function searchWithOffset(ModelCriteria $search) { if ($this->getArgValue('limit') >= 0) { $search->limit($this->getArgValue('limit')); @@ -222,7 +222,7 @@ abstract class BaseLoop * * @return array|\PropelModelPager */ - public function searchWithPagination(ModelCriteria $search, &$pagination) + protected function searchWithPagination(ModelCriteria $search, &$pagination) { $pagination = $search->paginate($this->getArgValue('page'), $this->getArgValue('limit')); diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php index a0e636926..4cde51824 100755 --- a/core/lib/Thelia/Core/Template/Loop/Category.php +++ b/core/lib/Thelia/Core/Template/Loop/Category.php @@ -46,7 +46,7 @@ use Thelia\Type\BooleanOrBothType; * - current : current id is used if you are on a category page * - not_empty : if value is 1, category and subcategories must have at least 1 product * - visible : default 1, if you want category not visible put 0 - * - order : all value available : 'alpha', 'alpha_reverse', 'manual' (default), 'manual-reverse', 'random' + * - order : all value available : 'alpha', 'alpha-reverse', 'manual' (default), 'manual-reverse', 'random' * - exclude : all category id you want to exclude (as for id, an integer or a "string list" can be used) * * example : @@ -77,7 +77,7 @@ class Category extends BaseLoop new Argument( 'order', new TypeCollection( - new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual-reverse', 'random')) + new Type\EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual-reverse', 'random')) ), 'manual' ), @@ -130,7 +130,7 @@ class Category extends BaseLoop case "alpha": $search->addAscendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE); break; - case "alpha_reverse": + case "alpha-reverse": $search->addDescendingOrderByColumn(\Thelia\Model\Map\CategoryI18nTableMap::TITLE); break; case "manual-reverse": diff --git a/core/lib/Thelia/Core/Template/Loop/Content.php b/core/lib/Thelia/Core/Template/Loop/Content.php index 7131c1d7e..15bb2068c 100755 --- a/core/lib/Thelia/Core/Template/Loop/Content.php +++ b/core/lib/Thelia/Core/Template/Loop/Content.php @@ -66,7 +66,7 @@ class Content extends BaseLoop new Argument( 'order', new TypeCollection( - new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse', 'random', 'given_id')) + new Type\EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual_reverse', 'random', 'given_id')) ), 'alpha' ), @@ -155,7 +155,7 @@ class Content extends BaseLoop case "alpha": $search->addAscendingOrderByColumn(\Thelia\Model\Map\ContentI18nTableMap::TITLE); break; - case "alpha_reverse": + case "alpha-reverse": $search->addDescendingOrderByColumn(\Thelia\Model\Map\ContentI18nTableMap::TITLE); break; case "manual": diff --git a/core/lib/Thelia/Core/Template/Loop/Feature.php b/core/lib/Thelia/Core/Template/Loop/Feature.php index 15ef6af99..cf8dcc563 100755 --- a/core/lib/Thelia/Core/Template/Loop/Feature.php +++ b/core/lib/Thelia/Core/Template/Loop/Feature.php @@ -65,7 +65,7 @@ class Feature extends BaseLoop new Argument( 'order', new TypeCollection( - new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse')) + new Type\EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual_reverse')) ), 'manual' ) @@ -124,7 +124,7 @@ class Feature extends BaseLoop case "alpha": $search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE); break; - case "alpha_reverse": + case "alpha-reverse": $search->addDescendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE); break; case "manual": diff --git a/core/lib/Thelia/Core/Template/Loop/FeatureAvailable.php b/core/lib/Thelia/Core/Template/Loop/FeatureAvailable.php index 2ef701cc9..838937558 100755 --- a/core/lib/Thelia/Core/Template/Loop/FeatureAvailable.php +++ b/core/lib/Thelia/Core/Template/Loop/FeatureAvailable.php @@ -59,7 +59,7 @@ class FeatureAvailable extends BaseLoop new Argument( 'order', new TypeCollection( - new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse')) + new Type\EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual_reverse')) ), 'manual' ) @@ -100,7 +100,7 @@ class FeatureAvailable extends BaseLoop case "alpha": $search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureAvI18nTableMap::TITLE); break; - case "alpha_reverse": + case "alpha-reverse": $search->addDescendingOrderByColumn(\Thelia\Model\Map\FeatureAvI18nTableMap::TITLE); break; case "manual": diff --git a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php index 43f6df506..9988c500f 100755 --- a/core/lib/Thelia/Core/Template/Loop/FeatureValue.php +++ b/core/lib/Thelia/Core/Template/Loop/FeatureValue.php @@ -61,7 +61,7 @@ class FeatureValue extends BaseLoop new Argument( 'order', new TypeCollection( - new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual_reverse')) + new Type\EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual_reverse')) ), 'manual' ) @@ -108,7 +108,7 @@ class FeatureValue extends BaseLoop case "alpha": $search->addAscendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE); break; - case "alpha_reverse": + case "alpha-reverse": $search->addDescendingOrderByColumn(\Thelia\Model\Map\FeatureI18nTableMap::TITLE); break; case "manual": diff --git a/core/lib/Thelia/Core/Template/Loop/Folder.php b/core/lib/Thelia/Core/Template/Loop/Folder.php index 7f4ee120d..c2f45682a 100755 --- a/core/lib/Thelia/Core/Template/Loop/Folder.php +++ b/core/lib/Thelia/Core/Template/Loop/Folder.php @@ -59,7 +59,7 @@ class Folder extends BaseLoop new Argument( 'order', new TypeCollection( - new Type\EnumListType(array('alpha', 'alpha_reverse', 'manual', 'manual-reverse', 'random')) + new Type\EnumListType(array('alpha', 'alpha-reverse', 'manual', 'manual-reverse', 'random')) ), 'manual' ), @@ -113,7 +113,7 @@ class Folder extends BaseLoop case "alpha": $search->addAscendingOrderByColumn(\Thelia\Model\Map\FolderI18nTableMap::TITLE); break; - case "alpha_reverse": + case "alpha-reverse": $search->addDescendingOrderByColumn(\Thelia\Model\Map\FolderI18nTableMap::TITLE); break; case "manual-reverse": diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 1d93515cb..88f33c3b3 100755 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -79,7 +79,7 @@ class Product extends BaseLoop new Argument( 'order', new TypeCollection( - new Type\EnumListType(array('alpha', 'alpha_reverse', /*'min_price', 'max_price',*/ 'manual', 'manual_reverse', 'ref', /*'promo', 'new',*/ 'random', 'given_id')) + new Type\EnumListType(array('alpha', 'alpha-reverse', /*'min_price', 'max_price',*/ 'manual', 'manual_reverse', 'ref', /*'promo', 'new',*/ 'random', 'given_id')) ), 'alpha' ), @@ -256,7 +256,7 @@ class Product extends BaseLoop case "alpha": $search->addAscendingOrderByColumn(\Thelia\Model\Map\ProductI18nTableMap::TITLE); break; - case "alpha_reverse": + case "alpha-reverse": $search->addDescendingOrderByColumn(\Thelia\Model\Map\ProductI18nTableMap::TITLE); break; /*case "min_price": diff --git a/core/lib/Thelia/Tests/Command/CacheClearTest.php b/core/lib/Thelia/Tests/Command/CacheClearTest.php index 8d0fbb925..4e05e5611 100755 --- a/core/lib/Thelia/Tests/Command/CacheClearTest.php +++ b/core/lib/Thelia/Tests/Command/CacheClearTest.php @@ -44,24 +44,26 @@ class CacheClearTest extends \PHPUnit_Framework_TestCase public function testCacheClear() { - $application = new Application($this->getKernel()); + // Fails on windows - do not execute this test on windows + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + $application = new Application($this->getKernel()); - $cacheClear = new CacheClear(); - $cacheClear->setContainer($this->getContainer()); + $cacheClear = new CacheClear(); + $cacheClear->setContainer($this->getContainer()); - $application->add($cacheClear); + $application->add($cacheClear); - $command = $application->find("cache:clear"); - $commandTester = new CommandTester($command); - $commandTester->execute(array( - "command" => $command->getName(), - "--env" => "test" - )); + $command = $application->find("cache:clear"); + $commandTester = new CommandTester($command); + $commandTester->execute(array( + "command" => $command->getName(), + "--env" => "test" + )); - $fs = new Filesystem(); - - $this->assertFalse($fs->exists($this->cache_dir)); + $fs = new Filesystem(); + $this->assertFalse($fs->exists($this->cache_dir)); + } } /** @@ -69,22 +71,28 @@ class CacheClearTest extends \PHPUnit_Framework_TestCase */ public function testCacheClearWithoutWritePermission() { - $fs = new Filesystem(); - $fs->chmod($this->cache_dir,0100); + // Fails on windows - mock this test on windows + if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + $fs = new Filesystem(); + $fs->chmod($this->cache_dir,0100); - $application = new Application($this->getKernel()); + $application = new Application($this->getKernel()); - $cacheClear = new CacheClear(); - $cacheClear->setContainer($this->getContainer()); + $cacheClear = new CacheClear(); + $cacheClear->setContainer($this->getContainer()); - $application->add($cacheClear); + $application->add($cacheClear); - $command = $application->find("cache:clear"); - $commandTester = new CommandTester($command); - $commandTester->execute(array( - "command" => $command->getName(), - "--env" => "test" - )); + $command = $application->find("cache:clear"); + $commandTester = new CommandTester($command); + $commandTester->execute(array( + "command" => $command->getName(), + "--env" => "test" + )); + } + else { + throw new \RuntimeException(""); + } } public function getKernel() diff --git a/install/INSTALL-TODO.txt b/install/INSTALL-TODO.txt index e1ffb2202..ba319c228 100644 --- a/install/INSTALL-TODO.txt +++ b/install/INSTALL-TODO.txt @@ -19,3 +19,5 @@ Variables Config à initialiser: - password.length : longueur du mot de passe, défaut 4 - form.secret : token csrf - verifyStock : vérification du stock lors du paiement/ajout au panier. Defaut 1 +- default_images_quality_percent : qualité par défaut des images générées (0 à 100, défaut: 75). +- original_image_delivery_mode : mode de mise à disposition des images originales (full resolution) dans le cache. 'symlink' pour un lien symbolique, 'copy' pour une copie \ No newline at end of file diff --git a/install/insert.sql b/install/insert.sql index ab349e09a..1263f47df 100755 --- a/install/insert.sql +++ b/install/insert.sql @@ -7,6 +7,11 @@ INSERT INTO `lang`(`id`,`title`,`code`,`locale`,`url`,`by_default`,`position`,`c INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updated_at`) VALUES ('session_config.default', '1', 1, 1, NOW(), NOW()), ('verifyStock', '1', 1, 0, NOW(), NOW()); +('imagine_driver', 'gd', 1, 0, NOW(), NOW()); +('default_images_quality_percent', '75', 1, 0, NOW(), NOW()); +('original_image_delivery_mode', 'symlink', 1, 0, NOW(), NOW()); + + INSERT INTO `module` (`code`, `type`, `activate`, `position`, `created_at`, `updated_at`) VALUES ('test', '1', '1', '1', NOW(), NOW()); diff --git a/local/config/database.yml.sample b/local/config/database.yml.sample deleted file mode 100755 index 3bb829965..000000000 --- a/local/config/database.yml.sample +++ /dev/null @@ -1,6 +0,0 @@ -database: - connection: - driver: %DRIVER% - user: %USERNAME% - password: %PASSWORD% - dsn: %DSN%