diff --git a/.gitignore b/.gitignore index 54223e3f8..0fb8e24f5 100755 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ phpmyadmin templates/default-esi local/modules/TemplateEsiModule composer.phar +web/.htaccess diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dd437a0c..cfc233a9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#2.0.0-beta5 +- Remove container from BaseAction. +- fix sending mail on order creation + #2.0.0-beta4 - Tinymce is now a dedicated module. You need to activate it. - Fix PDF creation. Bug #180 diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index 2195d946f..9e278d899 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -69,7 +69,7 @@ class Address extends BaseAction implements EventSubscriberInterface protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event) { - $addressModel->setDispatcher($this->getDispatcher()); + $addressModel->setDispatcher($event->getDispatcher()); $con = Propel::getWriteConnection(AddressTableMap::DATABASE_NAME); $con->beginTransaction(); try { diff --git a/core/lib/Thelia/Action/Administrator.php b/core/lib/Thelia/Action/Administrator.php index 5c34e2c59..77078df0b 100644 --- a/core/lib/Thelia/Action/Administrator.php +++ b/core/lib/Thelia/Action/Administrator.php @@ -40,7 +40,7 @@ class Administrator extends BaseAction implements EventSubscriberInterface $administrator = new AdminModel(); $administrator - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setFirstname($event->getFirstname()) ->setLastname($event->getLastname()) ->setLogin($event->getLogin()) @@ -62,7 +62,7 @@ class Administrator extends BaseAction implements EventSubscriberInterface if (null !== $administrator = AdminQuery::create()->findPk($event->getId())) { $administrator - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setFirstname($event->getFirstname()) ->setLastname($event->getLastname()) ->setLogin($event->getLogin()) diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php index 92eb75634..19037c9e4 100644 --- a/core/lib/Thelia/Action/Area.php +++ b/core/lib/Thelia/Action/Area.php @@ -31,7 +31,7 @@ use Thelia\Core\Event\Area\AreaUpdatePostageEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\AreaQuery; use Thelia\Model\CountryQuery; -use Thelia\Action\BaseAction; + use Thelia\Model\Area as AreaModel; /** @@ -45,7 +45,7 @@ class Area extends BaseAction implements EventSubscriberInterface public function addCountry(AreaAddCountryEvent $event) { if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { - $country->setDispatcher($this->getDispatcher()); + $country->setDispatcher($event->getDispatcher()); $country->setAreaId($event->getAreaId()) ->save(); @@ -56,7 +56,9 @@ class Area extends BaseAction implements EventSubscriberInterface public function removeCountry(AreaRemoveCountryEvent $event) { if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { - $country->setDispatcher($this->getDispatcher()); + $event->setArea($country->getArea()); + + $country->setDispatcher($event->getDispatcher()); $country->setAreaId(null) ->save(); } @@ -65,7 +67,7 @@ class Area extends BaseAction implements EventSubscriberInterface public function updatePostage(AreaUpdatePostageEvent $event) { if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) { - $area->setDispatcher($this->getDispatcher()); + $area->setDispatcher($event->getDispatcher()); $area ->setPostage($event->getPostage()) ->save(); @@ -77,7 +79,7 @@ class Area extends BaseAction implements EventSubscriberInterface public function delete(AreaDeleteEvent $event) { if (null !== $area = AreaQuery::create()->findPk($event->getAreaId())) { - $area->setDispatcher($this->getDispatcher()); + $area->setDispatcher($event->getDispatcher()); $area->delete(); $event->setArea($area); @@ -89,7 +91,7 @@ class Area extends BaseAction implements EventSubscriberInterface $area = new AreaModel(); $area - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setName($event->getAreaName()) ->save(); diff --git a/core/lib/Thelia/Action/Attribute.php b/core/lib/Thelia/Action/Attribute.php index 4591c2ea5..5372f1ec7 100644 --- a/core/lib/Thelia/Action/Attribute.php +++ b/core/lib/Thelia/Action/Attribute.php @@ -51,7 +51,7 @@ class Attribute extends BaseAction implements EventSubscriberInterface $attribute = new AttributeModel(); $attribute - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) @@ -78,7 +78,7 @@ class Attribute extends BaseAction implements EventSubscriberInterface if (null !== $attribute = AttributeQuery::create()->findPk($event->getAttributeId())) { $attribute - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) @@ -103,7 +103,7 @@ class Attribute extends BaseAction implements EventSubscriberInterface if (null !== ($attribute = AttributeQuery::create()->findPk($event->getAttributeId()))) { $attribute - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; @@ -118,7 +118,7 @@ class Attribute extends BaseAction implements EventSubscriberInterface */ public function updatePosition(UpdatePositionEvent $event) { - return $this->genericUpdatePosition(AttributeQuery::create(), $event); + $this->genericUpdatePosition(AttributeQuery::create(), $event); } protected function doAddToAllTemplates(AttributeModel $attribute) diff --git a/core/lib/Thelia/Action/AttributeAv.php b/core/lib/Thelia/Action/AttributeAv.php index f5d320f03..5c3fdebc4 100644 --- a/core/lib/Thelia/Action/AttributeAv.php +++ b/core/lib/Thelia/Action/AttributeAv.php @@ -47,7 +47,7 @@ class AttributeAv extends BaseAction implements EventSubscriberInterface $attribute = new AttributeAvModel(); $attribute - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setAttributeId($event->getAttributeId()) ->setLocale($event->getLocale()) @@ -70,7 +70,7 @@ class AttributeAv extends BaseAction implements EventSubscriberInterface if (null !== $attribute = AttributeAvQuery::create()->findPk($event->getAttributeAvId())) { $attribute - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) @@ -95,7 +95,7 @@ class AttributeAv extends BaseAction implements EventSubscriberInterface if (null !== ($attribute = AttributeAvQuery::create()->findPk($event->getAttributeAvId()))) { $attribute - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; @@ -110,7 +110,7 @@ class AttributeAv extends BaseAction implements EventSubscriberInterface */ public function updatePosition(UpdatePositionEvent $event) { - return $this->genericUpdatePosition(AttributeAvQuery::create(), $event); + $this->genericUpdatePosition(AttributeAvQuery::create(), $event); } /** diff --git a/core/lib/Thelia/Action/BaseAction.php b/core/lib/Thelia/Action/BaseAction.php index c376a78b7..8da1e1ce5 100644 --- a/core/lib/Thelia/Action/BaseAction.php +++ b/core/lib/Thelia/Action/BaseAction.php @@ -33,26 +33,6 @@ use Thelia\Form\Exception\FormValidationException; class BaseAction { - /** - * @var The container - */ - protected $container; - - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - /** - * Return the event dispatcher, - * - * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface - */ - public function getDispatcher() - { - return $this->container->get('event_dispatcher'); - } - /** * Changes object position, selecting absolute ou relative change. * @@ -65,16 +45,16 @@ class BaseAction { if (null !== $object = $query->findPk($event->getObjectId())) { - $object->setDispatcher($this->getDispatcher()); + $object->setDispatcher($event->getDispatcher()); $mode = $event->getMode(); if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE) - return $object->changeAbsolutePosition($event->getPosition()); + $object->changeAbsolutePosition($event->getPosition()); else if ($mode == UpdatePositionEvent::POSITION_UP) - return $object->movePositionUp(); + $object->movePositionUp(); else if ($mode == UpdatePositionEvent::POSITION_DOWN) - return $object->movePositionDown(); + $object->movePositionDown(); } } @@ -84,14 +64,15 @@ class BaseAction * @param ModelCriteria $query * @param UpdateSeoEvent $event * - * @return mixed + * @return mixed an SEOxxx object + * @throws FormValidationException if a rewritten URL cannot be created */ protected function genericUpdateSeo(ModelCriteria $query, UpdateSeoEvent $event) { if (null !== $object = $query->findPk($event->getObjectId())) { $object - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setMetaTitle($event->getMetaTitle()) @@ -109,9 +90,8 @@ class BaseAction } $event->setObject($object); - - return $object; } - } -} + return $object; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Action/Cart.php b/core/lib/Thelia/Action/Cart.php index dbaf3409b..25c2604c6 100644 --- a/core/lib/Thelia/Action/Cart.php +++ b/core/lib/Thelia/Action/Cart.php @@ -23,7 +23,8 @@ namespace Thelia\Action; -use Symfony\Component\HttpFoundation\Request; + +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Cart\CartEvent; use Thelia\Core\Event\TheliaEvents; @@ -67,7 +68,7 @@ class Cart extends BaseAction implements EventSubscriberInterface ->findOne(); $event->setCartItem( - $this->doAddItem($cart, $productId, $productPrice->getProductSaleElements(), $quantity, $productPrice) + $this->doAddItem($event->getDispatcher(), $cart, $productId, $productPrice->getProductSaleElements(), $quantity, $productPrice) ); } @@ -130,7 +131,7 @@ class Cart extends BaseAction implements EventSubscriberInterface if ($cartItem) { $event->setCartItem( - $this->updateQuantity($cartItem, $quantity) + $this->updateQuantity($event->getDispatcher(), $cartItem, $quantity) ); } } @@ -174,9 +175,9 @@ class Cart extends BaseAction implements EventSubscriberInterface * * @return CartItem */ - protected function updateQuantity(CartItem $cartItem, $quantity) + protected function updateQuantity(EventDispatcherInterface $dispatcher, CartItem $cartItem, $quantity) { - $cartItem->setDisptacher($this->getDispatcher()); + $cartItem->setDisptacher($dispatcher); $cartItem->updateQuantity($quantity) ->save(); @@ -194,10 +195,10 @@ class Cart extends BaseAction implements EventSubscriberInterface * * @return CartItem */ - protected function doAddItem(\Thelia\Model\Cart $cart, $productId, \Thelia\Model\ProductSaleElements $productSaleElements, $quantity, ProductPrice $productPrice) + protected function doAddItem(EventDispatcherInterface $dispatcher, \Thelia\Model\Cart $cart, $productId, \Thelia\Model\ProductSaleElements $productSaleElements, $quantity, ProductPrice $productPrice) { $cartItem = new CartItem(); - $cartItem->setDisptacher($this->getDispatcher()); + $cartItem->setDisptacher($dispatcher); $cartItem ->setCart($cart) ->setProductId($productId) diff --git a/core/lib/Thelia/Action/Category.php b/core/lib/Thelia/Action/Category.php index 9d895c7de..dfdeeb3b7 100644 --- a/core/lib/Thelia/Action/Category.php +++ b/core/lib/Thelia/Action/Category.php @@ -53,12 +53,12 @@ class Category extends BaseAction implements EventSubscriberInterface $category = new CategoryModel(); $category - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) - ->setTitle($event->getTitle()) ->setParent($event->getParent()) ->setVisible($event->getVisible()) + ->setTitle($event->getTitle()) ->save() ; @@ -76,7 +76,7 @@ class Category extends BaseAction implements EventSubscriberInterface if (null !== $category = CategoryQuery::create()->findPk($event->getCategoryId())) { $category - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) @@ -115,7 +115,7 @@ class Category extends BaseAction implements EventSubscriberInterface if (null !== $category = CategoryQuery::create()->findPk($event->getCategoryId())) { $category - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; @@ -133,7 +133,7 @@ class Category extends BaseAction implements EventSubscriberInterface $category = $event->getCategory(); $category - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setVisible($category->getVisible() ? false : true) ->save() ; @@ -146,7 +146,7 @@ class Category extends BaseAction implements EventSubscriberInterface */ public function updatePosition(UpdatePositionEvent $event) { - return $this->genericUpdatePosition(CategoryQuery::create(), $event); + $this->genericUpdatePosition(CategoryQuery::create(), $event); } public function addContent(CategoryAddContentEvent $event) @@ -158,7 +158,7 @@ class Category extends BaseAction implements EventSubscriberInterface $content = new CategoryAssociatedContent(); $content - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setCategory($event->getCategory()) ->setContentId($event->getContentId()) ->save() @@ -175,7 +175,7 @@ class Category extends BaseAction implements EventSubscriberInterface if ($content !== null) { $content - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete(); } } diff --git a/core/lib/Thelia/Action/Config.php b/core/lib/Thelia/Action/Config.php index b1c714a0e..377eb17f6 100644 --- a/core/lib/Thelia/Action/Config.php +++ b/core/lib/Thelia/Action/Config.php @@ -41,7 +41,7 @@ class Config extends BaseAction implements EventSubscriberInterface { $config = new ConfigModel(); - $config->setDispatcher($this->getDispatcher()) + $config->setDispatcher($event->getDispatcher()) ->setName($event->getEventName()) ->setValue($event->getValue()) ->setLocale($event->getLocale()) @@ -65,7 +65,7 @@ class Config extends BaseAction implements EventSubscriberInterface if ($event->getValue() !== $config->getValue()) { - $config->setDispatcher($this->getDispatcher())->setValue($event->getValue())->save(); + $config->setDispatcher($event->getDispatcher())->setValue($event->getValue())->save(); $event->setConfig($config); } @@ -82,7 +82,7 @@ class Config extends BaseAction implements EventSubscriberInterface if (null !== $config = ConfigQuery::create()->findPk($event->getConfigId())) { - $config->setDispatcher($this->getDispatcher()) + $config->setDispatcher($event->getDispatcher()) ->setName($event->getEventName()) ->setValue($event->getValue()) ->setHidden($event->getHidden()) @@ -110,7 +110,7 @@ class Config extends BaseAction implements EventSubscriberInterface if (!$config->getSecured()) { - $config->setDispatcher($this->getDispatcher())->delete(); + $config->setDispatcher($event->getDispatcher())->delete(); $event->setConfig($config); } diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php index 986698220..98a094f7b 100644 --- a/core/lib/Thelia/Action/Content.php +++ b/core/lib/Thelia/Action/Content.php @@ -68,7 +68,7 @@ class Content extends BaseAction implements EventSubscriberInterface public function update(ContentUpdateEvent $event) { if (null !== $content = ContentQuery::create()->findPk($event->getContentId())) { - $content->setDispatcher($this->getDispatcher()); + $content->setDispatcher($event->getDispatcher()); $content ->setVisible($event->getVisible()) @@ -100,21 +100,7 @@ class Content extends BaseAction implements EventSubscriberInterface public function updatePosition(UpdatePositionEvent $event) { - if (null !== $content = ContentQuery::create()->findPk($event->getObjectId())) { - $content->setDispatcher($this->getDispatcher()); - - switch ($event->getMode()) { - case UpdatePositionEvent::POSITION_ABSOLUTE: - $content->changeAbsolutePosition($event->getPosition()); - break; - case UpdatePositionEvent::POSITION_DOWN: - $content->movePositionDown(); - break; - case UpdatePositionEvent::POSITION_UP: - $content->movePositionUp(); - break; - } - } + $this->genericUpdatePosition(ContentQuery::create(), $event); } public function toggleVisibility(ContentToggleVisibilityEvent $event) @@ -122,7 +108,7 @@ class Content extends BaseAction implements EventSubscriberInterface $content = $event->getContent(); $content - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setVisible(!$content->getVisible()) ->save(); @@ -135,7 +121,7 @@ class Content extends BaseAction implements EventSubscriberInterface if (null !== $content = ContentQuery::create()->findPk($event->getContentId())) { $defaultFolderId = $content->getDefaultFolderId(); - $content->setDispatcher($this->getDispatcher()) + $content->setDispatcher($event->getDispatcher()) ->delete(); $event->setDefaultFolderId($defaultFolderId); diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index 8751dae3b..088185168 100644 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -23,6 +23,8 @@ namespace Thelia\Action; +use Propel\Runtime\ServiceContainer\ServiceContainerInterface; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Condition\ConditionFactory; use Thelia\Condition\Implementation\ConditionInterface; @@ -49,6 +51,34 @@ use Thelia\Model\OrderCoupon; class Coupon extends BaseAction implements EventSubscriberInterface { /** + * @var \Thelia\Core\HttpFoundation\Request + */ + protected $request; + + /** @var CouponFactory $couponFactory */ + protected $couponFactory; + + /** @var CouponManager $couponManager */ + protected $couponManager; + + /** @var ConditionInterface $noConditionRule */ + protected $noConditionRule; + + /** @var ConditionFactory $conditionFactory */ + protected $conditionFactory; + + public function __construct(Request $request, + CouponFactory $couponFactory, CouponManager $couponManager, + ConditionInterface $noConditionRule, ConditionFactory $conditionFactory) + { + $this->request = $request; + $this->couponFactory = $couponFactory; + $this->couponManager = $couponManager; + $this->noConditionRule = $noConditionRule; + $this->conditionFactory = $conditionFactory; + } + + /** * Occurring when a Coupon is about to be created * * @param CouponCreateOrUpdateEvent $event Event creation or update Coupon @@ -94,21 +124,13 @@ class Coupon extends BaseAction implements EventSubscriberInterface $totalDiscount = 0; $isValid = false; - /** @var CouponFactory $couponFactory */ - $couponFactory = $this->container->get('thelia.coupon.factory'); - - /** @var CouponManager $couponManager */ - $couponManager = $this->container->get('thelia.coupon.manager'); - /** @var CouponInterface $coupon */ - $coupon = $couponFactory->buildCouponFromCode($event->getCode()); + $coupon = $this->couponFactory->buildCouponFromCode($event->getCode()); if ($coupon) { $isValid = $coupon->isMatching(); if ($isValid) { - /** @var Request $request */ - $request = $this->container->get('request'); - $consumedCoupons = $request->getSession()->getConsumedCoupons(); + $consumedCoupons = $this->request->getSession()->getConsumedCoupons(); if (!isset($consumedCoupons) || !$consumedCoupons) { $consumedCoupons = array(); @@ -117,16 +139,16 @@ class Coupon extends BaseAction implements EventSubscriberInterface // Prevent accumulation of the same Coupon on a Checkout $consumedCoupons[$event->getCode()] = $event->getCode(); - $request->getSession()->setConsumedCoupons($consumedCoupons); + $this->request->getSession()->setConsumedCoupons($consumedCoupons); - $totalDiscount = $couponManager->getDiscount(); + $totalDiscount = $this->couponManager->getDiscount(); - $request + $this->request ->getSession() ->getCart() ->setDiscount($totalDiscount) ->save(); - $request + $this->request ->getSession() ->getOrder() ->setDiscount($totalDiscount) @@ -148,13 +170,13 @@ class Coupon extends BaseAction implements EventSubscriberInterface */ protected function createOrUpdate(CouponModel $coupon, CouponCreateOrUpdateEvent $event) { - $coupon->setDispatcher($this->getDispatcher()); + $coupon->setDispatcher($event->getDispatcher()); // Set default condition if none found /** @var ConditionInterface $noConditionRule */ - $noConditionRule = $this->container->get('thelia.condition.match_for_everyone'); + $noConditionRule = $this->getContainer()->get('thelia.condition.match_for_everyone'); /** @var ConditionFactory $conditionFactory */ - $conditionFactory = $this->container->get('thelia.condition.factory'); + $conditionFactory = $this->getContainer()->get('thelia.condition.factory'); $couponRuleCollection = new ConditionCollection(); $couponRuleCollection[] = $noConditionRule; $defaultSerializedRule = $conditionFactory->serializeConditionCollection( @@ -190,10 +212,10 @@ class Coupon extends BaseAction implements EventSubscriberInterface */ protected function createOrUpdateCondition(CouponModel $coupon, CouponCreateOrUpdateEvent $event) { - $coupon->setDispatcher($this->getDispatcher()); + $coupon->setDispatcher($event->getDispatcher()); /** @var ConditionFactory $conditionFactory */ - $conditionFactory = $this->container->get('thelia.condition.factory'); + $conditionFactory = $this->getContainer()->get('thelia.condition.factory'); $coupon->createOrUpdateConditions( $conditionFactory->serializeConditionCollection($event->getConditions()), @@ -208,10 +230,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface */ public function testFreePostage(OrderEvent $event) { - /** @var CouponManager $couponManager */ - $couponManager = $this->container->get('thelia.coupon.manager'); - - if ($couponManager->isCouponRemovingPostage()) { + if ($this->couponManager->isCouponRemovingPostage()) { $order = $event->getOrder(); $order->setPostage(0); @@ -227,21 +246,16 @@ class Coupon extends BaseAction implements EventSubscriberInterface */ public function afterOrder(OrderEvent $event) { - $request = $this->container->get('request'); - - /** @var CouponManager $couponManager */ - $couponManager = $this->container->get('thelia.coupon.manager'); - - $consumedCoupons = $request->getSession()->getConsumedCoupons(); + $consumedCoupons = $this->request->getSession()->getConsumedCoupons(); if (is_array($consumedCoupons)) { foreach ($consumedCoupons as $couponCode) { $couponQuery = CouponQuery::create(); $couponModel = $couponQuery->findOneByCode($couponCode); - $couponModel->setLocale($request->getSession()->getLang()->getLocale()); + $couponModel->setLocale($this->request->getSession()->getLang()->getLocale()); /* decrease coupon quantity */ - $couponManager->decrementQuantity($couponModel); + $this->couponManager->decrementQuantity($couponModel); /* memorize coupon */ $orderCoupon = new OrderCoupon(); @@ -264,7 +278,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface } } - $request->getSession()->setConsumedCoupons(array()); + $this->request->getSession()->setConsumedCoupons(array()); } /** diff --git a/core/lib/Thelia/Action/Currency.php b/core/lib/Thelia/Action/Currency.php index 92ce23f99..5e391c2bc 100644 --- a/core/lib/Thelia/Action/Currency.php +++ b/core/lib/Thelia/Action/Currency.php @@ -23,6 +23,7 @@ namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Model\CurrencyQuery; @@ -48,7 +49,7 @@ class Currency extends BaseAction implements EventSubscriberInterface $currency = new CurrencyModel(); $currency - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setName($event->getCurrencyName()) @@ -74,7 +75,7 @@ class Currency extends BaseAction implements EventSubscriberInterface if (null !== $currency = CurrencyQuery::create()->findPk($event->getCurrencyId())) { $currency - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setName($event->getCurrencyName()) @@ -104,7 +105,7 @@ class Currency extends BaseAction implements EventSubscriberInterface CurrencyQuery::create()->filterByByDefault(true)->update(array('ByDefault' => false)); $currency - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setByDefault($event->getIsDefault()) ->save() ; @@ -125,7 +126,7 @@ class Currency extends BaseAction implements EventSubscriberInterface if (null !== ($currency = CurrencyQuery::create()->findPk($event->getCurrencyId()))) { $currency - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; @@ -133,7 +134,7 @@ class Currency extends BaseAction implements EventSubscriberInterface } } - public function updateRates() + public function updateRates(EventDispatcherInterface $dispatcher) { $rates_url = ConfigQuery::read('currency_rate_update_url', 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml'); @@ -147,7 +148,7 @@ class Currency extends BaseAction implements EventSubscriberInterface if (null !== $currency = CurrencyQuery::create()->findOneByCode($code)) { $currency - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($dispatcher) ->setRate($rate) ->save() ; @@ -165,7 +166,7 @@ class Currency extends BaseAction implements EventSubscriberInterface */ public function updatePosition(UpdatePositionEvent $event) { - return $this->genericUpdatePosition(CurrencyQuery::create(), $event); + $this->genericUpdatePosition(CurrencyQuery::create(), $event); } /** diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php index 4fe5d0f72..1903cc45a 100644 --- a/core/lib/Thelia/Action/Customer.php +++ b/core/lib/Thelia/Action/Customer.php @@ -28,6 +28,7 @@ use Thelia\Core\Event\ActionEvent; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\Customer\CustomerEvent; use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\Security\SecurityContext; use Thelia\Model\Customer as CustomerModel; use Thelia\Core\Event\Customer\CustomerLoginEvent; @@ -41,6 +42,12 @@ use Thelia\Core\Event\Customer\CustomerLoginEvent; */ class Customer extends BaseAction implements EventSubscriberInterface { + protected $securityContext; + + public function __construct(SecurityContext $securityContext) + { + $this->securityContext = $securityContext; + } public function create(CustomerCreateOrUpdateEvent $event) { @@ -65,7 +72,7 @@ class Customer extends BaseAction implements EventSubscriberInterface $customer = $event->getCustomer(); - $customer->setDispatcher($this->getDispatcher()); + $customer->setDispatcher($event->getDispatcher()); $customer ->setTitleId($event->getTitle()) @@ -91,7 +98,7 @@ class Customer extends BaseAction implements EventSubscriberInterface private function createOrUpdateCustomer(CustomerModel $customer, CustomerCreateOrUpdateEvent $event) { - $customer->setDispatcher($this->getDispatcher()); + $customer->setDispatcher($event->getDispatcher()); $customer->createOrUpdate( $event->getTitle(), @@ -120,7 +127,7 @@ class Customer extends BaseAction implements EventSubscriberInterface public function login(CustomerLoginEvent $event) { - $this->getSecurityContext()->setCustomerUser($event->getCustomer()); + $this->securityContext->setCustomerUser($event->getCustomer()); } /** @@ -130,17 +137,7 @@ class Customer extends BaseAction implements EventSubscriberInterface */ public function logout(ActionEvent $event) { - $this->getSecurityContext()->clearCustomerUser(); - } - - /** - * Return the security context - * - * @return Thelia\Core\Security\SecurityContext - */ - protected function getSecurityContext() - { - return $this->container->get('thelia.securityContext'); + $this->securityContext->clearCustomerUser(); } /** diff --git a/core/lib/Thelia/Action/Document.php b/core/lib/Thelia/Action/Document.php index 35dc3e540..4605ee7c9 100644 --- a/core/lib/Thelia/Action/Document.php +++ b/core/lib/Thelia/Action/Document.php @@ -34,7 +34,6 @@ use Thelia\Model\ConfigQuery; use Thelia\Tools\FileManager; use Thelia\Tools\URL; -use Imagine\Document\Color; use Thelia\Exception\DocumentException; use Thelia\Core\Event\TheliaEvents; @@ -53,19 +52,6 @@ use Thelia\Core\Event\TheliaEvents; * A copy (or symbolic link, by default) of the original document is always created in the cache, so that the full * resolution document is always available. * - * Various document processing options are available : - * - * - resizing, with border, crop, or by keeping document aspect ratio - * - rotation, in degrees, positive or negative - * - background color, applyed to empty background when creating borders or rotating - * - effects. The effects are applied in the specified order. The following effects are available: - * - gamma:value : change the document Gamma to the specified value. Example: gamma:0.7 - * - grayscale or greyscale: switch document to grayscale - * - colorize:color : apply a color mask to the document. Exemple: colorize:#ff2244 - * - negative : transform the document in its negative equivalent - * - vflip or vertical_flip : vertical flip - * - hflip or horizontal_flip : horizontal flip - * * If a problem occurs, an DocumentException may be thrown. * * @package Thelia\Action @@ -144,7 +130,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface */ public function saveDocument(DocumentCreateOrUpdateEvent $event) { - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $model = $event->getModelDocument(); $nbModifiedLines = $model->save(); @@ -180,7 +166,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface $event->getModelDocument()->setTitle($event->getUploadedFile()->getClientOriginalName()); } - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); // Copy and save file if ($event->getUploadedFile()) { // Remove old picture file from file storage @@ -198,7 +184,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface public function updatePosition(UpdateFilePositionEvent $event) { - return $this->genericUpdatePosition($event->getQuery(), $event); + $this->genericUpdatePosition($event->getQuery(), $event); } /** @@ -211,7 +197,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface */ public function deleteDocument(DocumentDeleteEvent $event) { - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $fileManager->deleteFile($event->getDocumentToDelete(), $event->getDocumentType(), FileManager::FILE_TYPE_DOCUMENTS); } diff --git a/core/lib/Thelia/Action/Feature.php b/core/lib/Thelia/Action/Feature.php index e46239695..f2cda8e24 100644 --- a/core/lib/Thelia/Action/Feature.php +++ b/core/lib/Thelia/Action/Feature.php @@ -51,7 +51,7 @@ class Feature extends BaseAction implements EventSubscriberInterface $feature = new FeatureModel(); $feature - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) @@ -78,7 +78,7 @@ class Feature extends BaseAction implements EventSubscriberInterface if (null !== $feature = FeatureQuery::create()->findPk($event->getFeatureId())) { $feature - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) @@ -103,7 +103,7 @@ class Feature extends BaseAction implements EventSubscriberInterface if (null !== ($feature = FeatureQuery::create()->findPk($event->getFeatureId()))) { $feature - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; @@ -114,11 +114,11 @@ class Feature extends BaseAction implements EventSubscriberInterface /** * Changes position, selecting absolute ou relative change. * - * @param CategoryChangePositionEvent $event + * @param UpdatePositionEvent $event */ public function updatePosition(UpdatePositionEvent $event) { - return $this->genericUpdatePosition(FeatureQuery::create(), $event); + $this->genericUpdatePosition(FeatureQuery::create(), $event); } protected function doAddToAllTemplates(FeatureModel $feature) diff --git a/core/lib/Thelia/Action/FeatureAv.php b/core/lib/Thelia/Action/FeatureAv.php index b88c97324..9a97c871b 100644 --- a/core/lib/Thelia/Action/FeatureAv.php +++ b/core/lib/Thelia/Action/FeatureAv.php @@ -47,7 +47,7 @@ class FeatureAv extends BaseAction implements EventSubscriberInterface $feature = new FeatureAvModel(); $feature - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setFeatureId($event->getFeatureId()) ->setLocale($event->getLocale()) @@ -70,7 +70,7 @@ class FeatureAv extends BaseAction implements EventSubscriberInterface if (null !== $feature = FeatureAvQuery::create()->findPk($event->getFeatureAvId())) { $feature - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) @@ -95,7 +95,7 @@ class FeatureAv extends BaseAction implements EventSubscriberInterface if (null !== ($feature = FeatureAvQuery::create()->findPk($event->getFeatureAvId()))) { $feature - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; @@ -106,11 +106,11 @@ class FeatureAv extends BaseAction implements EventSubscriberInterface /** * Changes position, selecting absolute ou relative change. * - * @param CategoryChangePositionEvent $event + * @param UpdatePositionEvent $event */ public function updatePosition(UpdatePositionEvent $event) { - return $this->genericUpdatePosition(FeatureAvQuery::create(), $event); + $this->genericUpdatePosition(FeatureAvQuery::create(), $event); } /** diff --git a/core/lib/Thelia/Action/Folder.php b/core/lib/Thelia/Action/Folder.php index 2eece4095..7483c08b6 100644 --- a/core/lib/Thelia/Action/Folder.php +++ b/core/lib/Thelia/Action/Folder.php @@ -44,7 +44,7 @@ class Folder extends BaseAction implements EventSubscriberInterface { if (null !== $folder = FolderQuery::create()->findPk($event->getFolderId())) { - $folder->setDispatcher($this->getDispatcher()); + $folder->setDispatcher($event->getDispatcher()); $folder ->setParent($event->getParent()) @@ -76,7 +76,7 @@ class Folder extends BaseAction implements EventSubscriberInterface public function delete(FolderDeleteEvent $event) { if (null !== $folder = FolderQuery::create()->findPk($event->getFolderId())) { - $folder->setDispatcher($this->getDispatcher()) + $folder->setDispatcher($event->getDispatcher()) ->delete(); $event->setFolder($folder); @@ -89,7 +89,7 @@ class Folder extends BaseAction implements EventSubscriberInterface public function create(FolderCreateEvent $event) { $folder = new FolderModel(); - $folder->setDispatcher($this->getDispatcher()); + $folder->setDispatcher($event->getDispatcher()); $folder ->setParent($event->getParent()) @@ -106,7 +106,7 @@ class Folder extends BaseAction implements EventSubscriberInterface $folder = $event->getFolder(); $folder - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setVisible(!$folder->getVisible()) ->save(); @@ -117,7 +117,7 @@ class Folder extends BaseAction implements EventSubscriberInterface public function updatePosition(UpdatePositionEvent $event) { if (null !== $folder = FolderQuery::create()->findPk($event->getObjectId())) { - $folder->setDispatcher($this->getDispatcher()); + $folder->setDispatcher($event->getDispatcher()); switch ($event->getMode()) { case UpdatePositionEvent::POSITION_ABSOLUTE: diff --git a/core/lib/Thelia/Action/HttpException.php b/core/lib/Thelia/Action/HttpException.php index b875eb49b..ad1df93ab 100644 --- a/core/lib/Thelia/Action/HttpException.php +++ b/core/lib/Thelia/Action/HttpException.php @@ -29,6 +29,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\KernelEvents; +use Thelia\Core\Template\ParserInterface; use Thelia\Model\ConfigQuery; use Thelia\Core\Template\TemplateHelper; @@ -40,6 +41,16 @@ use Thelia\Core\Template\TemplateHelper; */ class HttpException extends BaseAction implements EventSubscriberInterface { + /** + * @var ParserInterface + */ + protected $parser; + + public function __construct(ParserInterface $parser) + { + $this->parser = $parser; + } + public function checkHttpException(GetResponseForExceptionEvent $event) { if ($event->getException() instanceof NotFoundHttpException) { @@ -53,14 +64,12 @@ class HttpException extends BaseAction implements EventSubscriberInterface protected function display404(GetResponseForExceptionEvent $event) { - $parser = $this->container->get("thelia.parser"); - // Define the template thant shoud be used - $parser->setTemplateDefinition(TemplateHelper::getInstance()->getActiveFrontTemplate()); + $this->parser->setTemplateDefinition(TemplateHelper::getInstance()->getActiveFrontTemplate()); //$event->getRequest()->attributes->set('_view', ConfigQuery::getPageNotFoundView()); - $response = new Response($parser->render(ConfigQuery::getPageNotFoundView()), 404); + $response = new Response($this->parser->render(ConfigQuery::getPageNotFoundView()), 404); $event->setResponse($response); } diff --git a/core/lib/Thelia/Action/Image.php b/core/lib/Thelia/Action/Image.php index e5beb2823..7b5ef0138 100644 --- a/core/lib/Thelia/Action/Image.php +++ b/core/lib/Thelia/Action/Image.php @@ -255,7 +255,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface */ public function saveImage(ImageCreateOrUpdateEvent $event) { - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $model = $event->getModelImage(); $nbModifiedLines = $model->save(); @@ -286,7 +286,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface */ public function updateImage(ImageCreateOrUpdateEvent $event) { - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); // Copy and save file if ($event->getUploadedFile()) { // Remove old picture file from file storage @@ -304,7 +304,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface public function updatePosition(UpdateFilePositionEvent $event) { - return $this->genericUpdatePosition($event->getQuery(), $event); + $this->genericUpdatePosition($event->getQuery(), $event); } /** @@ -317,7 +317,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface */ public function deleteImage(ImageDeleteEvent $event) { - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $fileManager->deleteFile($event->getImageToDelete(), $event->getImageType(), FileManager::FILE_TYPE_IMAGES); } @@ -416,7 +416,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface /** * Create a new Imagine object using current driver configuration * - * @return \Imagine\ImagineInterface + * @return ImagineInterface */ protected function createImagineInstance() { diff --git a/core/lib/Thelia/Action/Lang.php b/core/lib/Thelia/Action/Lang.php index 3acb62b29..20fde397a 100644 --- a/core/lib/Thelia/Action/Lang.php +++ b/core/lib/Thelia/Action/Lang.php @@ -45,7 +45,7 @@ class Lang extends BaseAction implements EventSubscriberInterface public function update(LangUpdateEvent $event) { if (null !== $lang = LangQuery::create()->findPk($event->getId())) { - $lang->setDispatcher($this->getDispatcher()); + $lang->setDispatcher($event->getDispatcher()); $lang->setTitle($event->getTitle()) ->setLocale($event->getLocale()) @@ -61,7 +61,7 @@ class Lang extends BaseAction implements EventSubscriberInterface public function toggleDefault(LangToggleDefaultEvent $event) { if (null !== $lang = LangQuery::create()->findPk($event->getLangId())) { - $lang->setDispatcher($this->getDispatcher()); + $lang->setDispatcher($event->getDispatcher()); $lang->toggleDefault(); @@ -74,7 +74,7 @@ class Lang extends BaseAction implements EventSubscriberInterface $lang = new LangModel(); $lang - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setTitle($event->getTitle()) ->setCode($event->getCode()) ->setLocale($event->getLocale()) @@ -88,7 +88,7 @@ class Lang extends BaseAction implements EventSubscriberInterface public function delete(LangDeleteEvent $event) { if (null !== $lang = LangQuery::create()->findPk($event->getLangId())) { - $lang->setDispatcher($this->getDispatcher()) + $lang->setDispatcher($event->getDispatcher()) ->delete(); $event->setLang($lang); diff --git a/core/lib/Thelia/Action/Message.php b/core/lib/Thelia/Action/Message.php index 045769e58..de9de9cbb 100644 --- a/core/lib/Thelia/Action/Message.php +++ b/core/lib/Thelia/Action/Message.php @@ -46,7 +46,7 @@ class Message extends BaseAction implements EventSubscriberInterface $message = new MessageModel(); $message - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setName($event->getMessageName()) @@ -72,7 +72,7 @@ class Message extends BaseAction implements EventSubscriberInterface if (null !== $message = MessageQuery::create()->findPk($event->getMessageId())) { $message - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setName($event->getMessageName()) ->setSecured($event->getSecured()) @@ -107,7 +107,7 @@ class Message extends BaseAction implements EventSubscriberInterface if (null !== ($message = MessageQuery::create()->findPk($event->getMessageId()))) { $message - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 5ce36c459..249aab3b2 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -23,19 +23,23 @@ namespace Thelia\Action; use Propel\Runtime\Propel; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Filesystem\Filesystem; use Thelia\Core\Event\Cache\CacheEvent; use Thelia\Core\Event\Module\ModuleDeleteEvent; use Thelia\Core\Event\Module\ModuleEvent; use Thelia\Core\Event\Module\ModuleToggleActivationEvent; +use Thelia\Core\Event\Order\OrderPaymentEvent; + use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\Event\UpdatePositionEvent; +use Thelia\Core\Translation\Translator; +use Thelia\Log\Tlog; use Thelia\Model\Map\ModuleTableMap; use Thelia\Model\ModuleQuery; use Thelia\Module\BaseModule; -use Thelia\Core\Event\UpdatePositionEvent; -use Thelia\Log\Tlog; -use Thelia\Core\Translation\Translator; /** * Class Module @@ -44,6 +48,15 @@ use Thelia\Core\Translation\Translator; */ class Module extends BaseAction implements EventSubscriberInterface { + /** + * @var ContainerInterface + */ + protected $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } public function toggleActivation(ModuleToggleActivationEvent $event) { @@ -63,7 +76,7 @@ class Module extends BaseAction implements EventSubscriberInterface $event->setModule($module); - $this->cacheClear(); + $this->cacheClear($event->getDispatcher()); } } @@ -108,7 +121,7 @@ class Module extends BaseAction implements EventSubscriberInterface $con->commit(); $event->setModule($module); - $this->cacheClear(); + $this->cacheClear($event->getDispatcher()); } catch (\Exception $e) { $con->rollBack(); @@ -125,7 +138,7 @@ class Module extends BaseAction implements EventSubscriberInterface if (null !== $module = ModuleQuery::create()->findPk($event->getId())) { $module - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) ->setChapo($event->getChapo()) @@ -139,21 +152,50 @@ class Module extends BaseAction implements EventSubscriberInterface } } + /** + * Call the payment method of the payment module of the given order + * + * @param OrderPaymentEvent $event + * @throws \RuntimeException if no payment module can be found. + */ + public function pay(OrderPaymentEvent $event) { + + $order = $event->getOrder(); + + /* call pay method */ + if (null === $paymentModule = ModuleQuery::create()->findPk($order->getPaymentModuleId())) { + throw new \RuntimeException( + Translator::getInstance()->trans( + "Failed to find a payment Module with ID=%mid for order ID=%oid", + array( + "%mid" => $order->getPaymentModuleId(), + "%oid" => $order->getId() + )) + ); + } + + $paymentModuleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode())); + + $paymentModuleInstance->pay($order); + } + /** * Changes position, selecting absolute ou relative change. * - * @param CategoryChangePositionEvent $event + * @param UpdatePositionEvent $event */ public function updatePosition(UpdatePositionEvent $event) { - return $this->genericUpdatePosition(ModuleQuery::create(), $event); + $this->genericUpdatePosition(ModuleQuery::create(), $event); } - protected function cacheClear() + protected function cacheClear(EventDispatcherInterface $dispatcher) { - $cacheEvent = new CacheEvent($this->container->getParameter('kernel.cache_dir')); + $cacheEvent = new CacheEvent( + $this->container->getParameter('kernel.cache_dir') + ); - $this->getDispatcher()->dispatch(TheliaEvents::CACHE_CLEAR, $cacheEvent); + $dispatcher->dispatch(TheliaEvents::CACHE_CLEAR, $cacheEvent); } /** @@ -183,6 +225,7 @@ class Module extends BaseAction implements EventSubscriberInterface TheliaEvents::MODULE_UPDATE_POSITION => array('updatePosition', 128), TheliaEvents::MODULE_DELETE => array('delete', 128), TheliaEvents::MODULE_UPDATE => array('update', 128), + TheliaEvents::MODULE_PAY => array('pay', 128), ); } } diff --git a/core/lib/Thelia/Action/Newsletter.php b/core/lib/Thelia/Action/Newsletter.php index aeb26f3d6..4130dd00b 100644 --- a/core/lib/Thelia/Action/Newsletter.php +++ b/core/lib/Thelia/Action/Newsletter.php @@ -25,7 +25,7 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Newsletter\NewsletterEvent; use Thelia\Core\Event\TheliaEvents; -use Thelia\Action\BaseAction; + use Thelia\Model\NewsletterQuery; use Thelia\Model\Newsletter as NewsletterModel; diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index 69d8645ac..c04c61366 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -23,14 +23,20 @@ namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Cart\CartTrait; use Thelia\Core\Event\Cart\CartEvent; use Thelia\Core\Event\Order\OrderAddressEvent; use Thelia\Core\Event\Order\OrderEvent; use Thelia\Core\Event\Order\OrderManualEvent; +use Thelia\Core\Event\Order\OrderPaymentEvent; use Thelia\Core\Event\TheliaEvents; +use Thelia\Core\HttpFoundation\Request; +use Thelia\Core\Security\SecurityContext; +use Thelia\Core\Template\ParserInterface; use Thelia\Exception\TheliaProcessException; +use Thelia\Mailer\MailerFactory; use Thelia\Model\AddressQuery; use Thelia\Model\Cart as CartModel; use Thelia\Model\ConfigQuery; @@ -39,7 +45,6 @@ use Thelia\Model\Customer as CustomerModel; use Thelia\Model\Lang; use Thelia\Model\Map\OrderTableMap; use Thelia\Model\MessageQuery; -use Thelia\Model\ModuleQuery; use Thelia\Model\Order as ModelOrder; use Thelia\Model\OrderAddress; use Thelia\Model\OrderProduct; @@ -47,6 +52,8 @@ use Thelia\Model\OrderProductAttributeCombination; use Thelia\Model\OrderStatus; use Thelia\Model\OrderStatusQuery; use Thelia\Tools\I18n; +use Thelia\Model\Country; + /** * @@ -58,6 +65,31 @@ class Order extends BaseAction implements EventSubscriberInterface { use CartTrait; + /** + * @var \Thelia\Core\HttpFoundation\Request + */ + protected $request; + /** + * @var MailerFactory + */ + protected $mailer; + /** + * @var ParserInterface + */ + protected $parser; + /** + * @var SecurityContext + */ + protected $securityContext; + + public function __construct(Request $request, ParserInterface $parser, MailerFactory $mailer, SecurityContext $securityContext) + { + $this->request = $request; + $this->parser = $parser; + $this->mailer = $mailer; + $this->securityContext = $securityContext; + } + /** * @param \Thelia\Core\Event\Order\OrderEvent $event */ @@ -118,7 +150,7 @@ class Order extends BaseAction implements EventSubscriberInterface $event->setOrder($order); } - protected function createOrder(ModelOrder $sessionOrder, Currency $currency, Lang $lang, CartModel $cart, CustomerModel $customer) + protected function createOrder(EventDispatcherInterface $dispatcher, ModelOrder $sessionOrder, Currency $currency, Lang $lang, CartModel $cart, CustomerModel $customer) { $con = \Propel\Runtime\Propel::getConnection( OrderTableMap::DATABASE_NAME @@ -126,9 +158,9 @@ class Order extends BaseAction implements EventSubscriberInterface $con->beginTransaction(); - /* use a copy to avoid errored record in session */ + $placedOrder = $sessionOrder->copy(); - $placedOrder->setDispatcher($this->getDispatcher()); + $placedOrder->setDispatcher($dispatcher); $deliveryAddress = AddressQuery::create()->findPk($sessionOrder->chosenDeliveryAddress); $taxCountry = $deliveryAddress->getCountry(); @@ -238,7 +270,7 @@ class Order extends BaseAction implements EventSubscriberInterface ->setTaxRuleTitle($taxRuleI18n->getTitle()) ->setTaxRuleDescription($taxRuleI18n->getDescription()) ->setEanCode($pse->getEanCode()) - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($dispatcher) ->save($con) ; @@ -279,6 +311,7 @@ class Order extends BaseAction implements EventSubscriberInterface public function createManual(OrderManualEvent $event) { $placedOrder = $this->createOrder( + $event->getDispatcher(), $event->getOrder(), $event->getCurrency(), $event->getLang(), @@ -297,14 +330,15 @@ class Order extends BaseAction implements EventSubscriberInterface $session = $this->getSession(); $placedOrder = $this->createOrder( + $event->getDispatcher(), $event->getOrder(), $session->getCurrency(), $session->getLang(), $session->getCart(), - $this->getSecurityContext()->getCustomerUser() + $this->securityContext->getCustomerUser() ); - $this->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder)); + $event->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder)); /* clear session */ @@ -318,14 +352,16 @@ class Order extends BaseAction implements EventSubscriberInterface $event->setPlacedOrder($placedOrder); /* empty cart */ - $this->getDispatcher()->dispatch(TheliaEvents::CART_CLEAR, new CartEvent($this->getCart($this->getRequest()))); + $dispatcher = $event->getDispatcher(); + + $dispatcher->dispatch( + TheliaEvents::CART_CLEAR, new CartEvent($this->getCart($dispatcher, $this->request))); + /* call pay method */ + $payEvent = new OrderPaymentEvent($placedOrder); - $paymentModule = ModuleQuery::create()->findPk($placedOrder->getPaymentModuleId()); - - $paymentModuleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode())); - $paymentModuleInstance->pay($placedOrder); + $dispatcher->dispatch(TheliaEvents::MODULE_PAY, $payEvent); } /** @@ -333,7 +369,7 @@ class Order extends BaseAction implements EventSubscriberInterface */ public function sendOrderEmail(OrderEvent $event) { - $contact_email = ConfigQuery::read('contact_email'); + $contact_email = ConfigQuery::read('store_email'); if ($contact_email) { @@ -348,21 +384,20 @@ class Order extends BaseAction implements EventSubscriberInterface $order = $event->getOrder(); $customer = $order->getCustomer(); - $parser = $this->container->get("thelia.parser"); - - $parser->assign('order_id', $order->getId()); - $parser->assign('order_ref', $order->getRef()); + $this->parser->assign('order_id', $order->getId()); + $this->parser->assign('order_ref', $order->getRef()); $message ->setLocale($order->getLang()->getLocale()); $instance = \Swift_Message::newInstance() ->addTo($customer->getEmail(), $customer->getFirstname()." ".$customer->getLastname()) - ->addFrom(ConfigQuery::read('contact_email'), ConfigQuery::read('company_name')) + ->addFrom($contact_email, ConfigQuery::read('store_name')) ; // Build subject and body - $message->build($parser, $instance); + + $message->buildMessage($this->parser, $instance); $this->getMailer()->send($instance); } @@ -376,9 +411,7 @@ class Order extends BaseAction implements EventSubscriberInterface */ public function getMailer() { - $mailer = $this->container->get('mailer'); - - return $mailer->getSwiftMailer(); + return $this->mailer->getSwiftMailer(); } /** @@ -469,24 +502,6 @@ class Order extends BaseAction implements EventSubscriberInterface ); } - /** - * Return the security context - * - * @return SecurityContext - */ - protected function getSecurityContext() - { - return $this->container->get('thelia.securityContext'); - } - - /** - * @return \Symfony\Component\HttpFoundation\Request - */ - protected function getRequest() - { - return $this->container->get('request'); - } - /** * Returns the session from the current request * @@ -494,8 +509,6 @@ class Order extends BaseAction implements EventSubscriberInterface */ protected function getSession() { - $request = $this->getRequest(); - - return $request->getSession(); + return $this->request->getSession(); } -} \ No newline at end of file +} diff --git a/core/lib/Thelia/Action/Product.php b/core/lib/Thelia/Action/Product.php index a2c24a163..dd01265e9 100644 --- a/core/lib/Thelia/Action/Product.php +++ b/core/lib/Thelia/Action/Product.php @@ -70,7 +70,7 @@ class Product extends BaseAction implements EventSubscriberInterface $product = new ProductModel(); $product - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setRef($event->getRef()) ->setTitle($event->getTitle()) @@ -102,7 +102,7 @@ class Product extends BaseAction implements EventSubscriberInterface if (null !== $product = ProductQuery::create()->findPk($event->getProductId())) { $product - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) @@ -141,7 +141,7 @@ class Product extends BaseAction implements EventSubscriberInterface if (null !== $product = ProductQuery::create()->findPk($event->getProductId())) { $product - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; @@ -159,7 +159,7 @@ class Product extends BaseAction implements EventSubscriberInterface $product = $event->getProduct(); $product - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setVisible($product->getVisible() ? false : true) ->save() ; @@ -172,7 +172,7 @@ class Product extends BaseAction implements EventSubscriberInterface */ public function updatePosition(UpdatePositionEvent $event) { - return $this->genericUpdatePosition(ProductQuery::create(), $event); + $this->genericUpdatePosition(ProductQuery::create(), $event); } public function addContent(ProductAddContentEvent $event) @@ -184,7 +184,7 @@ class Product extends BaseAction implements EventSubscriberInterface $content = new ProductAssociatedContent(); $content - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setProduct($event->getProduct()) ->setContentId($event->getContentId()) ->save() @@ -201,7 +201,7 @@ class Product extends BaseAction implements EventSubscriberInterface if ($content !== null) $content - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; } @@ -243,7 +243,7 @@ class Product extends BaseAction implements EventSubscriberInterface $accessory = new Accessory(); $accessory - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setProductId($event->getProduct()->getId()) ->setAccessory($event->getAccessoryId()) ->save() @@ -260,7 +260,7 @@ class Product extends BaseAction implements EventSubscriberInterface if ($accessory !== null) $accessory - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; } @@ -353,7 +353,7 @@ class Product extends BaseAction implements EventSubscriberInterface $featureProduct = new FeatureProduct(); $featureProduct - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setProductId($event->getProductId()) ->setFeatureId($event->getFeatureId()) diff --git a/core/lib/Thelia/Action/ProductSaleElement.php b/core/lib/Thelia/Action/ProductSaleElement.php index bfe2d5bb1..56d033419 100644 --- a/core/lib/Thelia/Action/ProductSaleElement.php +++ b/core/lib/Thelia/Action/ProductSaleElement.php @@ -37,7 +37,7 @@ use Thelia\Core\Event\ProductSaleElement\ProductSaleElementUpdateEvent; use Thelia\Model\ProductPriceQuery; use Propel\Runtime\Propel; use Thelia\Model\AttributeAvQuery; -use Thelia\Model\Currency; + use Thelia\Model\Map\AttributeCombinationTableMap; use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Core\Event\Product\ProductCombinationGenerationEvent; diff --git a/core/lib/Thelia/Action/Profile.php b/core/lib/Thelia/Action/Profile.php index a35a0d250..c264b1439 100644 --- a/core/lib/Thelia/Action/Profile.php +++ b/core/lib/Thelia/Action/Profile.php @@ -46,7 +46,7 @@ class Profile extends BaseAction implements EventSubscriberInterface $profile = new ProfileModel(); $profile - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setCode($event->getCode()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) @@ -68,7 +68,7 @@ class Profile extends BaseAction implements EventSubscriberInterface if (null !== $profile = ProfileQuery::create()->findPk($event->getId())) { $profile - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) ->setChapo($event->getChapo()) diff --git a/core/lib/Thelia/Action/Tax.php b/core/lib/Thelia/Action/Tax.php index 5189bf9db..87c78fe6e 100644 --- a/core/lib/Thelia/Action/Tax.php +++ b/core/lib/Thelia/Action/Tax.php @@ -39,7 +39,7 @@ class Tax extends BaseAction implements EventSubscriberInterface $tax = new TaxModel(); $tax - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setRequirements($event->getRequirements()) ->setType($event->getType()) ->setLocale($event->getLocale()) @@ -60,7 +60,7 @@ class Tax extends BaseAction implements EventSubscriberInterface if (null !== $tax = TaxQuery::create()->findPk($event->getId())) { $tax - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setRequirements($event->getRequirements()) ->setType($event->getType()) ->setLocale($event->getLocale()) diff --git a/core/lib/Thelia/Action/TaxRule.php b/core/lib/Thelia/Action/TaxRule.php index a5368a400..992a8d1a1 100644 --- a/core/lib/Thelia/Action/TaxRule.php +++ b/core/lib/Thelia/Action/TaxRule.php @@ -42,7 +42,7 @@ class TaxRule extends BaseAction implements EventSubscriberInterface $taxRule = new TaxRuleModel(); $taxRule - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) ->setDescription($event->getDescription()) @@ -61,7 +61,7 @@ class TaxRule extends BaseAction implements EventSubscriberInterface if (null !== $taxRule = TaxRuleQuery::create()->findPk($event->getId())) { $taxRule - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) ->setDescription($event->getDescription()) diff --git a/core/lib/Thelia/Action/Template.php b/core/lib/Thelia/Action/Template.php index cce146ec3..16493e94c 100644 --- a/core/lib/Thelia/Action/Template.php +++ b/core/lib/Thelia/Action/Template.php @@ -56,7 +56,7 @@ class Template extends BaseAction implements EventSubscriberInterface $template = new TemplateModel(); $template - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setName($event->getTemplateName()) @@ -78,7 +78,7 @@ class Template extends BaseAction implements EventSubscriberInterface if (null !== $template = TemplateQuery::create()->findPk($event->getTemplateId())) { $template - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->setLocale($event->getLocale()) ->setName($event->getTemplateName()) @@ -102,7 +102,7 @@ class Template extends BaseAction implements EventSubscriberInterface if ($product_count <= 0) { $template - ->setDispatcher($this->getDispatcher()) + ->setDispatcher($event->getDispatcher()) ->delete() ; } diff --git a/core/lib/Thelia/Cart/CartTrait.php b/core/lib/Thelia/Cart/CartTrait.php index 116a26da9..e7c946a67 100644 --- a/core/lib/Thelia/Cart/CartTrait.php +++ b/core/lib/Thelia/Cart/CartTrait.php @@ -22,6 +22,7 @@ /*************************************************************************************/ namespace Thelia\Cart; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Thelia\Model\CartQuery; use Thelia\Model\Cart as CartModel; use Thelia\Model\ConfigQuery; @@ -44,10 +45,11 @@ trait CartTrait * * search if cart already exists in session. If not try to create a new one or duplicate an old one. * + * @param EventDispatcherInterface $dispatcher the event dispatcher * @param \Symfony\Component\HttpFoundation\Request $request * @return \Thelia\Model\Cart */ - public function getCart(Request $request) + public function getCart(EventDispatcherInterface $dispatcher, Request $request) { $session = $request->getSession(); @@ -68,12 +70,12 @@ trait CartTrait if ($customer) { if ($cart->getCustomerId() != $customer->getId()) { //le customer du panier n'est pas le mm que celui connecté, il faut cloner le panier sans le customer_id - $cart = $this->duplicateCart($cart, $session, $customer); + $cart = $this->duplicateCart($dispatcher, $cart, $session, $customer); } } else { if ($cart->getCustomerId() != null) { //il faut dupliquer le panier sans le customer_id - $cart = $this->duplicateCart($cart, $session); + $cart = $this->duplicateCart($dispatcher, $cart, $session); } } @@ -116,13 +118,14 @@ trait CartTrait * @param \Thelia\Model\Customer $customer * @return \Thelia\Model\Cart */ - protected function duplicateCart(CartModel $cart, Session $session, Customer $customer = null) + protected function duplicateCart(EventDispatcherInterface $dispatcher, CartModel $cart, Session $session, Customer $customer = null) { $newCart = $cart->duplicate($this->generateCookie(), $customer); $session->setCart($newCart->getId()); $cartEvent = new CartEvent($newCart); - $this->getDispatcher()->dispatch(TheliaEvents::CART_DUPLICATE, $cartEvent); + + $dispatcher->dispatch(TheliaEvents::CART_DUPLICATE, $cartEvent); return $cartEvent->getCart(); } @@ -139,6 +142,4 @@ trait CartTrait return $id; } - - abstract public function getDispatcher(); } diff --git a/core/lib/Thelia/Command/CacheClear.php b/core/lib/Thelia/Command/CacheClear.php index 3b56cbf00..a2cd7ee2f 100644 --- a/core/lib/Thelia/Command/CacheClear.php +++ b/core/lib/Thelia/Command/CacheClear.php @@ -26,10 +26,10 @@ namespace Thelia\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Filesystem\Filesystem; + use Symfony\Component\Filesystem\Exception\IOException; -use Thelia\Command\ContainerAwareCommand; + use Thelia\Core\Event\Cache\CacheEvent; use Thelia\Core\Event\TheliaEvents; diff --git a/core/lib/Thelia/Command/ClearImageCache.php b/core/lib/Thelia/Command/ClearImageCache.php index 8401e47f3..053533469 100644 --- a/core/lib/Thelia/Command/ClearImageCache.php +++ b/core/lib/Thelia/Command/ClearImageCache.php @@ -23,7 +23,7 @@ namespace Thelia\Command; -use Thelia\Command\ContainerAwareCommand; + use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/core/lib/Thelia/Command/CreateAdminUser.php b/core/lib/Thelia/Command/CreateAdminUser.php index bbc4f9ad0..f935221dc 100644 --- a/core/lib/Thelia/Command/CreateAdminUser.php +++ b/core/lib/Thelia/Command/CreateAdminUser.php @@ -27,7 +27,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Thelia\Command\ContainerAwareCommand; + use Thelia\Model\Admin; class CreateAdminUser extends ContainerAwareCommand diff --git a/core/lib/Thelia/Command/GenerateResources.php b/core/lib/Thelia/Command/GenerateResources.php index 124648b2a..3db889ddb 100644 --- a/core/lib/Thelia/Command/GenerateResources.php +++ b/core/lib/Thelia/Command/GenerateResources.php @@ -27,9 +27,9 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Thelia\Command\ContainerAwareCommand; + use Thelia\Core\Security\Resource\AdminResources; -use Thelia\Model\Admin; + use Thelia\Model\Map\ResourceI18nTableMap; use Thelia\Model\Map\ResourceTableMap; diff --git a/core/lib/Thelia/Command/Install.php b/core/lib/Thelia/Command/Install.php index 4cff782ad..fd6237d8e 100644 --- a/core/lib/Thelia/Command/Install.php +++ b/core/lib/Thelia/Command/Install.php @@ -27,7 +27,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; -use Thelia\Command\ContainerAwareCommand; + use Thelia\Install\CheckPermission; use Thelia\Install\Database; diff --git a/core/lib/Thelia/Command/ModuleGenerateCommand.php b/core/lib/Thelia/Command/ModuleGenerateCommand.php index c6d8bf13f..8a610b991 100644 --- a/core/lib/Thelia/Command/ModuleGenerateCommand.php +++ b/core/lib/Thelia/Command/ModuleGenerateCommand.php @@ -97,7 +97,7 @@ class ModuleGenerateCommand extends BaseModuleGenerate file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "module.xml", $moduleContent); - $classContent = file_get_contents($skeletonDir . "Class.php"); + $classContent = file_get_contents($skeletonDir . "Class.php.template"); $classContent = str_replace("%%CLASSNAME%%", $this->module, $classContent); $classContent = str_replace("%%NAMESPACE%%", $this->module, $classContent); diff --git a/core/lib/Thelia/Command/ReloadDatabaseCommand.php b/core/lib/Thelia/Command/ReloadDatabaseCommand.php index 20aad0265..0bd76c9e5 100644 --- a/core/lib/Thelia/Command/ReloadDatabaseCommand.php +++ b/core/lib/Thelia/Command/ReloadDatabaseCommand.php @@ -24,7 +24,7 @@ namespace Thelia\Command; use Propel\Runtime\Propel; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; + use Symfony\Component\Console\Output\OutputInterface; use Thelia\Install\Database; diff --git a/core/lib/Thelia/Command/Skeleton/Module/Class.php b/core/lib/Thelia/Command/Skeleton/Module/Class.php.template similarity index 98% rename from core/lib/Thelia/Command/Skeleton/Module/Class.php rename to core/lib/Thelia/Command/Skeleton/Module/Class.php.template index 41fcfadbb..0b221bd8c 100644 --- a/core/lib/Thelia/Command/Skeleton/Module/Class.php +++ b/core/lib/Thelia/Command/Skeleton/Module/Class.php.template @@ -23,7 +23,6 @@ namespace %%NAMESPACE%%; -use Thelia\Module\BaseModule; class %%CLASSNAME%% extends BaseModule { diff --git a/core/lib/Thelia/Condition/ConditionEvaluator.php b/core/lib/Thelia/Condition/ConditionEvaluator.php index dd606fcd0..a08ab912a 100644 --- a/core/lib/Thelia/Condition/ConditionEvaluator.php +++ b/core/lib/Thelia/Condition/ConditionEvaluator.php @@ -24,8 +24,7 @@ namespace Thelia\Condition; use Thelia\Condition\Implementation\ConditionInterface; -use Thelia\Condition\Operators; -use Thelia\Condition\ConditionCollection; + /** * Validate Conditions diff --git a/core/lib/Thelia/Condition/ConditionFactory.php b/core/lib/Thelia/Condition/ConditionFactory.php index 72079fcc7..9d388a33e 100644 --- a/core/lib/Thelia/Condition/ConditionFactory.php +++ b/core/lib/Thelia/Condition/ConditionFactory.php @@ -26,7 +26,7 @@ namespace Thelia\Condition; use Symfony\Component\DependencyInjection\ContainerInterface; use Thelia\Condition\Implementation\ConditionInterface; use Thelia\Coupon\FacadeInterface; -use Thelia\Condition\ConditionCollection; + /** * Manage how Condition could interact with the current application state (Thelia) diff --git a/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php b/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php index 48ec8ed1e..9b5b218f2 100644 --- a/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php +++ b/core/lib/Thelia/Condition/Implementation/ConditionAbstract.php @@ -23,7 +23,7 @@ namespace Thelia\Condition\Implementation; -use Symfony\Component\Intl\Exception\NotImplementedException; + use Thelia\Condition\ConditionEvaluator; use Thelia\Condition\Operators; use Thelia\Condition\SerializableCondition; diff --git a/core/lib/Thelia/Condition/Implementation/MatchForEveryone.php b/core/lib/Thelia/Condition/Implementation/MatchForEveryone.php index 48b7c250b..74570cc41 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForEveryone.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForEveryone.php @@ -24,7 +24,7 @@ namespace Thelia\Condition\Implementation; use InvalidArgumentException; -use Thelia\Condition\Implementation\ConditionAbstract; + /** * Allow every one, perform no check diff --git a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php index 7cbdd32df..ec42d5d86 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmount.php @@ -23,7 +23,7 @@ namespace Thelia\Condition\Implementation; -use Thelia\Condition\Implementation\ConditionAbstract; + use Thelia\Condition\Operators; use Thelia\Exception\InvalidConditionOperatorException; use Thelia\Model\Currency; diff --git a/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php b/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php index f1123b57b..ab0fe481a 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForXArticles.php @@ -24,7 +24,7 @@ namespace Thelia\Condition\Implementation; use InvalidArgumentException; -use Thelia\Condition\Implementation\ConditionAbstract; + use Thelia\Condition\Operators; use Thelia\Exception\InvalidConditionOperatorException; use Thelia\Exception\InvalidConditionValueException; diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index d8252f11b..717c96975 100644 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -6,172 +6,153 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - diff --git a/core/lib/Thelia/Controller/Admin/AttributeController.php b/core/lib/Thelia/Controller/Admin/AttributeController.php index 52b70f0a2..75da59ec3 100644 --- a/core/lib/Thelia/Controller/Admin/AttributeController.php +++ b/core/lib/Thelia/Controller/Admin/AttributeController.php @@ -33,7 +33,7 @@ use Thelia\Model\AttributeQuery; use Thelia\Form\AttributeModificationForm; use Thelia\Form\AttributeCreationForm; use Thelia\Core\Event\UpdatePositionEvent; -use Thelia\Model\AttributeAv; + use Thelia\Core\Event\Attribute\AttributeAvUpdateEvent; use Thelia\Core\Event\Attribute\AttributeEvent; diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index 830d7bd3f..43d3bbdc9 100644 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -34,7 +34,7 @@ use Thelia\Core\Security\Exception\AuthenticationException; use Thelia\Tools\URL; use Thelia\Tools\Redirect; use Thelia\Model\AdminLog; -use Thelia\Model\Lang; + use Thelia\Model\LangQuery; use Thelia\Form\BaseForm; use Thelia\Form\Exception\FormValidationException; diff --git a/core/lib/Thelia/Controller/Admin/CategoryController.php b/core/lib/Thelia/Controller/Admin/CategoryController.php index 8dcba2cbe..a6581cca7 100644 --- a/core/lib/Thelia/Controller/Admin/CategoryController.php +++ b/core/lib/Thelia/Controller/Admin/CategoryController.php @@ -23,7 +23,7 @@ namespace Thelia\Controller\Admin; -use Thelia\Core\HttpFoundation\Response; + use Thelia\Core\Security\Resource\AdminResources; use Thelia\Core\Event\Category\CategoryDeleteEvent; use Thelia\Core\Event\TheliaEvents; diff --git a/core/lib/Thelia/Controller/Admin/CustomerController.php b/core/lib/Thelia/Controller/Admin/CustomerController.php index a901d4c6b..2368e630a 100644 --- a/core/lib/Thelia/Controller/Admin/CustomerController.php +++ b/core/lib/Thelia/Controller/Admin/CustomerController.php @@ -30,8 +30,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Form\CustomerCreateForm; use Thelia\Form\CustomerUpdateForm; use Thelia\Model\CustomerQuery; -use Thelia\Tools\Password; -use Thelia\Model\Address; + /** * Class CustomerController diff --git a/core/lib/Thelia/Controller/Admin/FeatureController.php b/core/lib/Thelia/Controller/Admin/FeatureController.php index 4cbbd8527..1a149e248 100644 --- a/core/lib/Thelia/Controller/Admin/FeatureController.php +++ b/core/lib/Thelia/Controller/Admin/FeatureController.php @@ -33,7 +33,7 @@ use Thelia\Model\FeatureQuery; use Thelia\Form\FeatureModificationForm; use Thelia\Form\FeatureCreationForm; use Thelia\Core\Event\UpdatePositionEvent; -use Thelia\Model\FeatureAv; + use Thelia\Core\Event\Feature\FeatureAvUpdateEvent; use Thelia\Core\Event\Feature\FeatureEvent; diff --git a/core/lib/Thelia/Controller/Admin/FileController.php b/core/lib/Thelia/Controller/Admin/FileController.php index f123bfb94..95936df28 100644 --- a/core/lib/Thelia/Controller/Admin/FileController.php +++ b/core/lib/Thelia/Controller/Admin/FileController.php @@ -81,7 +81,7 @@ class FileController extends BaseAdminController /** @var UploadedFile $fileBeingUploaded */ $fileBeingUploaded = $this->getRequest()->files->get('file'); - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); // Validate if file is too big if ($fileBeingUploaded->getError() == 1) { @@ -171,7 +171,7 @@ class FileController extends BaseAdminController /** @var UploadedFile $fileBeingUploaded */ $fileBeingUploaded = $this->getRequest()->files->get('file'); - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); // Validate if file is too big if ($fileBeingUploaded->getError() == 1) { @@ -312,7 +312,7 @@ class FileController extends BaseAdminController return $response; } try { - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $image = $fileManager->getImageModelQuery($parentType)->findPk($imageId); $redirectUrl = $fileManager->getRedirectionUrl($parentType, $image->getParentId(), FileManager::FILE_TYPE_IMAGES); @@ -341,7 +341,7 @@ class FileController extends BaseAdminController return $response; } try { - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $document = $fileManager->getDocumentModelQuery($parentType)->findPk($documentId); $redirectUrl = $fileManager->getRedirectionUrl($parentType, $document->getParentId(), FileManager::FILE_TYPE_DOCUMENTS); @@ -372,7 +372,7 @@ class FileController extends BaseAdminController $message = false; - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $imageModification = $fileManager->getImageForm($parentType, $this->getRequest()); try { @@ -449,7 +449,7 @@ class FileController extends BaseAdminController $message = false; - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $documentModification = $fileManager->getDocumentForm($parentType, $this->getRequest()); try { @@ -525,7 +525,7 @@ class FileController extends BaseAdminController $this->checkAuth(AdminResources::retrieve($parentType), array(), AccessManager::UPDATE); $this->checkXmlHttpRequest(); - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $imageModelQuery = $fileManager->getImageModelQuery($parentType); $model = $imageModelQuery->findPk($imageId); @@ -606,7 +606,7 @@ class FileController extends BaseAdminController $this->checkAuth(AdminResources::retrieve($parentType), array(), AccessManager::UPDATE); $this->checkXmlHttpRequest(); - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $imageModelQuery = $fileManager->getImageModelQuery($parentType); $model = $imageModelQuery->findPk($imageId); @@ -660,7 +660,7 @@ class FileController extends BaseAdminController $this->checkAuth(AdminResources::retrieve($parentType), array(), AccessManager::UPDATE); $this->checkXmlHttpRequest(); - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $documentModelQuery = $fileManager->getDocumentModelQuery($parentType); $model = $documentModelQuery->findPk($documentId); @@ -717,7 +717,7 @@ class FileController extends BaseAdminController $this->checkAuth(AdminResources::retrieve($parentType), array(), AccessManager::UPDATE); $this->checkXmlHttpRequest(); - $fileManager = new FileManager($this->container); + $fileManager = new FileManager(); $documentModelQuery = $fileManager->getDocumentModelQuery($parentType); $model = $documentModelQuery->findPk($documentId); diff --git a/core/lib/Thelia/Controller/Admin/ModuleController.php b/core/lib/Thelia/Controller/Admin/ModuleController.php index e86014809..2eedc8f44 100644 --- a/core/lib/Thelia/Controller/Admin/ModuleController.php +++ b/core/lib/Thelia/Controller/Admin/ModuleController.php @@ -31,6 +31,7 @@ use Thelia\Core\Event\Module\ModuleToggleActivationEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Security\AccessManager; use Thelia\Form\ModuleModificationForm; +use Thelia\Log\Tlog; use Thelia\Model\ModuleQuery; use Thelia\Module\ModuleManagement; use Thelia\Core\Event\UpdatePositionEvent; @@ -56,20 +57,6 @@ class ModuleController extends AbstractCrudController null, null, TheliaEvents::MODULE_UPDATE_POSITION -/* - $objectName, - - $defaultListOrder = null, - $orderRequestParameterName = null, - - $resourceCode, - - $createEventIdentifier, - $updateEventIdentifier, - $deleteEventIdentifier, - $visibilityToggleEventIdentifier = null, - $changePositionEventIdentifier = null -*/ ); } @@ -249,6 +236,8 @@ class ModuleController extends AbstractCrudController } } catch (\Exception $e) { $message = $e->getMessage(); + + Tlog::getInstance()->addError("Failed to activate/deactivate module:", $e); } if ($this->getRequest()->isXmlHttpRequest()) { @@ -288,8 +277,9 @@ class ModuleController extends AbstractCrudController } } catch (\Exception $e) { - \Thelia\Log\Tlog::getInstance()->error(sprintf("error during module removal : %s", $message)); $message = $e->getMessage(); + + Tlog::getInstance()->addError("Error during module removal", $e); } if ($message) { diff --git a/core/lib/Thelia/Controller/Admin/OrderController.php b/core/lib/Thelia/Controller/Admin/OrderController.php index 97713a589..1d7c080c4 100644 --- a/core/lib/Thelia/Controller/Admin/OrderController.php +++ b/core/lib/Thelia/Controller/Admin/OrderController.php @@ -23,7 +23,7 @@ namespace Thelia\Controller\Admin; -use Thelia\Core\HttpFoundation\Response; + use Thelia\Core\Security\Resource\AdminResources; use Thelia\Core\Event\Order\OrderAddressEvent; use Thelia\Core\Event\Order\OrderEvent; @@ -67,10 +67,8 @@ class OrderController extends BaseAdminController $message = null; try { - if ($order_id !== null) { - $order_id = $order_id; - } else { - $order_id = $this->getRequest()->get("order_id"); + if ($order_id === null) { + $order_id = $this->getRequest()->get("order_id"); } $order = OrderQuery::create()->findPk($order_id); diff --git a/core/lib/Thelia/Controller/Admin/SessionController.php b/core/lib/Thelia/Controller/Admin/SessionController.php index 78394fa19..03e626812 100644 --- a/core/lib/Thelia/Controller/Admin/SessionController.php +++ b/core/lib/Thelia/Controller/Admin/SessionController.php @@ -31,11 +31,11 @@ use Thelia\Model\AdminLog; use Thelia\Core\Security\Exception\AuthenticationException; use Thelia\Model\Lang; use Thelia\Model\LangQuery; -use Thelia\Tools\URL; -use Thelia\Tools\Redirect; + + use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Security\Authentication\AdminTokenAuthenticator; -use Symfony\Component\HttpFoundation\Cookie; + use Thelia\Core\Security\Exception\TokenAuthenticationException; class SessionController extends BaseAdminController diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 848d5514e..452fd87d0 100644 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -32,15 +32,15 @@ use Symfony\Component\Routing\Exception\InvalidParameterException; use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Router; -use Thelia\Core\Security\SecurityContext; + use Thelia\Core\Template\TemplateHelper; use Thelia\Core\Translation\Translator; use Thelia\Model\OrderQuery; -use Thelia\Tools\URL; + use Thelia\Tools\Redirect; use Thelia\Core\Template\ParserContext; use Thelia\Core\Event\ActionEvent; -use Symfony\Component\EventDispatcher\EventDispatcher; + use Thelia\Form\BaseForm; use Thelia\Form\Exception\FormValidationException; use Symfony\Component\EventDispatcher\Event; diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index 3e70364d4..d0c6b52f6 100644 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -28,7 +28,7 @@ use Thelia\Core\HttpFoundation\Response; use Thelia\Core\Template\TemplateHelper; use Thelia\Model\AddressQuery; use Thelia\Model\ModuleQuery; -use Thelia\Tools\Redirect; + use Thelia\Tools\URL; class BaseFrontController extends BaseController diff --git a/core/lib/Thelia/Controller/Front/DefaultController.php b/core/lib/Thelia/Controller/Front/DefaultController.php index 0466e4dd4..bd2b31fa5 100644 --- a/core/lib/Thelia/Controller/Front/DefaultController.php +++ b/core/lib/Thelia/Controller/Front/DefaultController.php @@ -24,7 +24,7 @@ namespace Thelia\Controller\Front; use Symfony\Component\HttpFoundation\Request; use Thelia\Model\ConfigQuery; -use Thelia\Tools\Redirect; + use Thelia\Tools\URL; /** diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorEvent.php index 48ff97be8..0071526dc 100644 --- a/core/lib/Thelia/Core/Event/Administrator/AdministratorEvent.php +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorEvent.php @@ -62,6 +62,8 @@ class AdministratorEvent extends ActionEvent public function setId($id) { $this->id = $id; + + return $this; } public function getId() @@ -72,6 +74,8 @@ class AdministratorEvent extends ActionEvent public function setFirstname($firstname) { $this->firstname = $firstname; + + return $this; } public function getFirstname() @@ -82,6 +86,8 @@ class AdministratorEvent extends ActionEvent public function setLastname($lastname) { $this->lastname = $lastname; + + return $this; } public function getLastname() @@ -92,6 +98,8 @@ class AdministratorEvent extends ActionEvent public function setLogin($login) { $this->login = $login; + + return $this; } public function getLogin() @@ -102,6 +110,8 @@ class AdministratorEvent extends ActionEvent public function setPassword($password) { $this->password = $password; + + return $this; } public function getPassword() @@ -112,6 +122,8 @@ class AdministratorEvent extends ActionEvent public function setProfile($profile) { $this->profile = $profile; + + return $this; } public function getProfile() diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php index 8cfe1ee02..5c310d7cb 100644 --- a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -54,6 +54,8 @@ class AdministratorUpdatePasswordEvent extends ActionEvent public function setPassword($password) { $this->password = $password; + + return $this; } /** @@ -70,6 +72,8 @@ class AdministratorUpdatePasswordEvent extends ActionEvent public function setAdmin(Admin $admin) { $this->admin = $admin; + + return $this; } /** diff --git a/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php b/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php index 32dc7a6c8..d833b4128 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaCreateEvent.php @@ -38,6 +38,8 @@ class AreaCreateEvent extends AreaEvent public function setAreaName($name) { $this->name = $name; + + return $this; } /** diff --git a/core/lib/Thelia/Core/Event/Area/AreaEvent.php b/core/lib/Thelia/Core/Event/Area/AreaEvent.php index 9e0c2dc00..6c951335a 100644 --- a/core/lib/Thelia/Core/Event/Area/AreaEvent.php +++ b/core/lib/Thelia/Core/Event/Area/AreaEvent.php @@ -31,6 +31,9 @@ use Thelia\Core\Event\ActionEvent; */ class AreaEvent extends ActionEvent { + /** + * @var \Thelia\Model\Area + */ protected $area; public function __construct($area = null) @@ -51,7 +54,7 @@ class AreaEvent extends ActionEvent } /** - * @return mixed + * @return null|\Thelia\Model\Area */ public function getArea() { diff --git a/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php b/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php new file mode 100644 index 000000000..13211092e --- /dev/null +++ b/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php @@ -0,0 +1,52 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Order; + +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Order; + +/** + * Class PaymentEvent + * @package Thelia\Core\Event\Module + * @author Franck Allimant + */ +class OrderPaymentEvent extends ActionEvent +{ + /** + * @var Order + */ + protected $order; + + public function __construct(Order $order) { + $this->order = $order; + } + + /** + * @return \Thelia\Model\Order + */ + public function getOrder() + { + return $this->order; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index 4691fd36d..24cb3eec6 100644 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -706,6 +706,10 @@ final class TheliaEvents const MODULE_UPDATE = 'thelia.module.update'; const MODULE_DELETE = 'thelia.module.delete'; + /* Invoke payment module */ + + const MODULE_PAY = 'thelia.module.pay'; + /** * sent for clearing cache */ diff --git a/core/lib/Thelia/Core/EventListener/ViewListener.php b/core/lib/Thelia/Core/EventListener/ViewListener.php index 948fd1267..59484eed3 100644 --- a/core/lib/Thelia/Core/EventListener/ViewListener.php +++ b/core/lib/Thelia/Core/EventListener/ViewListener.php @@ -31,11 +31,11 @@ use Symfony\Component\HttpFoundation\Request; use Thelia\Core\HttpFoundation\Response; use Symfony\Component\Routing\Router; use Thelia\Core\Template\Exception\ResourceNotFoundException; -use Thelia\Core\Template\ParserInterface; + use Thelia\Core\Template\TemplateHelper; use Thelia\Exception\OrderException; use Thelia\Tools\Redirect; -use Thelia\Tools\URL; + use Thelia\Core\Security\Exception\AuthenticationException; /** diff --git a/core/lib/Thelia/Core/Security/Authentication/AdminUsernamePasswordFormAuthenticator.php b/core/lib/Thelia/Core/Security/Authentication/AdminUsernamePasswordFormAuthenticator.php index 9b5205319..00201c0f1 100644 --- a/core/lib/Thelia/Core/Security/Authentication/AdminUsernamePasswordFormAuthenticator.php +++ b/core/lib/Thelia/Core/Security/Authentication/AdminUsernamePasswordFormAuthenticator.php @@ -25,10 +25,10 @@ namespace Thelia\Core\Security\Authentication; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Form\Form; + use Thelia\Core\Security\UserProvider\AdminUserProvider; -use Thelia\Core\Security\Authentication\UsernamePasswordFormAuthenticator; + use Thelia\Form\AdminLogin; class AdminUsernamePasswordFormAuthenticator extends UsernamePasswordFormAuthenticator diff --git a/core/lib/Thelia/Core/Security/Authentication/CustomerUsernamePasswordFormAuthenticator.php b/core/lib/Thelia/Core/Security/Authentication/CustomerUsernamePasswordFormAuthenticator.php index cd3dd0800..7da54e26b 100644 --- a/core/lib/Thelia/Core/Security/Authentication/CustomerUsernamePasswordFormAuthenticator.php +++ b/core/lib/Thelia/Core/Security/Authentication/CustomerUsernamePasswordFormAuthenticator.php @@ -25,7 +25,7 @@ namespace Thelia\Core\Security\Authentication; use Symfony\Component\HttpFoundation\Request; -use Thelia\Core\Security\Authentication\UsernamePasswordFormAuthenticator; + use Thelia\Form\CustomerLogin; use Thelia\Core\Security\UserProvider\CustomerUserProvider; diff --git a/core/lib/Thelia/Core/Security/Authentication/TokenAuthenticator.php b/core/lib/Thelia/Core/Security/Authentication/TokenAuthenticator.php index e00ae4375..c348628ab 100644 --- a/core/lib/Thelia/Core/Security/Authentication/TokenAuthenticator.php +++ b/core/lib/Thelia/Core/Security/Authentication/TokenAuthenticator.php @@ -23,7 +23,7 @@ namespace Thelia\Core\Security\Authentication; -use Thelia\Core\Security\Authentication\AuthenticatorInterface; + use Thelia\Core\Security\UserProvider\TokenUserProvider; use Thelia\Core\Security\Exception\TokenAuthenticationException; diff --git a/core/lib/Thelia/Core/Security/Authentication/UsernamePasswordFormAuthenticator.php b/core/lib/Thelia/Core/Security/Authentication/UsernamePasswordFormAuthenticator.php index d9a223430..2b85bb7f3 100644 --- a/core/lib/Thelia/Core/Security/Authentication/UsernamePasswordFormAuthenticator.php +++ b/core/lib/Thelia/Core/Security/Authentication/UsernamePasswordFormAuthenticator.php @@ -23,10 +23,10 @@ namespace Thelia\Core\Security\Authentication; -use Thelia\Core\Security\Authentication\AuthenticatorInterface; + use Symfony\Component\HttpFoundation\Request; use Thelia\Core\Security\UserProvider\UserProviderInterface; -use Symfony\Component\Form\Form; + use Thelia\Core\Security\Exception\WrongPasswordException; use Thelia\Core\Security\Exception\UsernameNotFoundException; use Symfony\Component\Validator\Exception\ValidatorException; diff --git a/core/lib/Thelia/Core/Security/UserProvider/AdminUserProvider.php b/core/lib/Thelia/Core/Security/UserProvider/AdminUserProvider.php index a6147fca4..c7ee4207a 100644 --- a/core/lib/Thelia/Core/Security/UserProvider/AdminUserProvider.php +++ b/core/lib/Thelia/Core/Security/UserProvider/AdminUserProvider.php @@ -23,7 +23,7 @@ namespace Thelia\Core\Security\UserProvider; -use Thelia\Model\Admin; + use Thelia\Model\AdminQuery; class AdminUserProvider implements UserProviderInterface diff --git a/core/lib/Thelia/Core/Security/UserProvider/CustomerUserProvider.php b/core/lib/Thelia/Core/Security/UserProvider/CustomerUserProvider.php index ccc15c3c7..730bdcfeb 100644 --- a/core/lib/Thelia/Core/Security/UserProvider/CustomerUserProvider.php +++ b/core/lib/Thelia/Core/Security/UserProvider/CustomerUserProvider.php @@ -23,7 +23,7 @@ namespace Thelia\Core\Security\UserProvider; -use Thelia\Action\Customer; + use Thelia\Model\CustomerQuery; class CustomerUserProvider implements UserProviderInterface { diff --git a/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php b/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php index bca1ce1c7..e50a7a330 100644 --- a/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php +++ b/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php @@ -316,8 +316,6 @@ class AsseticAssetManager implements AssetManagerInterface // Get the URL part from the relative path $outputRelativePath = $webAssetsTemplate . DS . $webAssetsKey; - $outputRelativeWebPath = rtrim(str_replace('\\', '/', $outputRelativePath), '/') . '/'; - $assetTargetFilename = $asset->getTargetPath(); /* @@ -333,11 +331,18 @@ class AsseticAssetManager implements AssetManagerInterface $writer = new AssetWriter($outputDirectory . DS . $assetFileDirectoryInAssetDirectory); - Tlog::getInstance()->addDebug("Writing asset to $outputDirectory . DS . $assetFileDirectoryInAssetDirectory"); + Tlog::getInstance()->addDebug("Writing asset to $outputDirectory" . DS . "$assetFileDirectoryInAssetDirectory"); $writer->writeAsset($asset); } + // Normalize path to generate a valid URL + if (DS != '/') { + $outputRelativeWebPath = str_replace(DS, '/', $outputRelativePath); + $assetFileDirectoryInAssetDirectory = str_replace(DS, '/', $assetFileDirectoryInAssetDirectory); + $assetTargetFilename = str_replace(DS, '/', $assetTargetFilename); + } + return rtrim($outputUrl, '/') . '/' . trim($outputRelativeWebPath, '/') . '/' . trim($assetFileDirectoryInAssetDirectory, '/') . '/' . ltrim($assetTargetFilename, '/'); } } diff --git a/core/lib/Thelia/Core/Template/Element/BaseI18nLoop.php b/core/lib/Thelia/Core/Template/Element/BaseI18nLoop.php index aff1d9188..000716c9a 100644 --- a/core/lib/Thelia/Core/Template/Element/BaseI18nLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseI18nLoop.php @@ -23,7 +23,7 @@ namespace Thelia\Core\Template\Element; -use Symfony\Component\HttpFoundation\Request; + use Thelia\Core\Template\Loop\Argument\Argument; use Propel\Runtime\ActiveQuery\ModelCriteria; use Thelia\Model\Tools\ModelCriteriaTools; diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index 2aa5e874f..de851cc8c 100644 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -24,14 +24,11 @@ namespace Thelia\Core\Template\Element; use Propel\Runtime\ActiveQuery\Criteria; +use Propel\Runtime\ActiveQuery\ModelCriteria; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Thelia\Core\Security\SecurityContext; use Thelia\Core\Template\Element\Exception\LoopException; use Thelia\Core\Template\Loop\Argument\Argument; -use Propel\Runtime\ActiveQuery\ModelCriteria; -use Thelia\Core\Security\SecurityContext; -use Thelia\Type\AlphaNumStringListType; use Thelia\Type\EnumListType; use Thelia\Type\EnumType; use Thelia\Type\TypeCollection; @@ -339,7 +336,7 @@ abstract class BaseLoop public function count() { $hash = $this->args->getHash(); - if(false === array_key_exists($hash, self::$cacheCount)) + if(false === isset(self::$cacheCount[$hash])) { $count = 0; if ($this instanceof PropelSearchLoopInterface) { @@ -370,7 +367,7 @@ abstract class BaseLoop public function exec(&$pagination) { $hash = $this->args->getHash(); - if(false === array_key_exists($hash, self::$cacheLoopResult)) + if(false === isset(self::$cacheLoopResult[$hash])) { if ($this instanceof PropelSearchLoopInterface) { $searchModelCriteria = $this->buildModelCriteria(); diff --git a/core/lib/Thelia/Core/Template/Element/LoopResult.php b/core/lib/Thelia/Core/Template/Element/LoopResult.php index af24a4bda..a8e093d9b 100644 --- a/core/lib/Thelia/Core/Template/Element/LoopResult.php +++ b/core/lib/Thelia/Core/Template/Element/LoopResult.php @@ -25,7 +25,7 @@ namespace Thelia\Core\Template\Element; use Propel\Runtime\Collection\ObjectCollection; use Propel\Runtime\Util\PropelModelPager; -use Thelia\Core\Template\Element\LoopResultRow; + class LoopResult implements \Iterator { diff --git a/core/lib/Thelia/Core/Template/Loop/Accessory.php b/core/lib/Thelia/Core/Template/Loop/Accessory.php index de08f1f5b..45be652e4 100644 --- a/core/lib/Thelia/Core/Template/Loop/Accessory.php +++ b/core/lib/Thelia/Core/Template/Loop/Accessory.php @@ -23,7 +23,7 @@ namespace Thelia\Core\Template\Loop; -use Thelia\Core\Template\Loop\Product; + use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Core\Template\Element\LoopResult; diff --git a/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php b/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php index 0ba86e7d0..56100e490 100644 --- a/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php +++ b/core/lib/Thelia/Core/Template/Loop/Argument/Argument.php @@ -56,6 +56,11 @@ class Argument return $this->type->getFormattedValue($this->value); } + public function getRawValue() + { + return $this->value; + } + public function setValue($value) { if ($value === null) { @@ -147,4 +152,5 @@ class Argument $empty ); } + } diff --git a/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php b/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php index 7f5a604c5..eb815c708 100644 --- a/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php +++ b/core/lib/Thelia/Core/Template/Loop/Argument/ArgumentCollection.php @@ -153,6 +153,11 @@ class ArgumentCollection implements \Iterator unset($arguments['name']); } - return sha1(serialize($arguments)); + $string = ''; + foreach ($arguments as $key => $argument) { + $string .= $key.'='.$argument->getRawValue(); + } + + return md5($string); } } diff --git a/core/lib/Thelia/Core/Template/Loop/AssociatedContent.php b/core/lib/Thelia/Core/Template/Loop/AssociatedContent.php index 3cfedd5d3..535f47c2a 100644 --- a/core/lib/Thelia/Core/Template/Loop/AssociatedContent.php +++ b/core/lib/Thelia/Core/Template/Loop/AssociatedContent.php @@ -23,7 +23,7 @@ namespace Thelia\Core\Template\Loop; -use Thelia\Core\Template\Loop\Content; + use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Core\Template\Element\LoopResult; diff --git a/core/lib/Thelia/Core/Template/Loop/Cart.php b/core/lib/Thelia/Core/Template/Loop/Cart.php index 2ad8ae8a2..02a3fada6 100644 --- a/core/lib/Thelia/Core/Template/Loop/Cart.php +++ b/core/lib/Thelia/Core/Template/Loop/Cart.php @@ -15,7 +15,7 @@ use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; -use Thelia\TaxEngine\TaxEngine; + use Thelia\Type; class Cart extends BaseLoop implements ArraySearchLoopInterface @@ -55,7 +55,7 @@ class Cart extends BaseLoop implements ArraySearchLoopInterface public function buildArray() { - $cart = $this->getCart($this->request); + $cart = $this->getCart($this->getDispatcher(), $this->request); if (null === $cart) { return array(); diff --git a/core/lib/Thelia/Core/Template/Loop/Delivery.php b/core/lib/Thelia/Core/Template/Loop/Delivery.php index 87f00a7ec..67bf0fbd3 100644 --- a/core/lib/Thelia/Core/Template/Loop/Delivery.php +++ b/core/lib/Thelia/Core/Template/Loop/Delivery.php @@ -29,7 +29,7 @@ use Thelia\Exception\OrderException; use Thelia\Model\CountryQuery; use Thelia\Module\BaseModule; use Thelia\Module\DeliveryModuleInterface; -use Thelia\TaxEngine\TaxEngine; + /** * Class Delivery diff --git a/core/lib/Thelia/Core/Template/Loop/Order.php b/core/lib/Thelia/Core/Template/Loop/Order.php index 696dc7bc2..870ce2121 100644 --- a/core/lib/Thelia/Core/Template/Loop/Order.php +++ b/core/lib/Thelia/Core/Template/Loop/Order.php @@ -31,7 +31,7 @@ use Thelia\Core\Template\Element\PropelSearchLoopInterface; use Thelia\Core\Template\Element\SearchLoopInterface; use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\ArgumentCollection; -use Thelia\Model\Base\Customer; + use Thelia\Model\CustomerQuery; use Thelia\Model\Map\CustomerTableMap; use Thelia\Model\Map\OrderAddressTableMap; diff --git a/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php b/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php index 4ea880d01..449cc1e29 100644 --- a/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php +++ b/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php @@ -24,7 +24,7 @@ namespace Thelia\Core\Template\Loop; use Propel\Runtime\ActiveQuery\Criteria; -use Thelia\Condition\ConditionFactory; + use Thelia\Core\Template\Element\BaseLoop; use Thelia\Core\Template\Element\LoopResult; use Thelia\Core\Template\Element\LoopResultRow; diff --git a/core/lib/Thelia/Core/Template/Loop/Product.php b/core/lib/Thelia/Core/Template/Loop/Product.php index 99689fbd2..8bcf76e4d 100644 --- a/core/lib/Thelia/Core/Template/Loop/Product.php +++ b/core/lib/Thelia/Core/Template/Loop/Product.php @@ -43,7 +43,7 @@ use Thelia\Model\Map\ProductSaleElementsTableMap; use Thelia\Model\Map\ProductTableMap; use Thelia\Model\ProductCategoryQuery; use Thelia\Model\ProductQuery; -use Thelia\TaxEngine\TaxEngine; + use Thelia\Type\TypeCollection; use Thelia\Type; diff --git a/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php b/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php index 8e2aa03dd..e873faaf2 100644 --- a/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php +++ b/core/lib/Thelia/Core/Template/Loop/ProductSaleElements.php @@ -36,7 +36,7 @@ use Thelia\Exception\TaxEngineException; use Thelia\Model\Base\ProductSaleElementsQuery; use Thelia\Model\CurrencyQuery; use Thelia\Model\Map\ProductSaleElementsTableMap; -use Thelia\TaxEngine\TaxEngine; + use Thelia\Type\TypeCollection; use Thelia\Type; diff --git a/core/lib/Thelia/Core/Template/ParserInterface.php b/core/lib/Thelia/Core/Template/ParserInterface.php index 22badf688..9ec99360c 100644 --- a/core/lib/Thelia/Core/Template/ParserInterface.php +++ b/core/lib/Thelia/Core/Template/ParserInterface.php @@ -58,4 +58,12 @@ interface ParserInterface * @return array: an array of defined templates directories for the given template type */ public function getTemplateDirectories($templateType); + + /** + * Create a variable that will be available in the templates + * + * @param $variable the vatiable name + * @param $value the value of the variable + */ + public function assign($variable, $value); } diff --git a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php index 18e771336..d595fdbe4 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php +++ b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php @@ -23,7 +23,8 @@ namespace Thelia\Core\Template\Smarty\Assets; -use Thelia\Core\Template\TemplateDefinition; + +use Thelia\Log\Tlog; use Thelia\Tools\URL; use Thelia\Core\Template\Assets\AssetManagerInterface; @@ -109,6 +110,11 @@ class SmartyAssetsManager $assetSource = $templateDirectories[$templateDefinition->getName()][$assetOrigin]; + if (DS != '/') { + // Just to be sure to generate a clean pathname + $file = str_replace('/', DS, $file); + } + $url = $this->assetsManager->processAsset( $assetSource . DS . $file, $assetSource . DS . self::$assetsDirectory, diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php index 13ee8e852..bdc477551 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/DataAccessFunctions.php @@ -37,7 +37,7 @@ use Thelia\Model\CountryQuery; use Thelia\Model\CurrencyQuery; use Thelia\Model\FolderQuery; use Thelia\Model\OrderQuery; -use Thelia\Model\Product; + use Thelia\Model\ProductQuery; use Thelia\Model\Tools\ModelCriteriaTools; use Thelia\TaxEngine\TaxEngine; @@ -190,7 +190,7 @@ class DataAccessFunctions extends AbstractSmartyPlugin self::$dataAccessCache['currentCountry'] = $taxCountry; } - $cart = $this->getCart($this->request); + $cart = $this->getCart($this->getDispatcher(), $this->request); $result = ""; switch ($params["attr"]) { case "count_item": diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 9a1279da9..fac094dd6 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -24,7 +24,7 @@ namespace Thelia\Core\Template\Smarty\Plugins; use Symfony\Component\Form\FormView; use Thelia\Core\Form\Type\TheliaType; -use Thelia\Form\BaseForm; + use Thelia\Core\Template\Element\Exception\ElementNotFoundException; use Symfony\Component\HttpFoundation\Request; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php index da98ce14d..5f88068ac 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php @@ -48,7 +48,13 @@ class Module extends AbstractSmartyPlugin /** * Process theliaModule template inclusion function * - * @param unknown $params + * This function accepts two parameters: + * + * - location : this is the location in the admin template. Example: folder-edit'. The function will search for + * AdminIncludes/.html file, and fetch it as a Smarty template. + * - countvar : this is the name of a template variable where the number of found modules includes will be assigned. + * + * @param array $params * @param \Smarty_Internal_Template $template * @internal param \Thelia\Core\Template\Smarty\Plugins\unknown $smarty * @@ -68,6 +74,8 @@ class Module extends AbstractSmartyPlugin $modules = ModuleQuery::getActivated(); + $count = 0; + foreach ($modules as $module) { if (null !== $moduleLimit && $moduleLimit != $module->getCode()) { @@ -78,6 +86,8 @@ class Module extends AbstractSmartyPlugin if (file_exists($file)) { $content .= file_get_contents($file); + + $count++; } } } @@ -86,6 +96,10 @@ class Module extends AbstractSmartyPlugin return $template->fetch(sprintf("string:%s", $content)); } + if (false !== $countvarname = $this->getParam($params, 'countvar', false)) { + $template->assign($countvarname, $count); + } + return ""; } diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index 251ae9b9c..cffd16479 100644 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -7,10 +7,10 @@ use \Symfony\Component\EventDispatcher\EventDispatcherInterface; use \Smarty; -use Thelia\Core\HttpFoundation\Response; + use Thelia\Core\Template\ParserInterface; -use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; + use Thelia\Core\Template\Exception\ResourceNotFoundException; use Thelia\Core\Template\ParserContext; use Thelia\Core\Template\TemplateDefinition; diff --git a/core/lib/Thelia/Core/Template/TemplateDefinition.php b/core/lib/Thelia/Core/Template/TemplateDefinition.php index 28ac17866..b511414a5 100644 --- a/core/lib/Thelia/Core/Template/TemplateDefinition.php +++ b/core/lib/Thelia/Core/Template/TemplateDefinition.php @@ -30,10 +30,10 @@ class TemplateDefinition const PDF = 3; const EMAIL = 4; - const FRONT_OFFICE_SUBDIR = 'frontOffice/'; - const BACK_OFFICE_SUBDIR = 'backOffice/'; - const PDF_SUBDIR = 'pdf/'; - const EMAIL_SUBDIR = 'email/'; + const FRONT_OFFICE_SUBDIR = 'frontOffice'; + const BACK_OFFICE_SUBDIR = 'backOffice'; + const PDF_SUBDIR = 'pdf'; + const EMAIL_SUBDIR = 'email'; protected static $standardTemplatesSubdirs = array( self::FRONT_OFFICE => self::FRONT_OFFICE_SUBDIR, @@ -64,16 +64,16 @@ class TemplateDefinition switch ($type) { case TemplateDefinition::FRONT_OFFICE: - $this->path = self::FRONT_OFFICE_SUBDIR . $name; + $this->path = self::FRONT_OFFICE_SUBDIR . DS . $name; break; case TemplateDefinition::BACK_OFFICE: - $this->path = self::BACK_OFFICE_SUBDIR . $name; + $this->path = self::BACK_OFFICE_SUBDIR . DS . $name; break; case TemplateDefinition::PDF: - $this->path = self::PDF_SUBDIR . $name; + $this->path = self::PDF_SUBDIR . DS . $name; break; case TemplateDefinition::EMAIL: - $this->path = self::EMAIL_SUBDIR . $name; + $this->path = self::EMAIL_SUBDIR . DS . $name; break; default: $this->path = $name; diff --git a/core/lib/Thelia/Core/Template/TemplateHelper.php b/core/lib/Thelia/Core/Template/TemplateHelper.php index a95d7b899..c08d94c0a 100644 --- a/core/lib/Thelia/Core/Template/TemplateHelper.php +++ b/core/lib/Thelia/Core/Template/TemplateHelper.php @@ -129,7 +129,7 @@ class TemplateHelper if ($file->isDot() || ! $file->isDir()) continue; // Ignore reserved directory names - if (in_array($file->getFilename()."/", $exclude)) continue; + if (in_array($file->getFilename(), $exclude)) continue; $list[] = new TemplateDefinition($file->getFilename(), $templateType); } diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index cc85ad632..9eb47b5ef 100644 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -47,7 +47,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Config\DatabaseConfiguration; use Thelia\Config\DefinePropel; use Thelia\Core\Template\TemplateDefinition; -use Thelia\Core\TheliaContainerBuilder; + use Thelia\Core\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\Config\FileLocator; diff --git a/core/lib/Thelia/Coupon/BaseFacade.php b/core/lib/Thelia/Coupon/BaseFacade.php index d1f1d22a6..4e7e7de13 100644 --- a/core/lib/Thelia/Coupon/BaseFacade.php +++ b/core/lib/Thelia/Coupon/BaseFacade.php @@ -71,7 +71,7 @@ class BaseFacade implements FacadeInterface */ public function getCart() { - return $this->getCartFromTrait($this->getRequest()); + return $this->getCartFromTrait($this->getDispatcher(), $this->getRequest()); } /** diff --git a/core/lib/Thelia/Coupon/Type/CouponAbstract.php b/core/lib/Thelia/Coupon/Type/CouponAbstract.php index ac4893478..23247e658 100644 --- a/core/lib/Thelia/Coupon/Type/CouponAbstract.php +++ b/core/lib/Thelia/Coupon/Type/CouponAbstract.php @@ -28,7 +28,7 @@ use Thelia\Core\Translation\Translator; use Thelia\Coupon\FacadeInterface; use Thelia\Condition\ConditionCollection; use Thelia\Condition\ConditionOrganizerInterface; -use Thelia\Exception\InvalidConditionException; + /** * Assist in writing a CouponInterface diff --git a/core/lib/Thelia/Coupon/Type/RemoveXAmount.php b/core/lib/Thelia/Coupon/Type/RemoveXAmount.php index 3158fd2b2..df28b6a11 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXAmount.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXAmount.php @@ -23,7 +23,7 @@ namespace Thelia\Coupon\Type; -use Thelia\Coupon\Type\CouponAbstract; + /** * Allow to remove an amount from the checkout total diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php index b6c13df1a..023df3b27 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php @@ -24,8 +24,7 @@ namespace Thelia\Coupon\Type; use Thelia\Coupon\FacadeInterface; -use Thelia\Coupon\Type\CouponAbstract; -use Thelia\Exception\MissingFacadeException; + /** * @package Coupon diff --git a/core/lib/Thelia/Form/AdministratorCreationForm.php b/core/lib/Thelia/Form/AdministratorCreationForm.php index f2a7e2452..9ad3e3421 100644 --- a/core/lib/Thelia/Form/AdministratorCreationForm.php +++ b/core/lib/Thelia/Form/AdministratorCreationForm.php @@ -23,7 +23,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraints\NotBlank; + use Symfony\Component\Validator\ExecutionContextInterface; use Thelia\Core\Translation\Translator; use Thelia\Model\AdminQuery; diff --git a/core/lib/Thelia/Form/Area/AreaModificationForm.php b/core/lib/Thelia/Form/Area/AreaModificationForm.php index 03f4b2e46..a2a5ff12e 100644 --- a/core/lib/Thelia/Form/Area/AreaModificationForm.php +++ b/core/lib/Thelia/Form/Area/AreaModificationForm.php @@ -23,7 +23,7 @@ namespace Thelia\Form\Area; use Symfony\Component\Validator\Constraints\GreaterThan; -use Thelia\Form\Area\AreaCreateForm; + /** * Class AreaModificationForm diff --git a/core/lib/Thelia/Form/CustomerCreateForm.php b/core/lib/Thelia/Form/CustomerCreateForm.php index e8582bf6c..b1984e8d4 100644 --- a/core/lib/Thelia/Form/CustomerCreateForm.php +++ b/core/lib/Thelia/Form/CustomerCreateForm.php @@ -23,7 +23,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraints\NotBlank; + use Symfony\Component\Validator\ExecutionContextInterface; use Thelia\Model\ConfigQuery; use Thelia\Model\CustomerQuery; diff --git a/core/lib/Thelia/Form/CustomerLogin.php b/core/lib/Thelia/Form/CustomerLogin.php index 66b5c34ef..cc0c1fd82 100644 --- a/core/lib/Thelia/Form/CustomerLogin.php +++ b/core/lib/Thelia/Form/CustomerLogin.php @@ -23,8 +23,8 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraints\NotBlank; -use Symfony\Component\Validator\Constraints\Email; + + use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ExecutionContextInterface; use Thelia\Core\Translation\Translator; diff --git a/core/lib/Thelia/Form/Image/DocumentModification.php b/core/lib/Thelia/Form/Image/DocumentModification.php index dbb85f5b3..267f3068d 100644 --- a/core/lib/Thelia/Form/Image/DocumentModification.php +++ b/core/lib/Thelia/Form/Image/DocumentModification.php @@ -22,7 +22,7 @@ /*************************************************************************************/ namespace Thelia\Form\Image; -use Symfony\Component\Validator\Constraints\Image; + use Symfony\Component\Validator\Constraints\NotBlank; use Thelia\Core\Translation\Translator; use Thelia\Form\BaseForm; diff --git a/core/lib/Thelia/Form/MailingSystemModificationForm.php b/core/lib/Thelia/Form/MailingSystemModificationForm.php index 144037a50..c30025bd1 100644 --- a/core/lib/Thelia/Form/MailingSystemModificationForm.php +++ b/core/lib/Thelia/Form/MailingSystemModificationForm.php @@ -22,9 +22,9 @@ /*************************************************************************************/ namespace Thelia\Form; -use Symfony\Component\Validator\ExecutionContextInterface; + use Thelia\Core\Translation\Translator; -use Thelia\Model\ProfileQuery; + /** * Class MailingSystemModificationForm diff --git a/core/lib/Thelia/Form/ProductCombinationGenerationForm.php b/core/lib/Thelia/Form/ProductCombinationGenerationForm.php index 1ca633ccd..82df0e09a 100644 --- a/core/lib/Thelia/Form/ProductCombinationGenerationForm.php +++ b/core/lib/Thelia/Form/ProductCombinationGenerationForm.php @@ -23,7 +23,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints\GreaterThan; -use Thelia\Model\Currency; + use Thelia\Core\Translation\Translator; class ProductCombinationGenerationForm extends BaseForm diff --git a/core/lib/Thelia/Form/ProfileUpdateModuleAccessForm.php b/core/lib/Thelia/Form/ProfileUpdateModuleAccessForm.php index 488c22d42..2f7331cb9 100644 --- a/core/lib/Thelia/Form/ProfileUpdateModuleAccessForm.php +++ b/core/lib/Thelia/Form/ProfileUpdateModuleAccessForm.php @@ -23,7 +23,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraints\NotBlank; + use Symfony\Component\Validator\ExecutionContextInterface; use Thelia\Core\Security\AccessManager; use Thelia\Model\ProfileQuery; diff --git a/core/lib/Thelia/Form/ProfileUpdateResourceAccessForm.php b/core/lib/Thelia/Form/ProfileUpdateResourceAccessForm.php index 69a982ac6..f4ce79414 100644 --- a/core/lib/Thelia/Form/ProfileUpdateResourceAccessForm.php +++ b/core/lib/Thelia/Form/ProfileUpdateResourceAccessForm.php @@ -23,7 +23,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints; -use Symfony\Component\Validator\Constraints\NotBlank; + use Symfony\Component\Validator\ExecutionContextInterface; use Thelia\Core\Security\AccessManager; use Thelia\Model\ProfileQuery; diff --git a/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php b/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php index b35aad12f..f204e7254 100644 --- a/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php +++ b/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php @@ -56,9 +56,6 @@ trait StandardDescriptionFieldsTrait new NotBlank() ), "label" => Translator::getInstance()->trans("Title"), - "label_attr" => array( - "for" => "title" - ), "label_attr" => array("for" => "title_field") ) ); diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index 38b6049dc..4ace03c8b 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -394,6 +394,7 @@ class CheckPermission extends BaseInstall { $val = trim($val); $last = strtolower($val[strlen($val)-1]); + // Do not add breaks in the switch below switch ($last) { // The 'G' modifier is available since PHP 5.1.0 case 'g': diff --git a/core/lib/Thelia/Log/Destination/TlogDestinationRotatingFile.php b/core/lib/Thelia/Log/Destination/TlogDestinationRotatingFile.php index dfd225347..4bb5e73d5 100644 --- a/core/lib/Thelia/Log/Destination/TlogDestinationRotatingFile.php +++ b/core/lib/Thelia/Log/Destination/TlogDestinationRotatingFile.php @@ -23,7 +23,7 @@ namespace Thelia\Log\Destination; -use Thelia\Log\AbstractTlogDestination; + use Thelia\Log\TlogDestinationConfig; use Thelia\Core\Translation\Translator; diff --git a/core/lib/Thelia/Log/Tlog.php b/core/lib/Thelia/Log/Tlog.php index 5e3d0537a..7e3554755 100644 --- a/core/lib/Thelia/Log/Tlog.php +++ b/core/lib/Thelia/Log/Tlog.php @@ -663,9 +663,13 @@ class Tlog Implements LoggerInterface { $text = ''; - if (is_scalar($message) === false) { - $text = print_r($message, true); - } else { + if ($message instanceof \Exception) { + $text = $message->getMessage()."\n".$message->getTraceAsString(); + } + else if (is_scalar($message) === false) { + $text = print_r($message, 1); + } + else { $text = $message; } diff --git a/core/lib/Thelia/Model/Address.php b/core/lib/Thelia/Model/Address.php index b4d5bc29a..20bf10bd8 100644 --- a/core/lib/Thelia/Model/Address.php +++ b/core/lib/Thelia/Model/Address.php @@ -3,11 +3,11 @@ namespace Thelia\Model; use Propel\Runtime\Connection\ConnectionInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; + use Thelia\Core\Event\Address\AddressEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Address as BaseAddress; -use Thelia\Model\AddressQuery; + class Address extends BaseAddress { use \Thelia\Model\Tools\ModelEventDispatcherTrait; diff --git a/core/lib/Thelia/Model/AttributeAv.php b/core/lib/Thelia/Model/AttributeAv.php index 8059b217e..bb0694eb5 100644 --- a/core/lib/Thelia/Model/AttributeAv.php +++ b/core/lib/Thelia/Model/AttributeAv.php @@ -6,7 +6,7 @@ use Thelia\Model\Base\AttributeAv as BaseAttributeAv; use Thelia\Core\Event\Attribute\AttributeAvEvent; use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Core\Event\TheliaEvents; -use Propel\Runtime\ActiveQuery\Criteria; + class AttributeAv extends BaseAttributeAv { diff --git a/core/lib/Thelia/Model/Cart.php b/core/lib/Thelia/Model/Cart.php index 5139057f4..0c30f2acf 100644 --- a/core/lib/Thelia/Model/Cart.php +++ b/core/lib/Thelia/Model/Cart.php @@ -3,11 +3,10 @@ namespace Thelia\Model; use Propel\Runtime\ActiveQuery\Criteria; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; + use Thelia\Model\Base\Cart as BaseCart; -use Thelia\Model\ProductSaleElementsQuery; -use Thelia\Model\ProductPriceQuery; -use Thelia\Model\CartItemQuery; + + use Thelia\TaxEngine\Calculator; class Cart extends BaseCart diff --git a/core/lib/Thelia/Model/CartItem.php b/core/lib/Thelia/Model/CartItem.php index ef72c070c..4e533f79d 100644 --- a/core/lib/Thelia/Model/CartItem.php +++ b/core/lib/Thelia/Model/CartItem.php @@ -6,7 +6,7 @@ use Propel\Runtime\Connection\ConnectionInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\CartItem as BaseCartItem; -use Thelia\Model\ConfigQuery; + use Thelia\Core\Event\Cart\CartEvent; use Thelia\TaxEngine\Calculator; diff --git a/core/lib/Thelia/Model/CartQuery.php b/core/lib/Thelia/Model/CartQuery.php index 1d51262d2..fcb9a82da 100644 --- a/core/lib/Thelia/Model/CartQuery.php +++ b/core/lib/Thelia/Model/CartQuery.php @@ -3,7 +3,7 @@ namespace Thelia\Model; use Thelia\Model\Base\CartQuery as BaseCartQuery; -use Symfony\Component\HttpFoundation\Request; + /** * Skeleton subclass for performing query and update operations on the 'cart' table. diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index 020dd8c92..d6ac1c394 100644 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -4,9 +4,8 @@ namespace Thelia\Model; use Thelia\Core\Event\Category\CategoryEvent; use Thelia\Model\Base\Category as BaseCategory; -use Propel\Runtime\ActiveQuery\Criteria; -use Thelia\Model\ProductCategoryQuery; -use Thelia\Tools\URL; + + use Thelia\Core\Event\TheliaEvents; use Propel\Runtime\Connection\ConnectionInterface; diff --git a/core/lib/Thelia/Model/CategoryImage.php b/core/lib/Thelia/Model/CategoryImage.php index 378350bf1..1a0b7a5fc 100644 --- a/core/lib/Thelia/Model/CategoryImage.php +++ b/core/lib/Thelia/Model/CategoryImage.php @@ -2,8 +2,7 @@ namespace Thelia\Model; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpFoundation\File\UploadedFile; + use Thelia\Model\Base\CategoryImage as BaseCategoryImage; use Propel\Runtime\Connection\ConnectionInterface; diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 3a002e6d1..d8ce9457a 100644 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -6,9 +6,9 @@ use Propel\Runtime\Propel; use Thelia\Core\Event\Content\ContentEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Content as BaseContent; -use Thelia\Model\ContentFolderQuery; + use Thelia\Model\Map\ContentTableMap; -use Thelia\Tools\URL; + use Propel\Runtime\Connection\ConnectionInterface; class Content extends BaseContent diff --git a/core/lib/Thelia/Model/Customer.php b/core/lib/Thelia/Model/Customer.php index 39ace0648..127a69a82 100644 --- a/core/lib/Thelia/Model/Customer.php +++ b/core/lib/Thelia/Model/Customer.php @@ -3,11 +3,11 @@ namespace Thelia\Model; use Propel\Runtime\Exception\PropelException; -use Thelia\Model\AddressQuery; + use Thelia\Model\Base\Customer as BaseCustomer; use Thelia\Model\Exception\InvalidArgumentException; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; + use Thelia\Core\Event\CustomRefEvent; use Thelia\Core\Event\TheliaEvents; diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index b267ce5f1..1189a44e4 100644 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -5,7 +5,7 @@ namespace Thelia\Model; use Thelia\Core\Event\Folder\FolderEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Folder as BaseFolder; -use Thelia\Tools\URL; + use Propel\Runtime\Connection\ConnectionInterface; class Folder extends BaseFolder diff --git a/core/lib/Thelia/Model/Lang.php b/core/lib/Thelia/Model/Lang.php index e7b83ead4..f4f524e97 100644 --- a/core/lib/Thelia/Model/Lang.php +++ b/core/lib/Thelia/Model/Lang.php @@ -11,7 +11,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Template\TemplateHelper; use Thelia\Core\Translation\Translator; use Thelia\Model\Base\Lang as BaseLang; -use Thelia\Model\LangQuery; + use Thelia\Model\Map\LangTableMap; class Lang extends BaseLang { diff --git a/core/lib/Thelia/Model/Module.php b/core/lib/Thelia/Model/Module.php index bfae1001a..957ced4ab 100644 --- a/core/lib/Thelia/Model/Module.php +++ b/core/lib/Thelia/Model/Module.php @@ -5,7 +5,7 @@ namespace Thelia\Model; use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\Module as BaseModule; use Thelia\Model\Tools\ModelEventDispatcherTrait; -use Thelia\Core\Event\TheliaEvents; + class Module extends BaseModule { diff --git a/core/lib/Thelia/Model/Order.php b/core/lib/Thelia/Model/Order.php index cadcda30e..4add32a45 100644 --- a/core/lib/Thelia/Model/Order.php +++ b/core/lib/Thelia/Model/Order.php @@ -4,15 +4,13 @@ namespace Thelia\Model; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Connection\ConnectionInterface; -use Propel\Runtime\Propel; + use Thelia\Core\Event\Order\OrderEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Order as BaseOrder; use Thelia\Model\Base\OrderProductTaxQuery; use Thelia\Model\Map\OrderProductTaxTableMap; -use Thelia\Model\OrderProductQuery; -use Thelia\Model\Map\OrderTableMap; -use \PDO; + class Order extends BaseOrder { diff --git a/core/lib/Thelia/Model/OrderQuery.php b/core/lib/Thelia/Model/OrderQuery.php index 5e5f77f07..d027af528 100644 --- a/core/lib/Thelia/Model/OrderQuery.php +++ b/core/lib/Thelia/Model/OrderQuery.php @@ -4,10 +4,10 @@ namespace Thelia\Model; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\ActiveQuery\Join; -use Propel\Runtime\Exception\PropelException; -use Propel\Runtime\Propel; + + use Thelia\Model\Base\OrderQuery as BaseOrderQuery; -use \PDO; + use Thelia\Model\Map\OrderTableMap; /** diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php index 5bcc56b46..d636c64a4 100644 --- a/core/lib/Thelia/Model/Product.php +++ b/core/lib/Thelia/Model/Product.php @@ -4,7 +4,7 @@ namespace Thelia\Model; use Propel\Runtime\Exception\PropelException; use Thelia\Model\Base\Product as BaseProduct; -use Thelia\Tools\URL; + use Thelia\TaxEngine\Calculator; use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Core\Event\TheliaEvents; @@ -12,7 +12,7 @@ use Thelia\Core\Event\Product\ProductEvent; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Propel; use Thelia\Model\Map\ProductTableMap; -use Thelia\Model\ProductSaleElementsQuery; + class Product extends BaseProduct { diff --git a/core/lib/Thelia/Model/RewritingUrl.php b/core/lib/Thelia/Model/RewritingUrl.php index a13777c41..a8fc84d28 100644 --- a/core/lib/Thelia/Model/RewritingUrl.php +++ b/core/lib/Thelia/Model/RewritingUrl.php @@ -5,7 +5,7 @@ namespace Thelia\Model; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Connection\ConnectionInterface; use Thelia\Model\Base\RewritingUrl as BaseRewritingUrl; -use Thelia\Model\RewritingUrlQuery; + class RewritingUrl extends BaseRewritingUrl { diff --git a/core/lib/Thelia/Model/TaxRuleQuery.php b/core/lib/Thelia/Model/TaxRuleQuery.php index d68ad7ef2..064ec467a 100644 --- a/core/lib/Thelia/Model/TaxRuleQuery.php +++ b/core/lib/Thelia/Model/TaxRuleQuery.php @@ -5,7 +5,7 @@ namespace Thelia\Model; use Propel\Runtime\ActiveQuery\Criteria; use Thelia\Model\Base\TaxRuleQuery as BaseTaxRuleQuery; use Thelia\Model\Map\TaxRuleCountryTableMap; -use Thelia\Model\Map\TaxTableMap; + /** * Skeleton subclass for performing query and update operations on the 'tax_rule' table. diff --git a/core/lib/Thelia/TaxEngine/TaxEngine.php b/core/lib/Thelia/TaxEngine/TaxEngine.php index bfa447d23..62a8b2f68 100644 --- a/core/lib/Thelia/TaxEngine/TaxEngine.php +++ b/core/lib/Thelia/TaxEngine/TaxEngine.php @@ -57,8 +57,8 @@ class TaxEngine * Add a directroy which contains tax types classes. The tax engine * will scan this directory, and add all the tax type classes. * - * @param unknown $namespace the namespace of the classes in the directory - * @param unknown $path_to_tax_type_classes the path to the directory + * @param string $namespace the namespace of the classes in the directory + * @param string $path_to_tax_type_classes the path to the directory */ public function addTaxTypeDirectory($namespace, $path_to_tax_type_classes) { diff --git a/core/lib/Thelia/Tests/Action/AddressTest.php b/core/lib/Thelia/Tests/Action/AddressTest.php index 9c4198c06..ba567bb60 100644 --- a/core/lib/Thelia/Tests/Action/AddressTest.php +++ b/core/lib/Thelia/Tests/Action/AddressTest.php @@ -26,7 +26,7 @@ namespace Thelia\Tests\Action; use Thelia\Action\Address; use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent; use Thelia\Model\Base\CustomerQuery; -use Thelia\Tests\Action\BaseAction; + /** * @@ -36,7 +36,7 @@ use Thelia\Tests\Action\BaseAction; * @package Thelia\Tests\Action * @author Manuel Raynaud */ -class AddressTest extends BaseAction +class AddressTest extends \PHPUnit_Framework_TestCase { public function testCreatedAddress() @@ -59,8 +59,9 @@ class AddressTest extends BaseAction "" ); $AddressCreateOrUpdateEvent->setCustomer($customer); + $AddressCreateOrUpdateEvent->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); - $actionAddress = new Address($this->getContainer()); + $actionAddress = new Address(); $actionAddress->create($AddressCreateOrUpdateEvent); $createdAddress = $AddressCreateOrUpdateEvent->getAddress(); @@ -106,8 +107,9 @@ class AddressTest extends BaseAction "" ); $addressEvent->setAddress($address); + $addressEvent->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); - $actionAddress = new Address($this->getContainer()); + $actionAddress = new Address(); $actionAddress->update($addressEvent); $updatedAddress = $addressEvent->getAddress(); diff --git a/core/lib/Thelia/Tests/Action/AdministratorTest.php b/core/lib/Thelia/Tests/Action/AdministratorTest.php new file mode 100644 index 000000000..bfaee0d6b --- /dev/null +++ b/core/lib/Thelia/Tests/Action/AdministratorTest.php @@ -0,0 +1,143 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Thelia\Action\Administrator; +use Thelia\Core\Event\Administrator\AdministratorEvent; +use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent; +use Thelia\Model\AdminQuery; +use Thelia\Model\LangQuery; + + +/** + * Class AdministratorTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class AdministratorTest extends \PHPUnit_Framework_TestCase +{ + + public function testCreate() + { + $login = 'thelia'.uniqid(); + $locale = LangQuery::create()->findOne()->getLocale(); + $adminEvent = new AdministratorEvent(); + $adminEvent + ->setFirstname('thelia') + ->setLastname('thelia') + ->setLogin($login) + ->setPassword('azerty') + ->setLocale($locale) + ->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")) + ; + + $admin = new Administrator(); + $admin->create($adminEvent); + + $createdAdmin = $adminEvent->getAdministrator(); + + $this->assertInstanceOf("Thelia\Model\Admin", $createdAdmin); + $this->assertFalse($createdAdmin->isNew()); + + $this->assertEquals($adminEvent->getFirstname(), $createdAdmin->getFirstname()); + $this->assertEquals($adminEvent->getLastname(), $createdAdmin->getLastname()); + $this->assertEquals($adminEvent->getLogin(), $createdAdmin->getLogin()); + $this->assertEquals($adminEvent->getLocale(), $createdAdmin->getLocale()); + $this->assertEquals($adminEvent->getProfile(), $createdAdmin->getProfileId()); + $this->assertTrue(password_verify($adminEvent->getPassword(), $createdAdmin->getPassword())); + } + + public function testUpdate() + { + $admin = AdminQuery::create()->findOne(); + + $login = 'thelia'.uniqid(); + $locale = LangQuery::create()->findOne()->getLocale(); + $adminEvent = new AdministratorEvent(); + $adminEvent + ->setId($admin->getId()) + ->setFirstname('thelia_update') + ->setLastname('thelia_update') + ->setLogin($login) + ->setPassword('azertyuiop') + ->setLocale($locale) + ->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")) + ; + + $actionAdmin = new Administrator(); + $actionAdmin->update($adminEvent); + + $updatedAdmin = $adminEvent->getAdministrator(); + + $this->assertInstanceOf("Thelia\Model\Admin", $updatedAdmin); + $this->assertFalse($updatedAdmin->isNew()); + + $this->assertEquals($adminEvent->getFirstname(), $updatedAdmin->getFirstname()); + $this->assertEquals($adminEvent->getLastname(), $updatedAdmin->getLastname()); + $this->assertEquals($adminEvent->getLogin(), $updatedAdmin->getLogin()); + $this->assertEquals($adminEvent->getLocale(), $updatedAdmin->getLocale()); + $this->assertEquals($adminEvent->getProfile(), $updatedAdmin->getProfileId()); + $this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword())); + } + + public function testDelete() + { + $admin = AdminQuery::create()->findOne(); + + $adminEvent = new AdministratorEvent(); + + $adminEvent + ->setId($admin->getId()) + ->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")) + ; + + $actionAdmin = new Administrator(); + $actionAdmin->delete($adminEvent); + + $deletedAdmin = $adminEvent->getAdministrator(); + + $this->assertInstanceOf("Thelia\Model\Admin", $deletedAdmin); + $this->assertTrue($deletedAdmin->isDeleted()); + } + + public function testUpdatePassword() + { + $admin = AdminQuery::create()->findOne(); + + $adminEvent = new AdministratorUpdatePasswordEvent($admin); + $adminEvent + ->setPassword('toto') + ->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $actionAdmin = new Administrator(); + $actionAdmin->updatePassword($adminEvent); + + $updatedAdmin = $adminEvent->getAdmin(); + + $this->assertInstanceOf("Thelia\Model\Admin", $updatedAdmin); + $this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword())); + } + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Action/AreaTest.php b/core/lib/Thelia/Tests/Action/AreaTest.php new file mode 100644 index 000000000..bfc756e5b --- /dev/null +++ b/core/lib/Thelia/Tests/Action/AreaTest.php @@ -0,0 +1,152 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Thelia\Action\Area; +use Thelia\Core\Event\Area\AreaAddCountryEvent; +use Thelia\Core\Event\Area\AreaCreateEvent; +use Thelia\Core\Event\Area\AreaDeleteEvent; +use Thelia\Core\Event\Area\AreaRemoveCountryEvent; +use Thelia\Core\Event\Area\AreaUpdatePostageEvent; +use Thelia\Model\Area as AreaModel; +use Thelia\Model\CountryQuery; + + +/** + * Class AreaTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class AreaTest extends \PHPUnit_Framework_TestCase +{ + + public function testCreate() + { + $event = new AreaCreateEvent(); + $event + ->setAreaName('foo') + ->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $areaAction = new Area(); + $areaAction->create($event); + + $createdArea = $event->getArea(); + + $this->assertInstanceOf('Thelia\Model\Area', $createdArea); + $this->assertFalse($createdArea->isNew()); + $this->assertTrue($event->hasArea()); + + $this->assertEquals('foo', $createdArea->getName()); + + return $createdArea; + } + + /** + * @param AreaModel $area + * @depends testCreate + */ + public function testUpdatePostage(AreaModel $area) + { + $event = new AreaUpdatePostageEvent($area->getId()); + $event + ->setPostage(20) + ->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $areaAction = new Area(); + $areaAction->updatePostage($event); + + $updatedArea = $event->getArea(); + + $this->assertInstanceOf('Thelia\Model\Area', $updatedArea); + $this->assertEquals(20, $updatedArea->getPostage()); + + return $updatedArea; + + } + + /** + * @param AreaModel $area + * @depends testUpdatePostage + */ + public function testAddCountry(AreaModel $area) + { + $country = CountryQuery::create()->findOne(); + + $event = new AreaAddCountryEvent($area->getId(), $country->getId()); + $event->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $areaAction = new Area(); + $areaAction->addCountry($event); + + $updatedArea = $event->getArea(); + + $updatedCountry = CountryQuery::create()->findOneByAreaId($updatedArea->getId()); + + $this->assertInstanceOf('Thelia\Model\Area', $updatedArea); + $this->assertEquals($country->getId(), $updatedCountry->getId()); + + return $updatedArea; + } + + /** + * @param AreaModel $area + * @depends testAddCountry + */ + public function testRemoveCountry(AreaModel $area) + { + $country = CountryQuery::create()->filterByArea($area)->find()->getFirst(); + + $event = new AreaRemoveCountryEvent($area->getId(), $country->getId()); + $event->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $areaAction = new Area(); + $areaAction->removeCountry($event); + + $updatedCountry = CountryQuery::create()->findPk($country->getId()); + $updatedArea = $event->getArea(); + + $this->assertInstanceOf('Thelia\Model\Area', $updatedArea); + $this->assertNull($updatedCountry->getAreaId()); + + return $event->getArea(); + } + + /** + * @depends testRemoveCountry + */ + public function testDelete(AreaModel $area) + { + $event = new AreaDeleteEvent($area->getId()); + $event->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $areaAction = new Area(); + $areaAction->delete($event); + + $deletedArea = $event->getArea(); + + $this->assertInstanceOf('Thelia\Model\Area', $deletedArea); + $this->assertTrue($deletedArea->isDeleted()); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Action/AttributeAvTest.php b/core/lib/Thelia/Tests/Action/AttributeAvTest.php new file mode 100644 index 000000000..0a8c6564a --- /dev/null +++ b/core/lib/Thelia/Tests/Action/AttributeAvTest.php @@ -0,0 +1,120 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Thelia\Action\AttributeAv; +use Thelia\Core\Event\Attribute\AttributeAvCreateEvent; +use Thelia\Core\Event\Attribute\AttributeAvDeleteEvent; +use Thelia\Core\Event\Attribute\AttributeAvUpdateEvent; +use Thelia\Model\AttributeQuery; +use Thelia\Model\AttributeAv as AttributeAvModel; + + +/** + * Class AttributeAvTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class AttributeAvTest extends \PHPUnit_Framework_TestCase +{ + + public function testCreate() + { + $attribute = AttributeQuery::create()->findOne(); + + $event = new AttributeAvCreateEvent(); + + $event + ->setAttributeId($attribute->getId()) + ->setLocale('en_US') + ->setTitle('foo') + ->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $action = new AttributeAv(); + $action->create($event); + + $attributeAvCreated = $event->getAttributeAv(); + + $this->assertInstanceOf('Thelia\Model\AttributeAv', $attributeAvCreated); + + $this->assertEquals('en_US', $attributeAvCreated->getLocale()); + $this->assertEquals('foo', $attributeAvCreated->getTitle()); + $this->assertNull($attributeAvCreated->getDescription()); + $this->assertNull($attributeAvCreated->getPostscriptum()); + $this->assertNull($attributeAvCreated->getChapo()); + $this->assertEquals($attribute, $attributeAvCreated->getAttribute()); + + return $attributeAvCreated; + } + + /** + * @param AttributeAvModel $attributeAv + * @depends testCreate + */ + public function testUpdate(AttributeAvModel $attributeAv) + { + $event = new AttributeAvUpdateEvent($attributeAv->getId()); + + $event + ->setLocale($attributeAv->getLocale()) + ->setTitle('bar') + ->setDescription('bar description') + ->setChapo('bar chapo') + ->setPostscriptum('bar postscriptum') + ->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")) + ; + + $action = new AttributeAv(); + $action->update($event); + + $updatedAttributeAv = $event->getAttributeAv(); + + $this->assertInstanceOf('Thelia\Model\AttributeAv', $updatedAttributeAv); + + $this->assertEquals('bar', $updatedAttributeAv->getTitle()); + $this->assertEquals('bar description', $updatedAttributeAv->getDescription()); + $this->assertEquals('bar chapo', $updatedAttributeAv->getChapo()); + $this->assertEquals('bar postscriptum', $updatedAttributeAv->getPostscriptum()); + + return $updatedAttributeAv; + } + + /** + * @depends testUpdate + */ + public function testDelete(AttributeAvModel $attributeAv) + { + $event = new AttributeAvDeleteEvent($attributeAv->getId()); + $event->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $action = new AttributeAv(); + $action->delete($event); + + $deletedAttributeAv = $event->getAttributeAv(); + + $this->assertInstanceOf('Thelia\Model\AttributeAv', $deletedAttributeAv); + $this->assertTrue($deletedAttributeAv->isDeleted()); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Action/AttributeTest.php b/core/lib/Thelia/Tests/Action/AttributeTest.php new file mode 100644 index 000000000..d5fdd9ead --- /dev/null +++ b/core/lib/Thelia/Tests/Action/AttributeTest.php @@ -0,0 +1,111 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Thelia\Action\Attribute; +use Thelia\Core\Event\Attribute\AttributeDeleteEvent; +use Thelia\Core\Event\Attribute\AttributeUpdateEvent; +use Thelia\Model\Attribute as AttributeModel; +use Thelia\Core\Event\Attribute\AttributeCreateEvent; + + +/** + * Class AttributeTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class AttributeTest extends \PHPUnit_Framework_TestCase +{ + + public function testCreateSimple() + { + $event = new AttributeCreateEvent(); + + $event + ->setLocale('en_US') + ->setTitle('foo') + ->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $action = new Attribute(); + $action->create($event); + + $createdAttribute = $event->getAttribute(); + + $this->assertInstanceOf('Thelia\Model\Attribute', $createdAttribute); + $this->assertEquals($createdAttribute->getLocale(), 'en_US'); + $this->assertEquals($createdAttribute->getTitle(), 'foo'); + + return $createdAttribute; + + } + + /** + * @param AttributeModel $attribute + * @depends testCreateSimple + */ + public function testUpdate(AttributeModel $attribute) + { + $event = new AttributeUpdateEvent($attribute->getId()); + + $event + ->setLocale($attribute->getLocale()) + ->setTitle('bar') + ->setDescription('bar description') + ->setChapo('bar chapo') + ->setPostscriptum('bar postscriptum') + ->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $action = new Attribute(); + $action->update($event); + + $updatedAttribute = $event->getAttribute(); + + $this->assertInstanceOf('Thelia\Model\Attribute', $updatedAttribute); + $this->assertEquals('en_US', $updatedAttribute->getLocale()); + $this->assertEquals('bar', $updatedAttribute->getTitle()); + $this->assertEquals('bar description', $updatedAttribute->getDescription()); + $this->assertEquals('bar chapo', $updatedAttribute->getChapo()); + $this->assertEquals('bar postscriptum', $updatedAttribute->getPostscriptum()); + + return $updatedAttribute; + } + + /** + * @depends testUpdate + */ + public function testDelete(AttributeModel $attribute) + { + $event = new AttributeDeleteEvent($attribute->getId()); + $event->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $action = new Attribute(); + $action->delete($event); + + $deletedAttribute = $event->getAttribute(); + + $this->assertInstanceOf('Thelia\Model\Attribute', $deletedAttribute); + $this->assertTrue($deletedAttribute->isDeleted()); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Action/CacheTest.php b/core/lib/Thelia/Tests/Action/CacheTest.php new file mode 100644 index 000000000..5768581e5 --- /dev/null +++ b/core/lib/Thelia/Tests/Action/CacheTest.php @@ -0,0 +1,59 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Symfony\Component\Filesystem\Filesystem; +use Thelia\Action\Cache; +use Thelia\Core\Event\Cache\CacheEvent; + + +/** + * Class CacheTest + * @package Thelia\Tests\Action\assets + * @author Manuel Raynaud + */ +class CacheTest extends \PHPUnit_Framework_TestCase +{ + + protected $dir; + + public function setUp() + { + $this->dir = __DIR__ . '/test'; + + $fs = new Filesystem(); + $fs->mkdir($this->dir); + } + + public function testCacheClear() + { + $event = new CacheEvent($this->dir); + + $action = new Cache(); + $action->cacheClear($event); + + $fs = new Filesystem(); + $this->assertFalse($fs->exists($this->dir)); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Action/CategoryTest.php b/core/lib/Thelia/Tests/Action/CategoryTest.php new file mode 100644 index 000000000..50d60f01a --- /dev/null +++ b/core/lib/Thelia/Tests/Action/CategoryTest.php @@ -0,0 +1,197 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Routing\Router; +use Thelia\Action\Category; +use Thelia\Core\Event\Category\CategoryDeleteEvent; +use Thelia\Core\Event\Category\CategoryUpdateEvent; +use Thelia\Core\Event\UpdateSeoEvent; +use Thelia\Model\Category as CategoryModel; +use Thelia\Core\Event\Category\CategoryCreateEvent; +use Thelia\Model\CategoryQuery; +use Thelia\Tests\TestCaseWithURLToolSetup; +use Thelia\Tools\URL; + + +/** + * Class CategoryTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class CategoryTest extends TestCaseWithURLToolSetup +{ + + protected function getRandomCategory() + { + $category = CategoryQuery::create() + ->addAscendingOrderByColumn('RAND()') + ->findOne(); + + if (null === $category) { + $this->fail('use fixtures before launching test, there is no category in database'); + } + + return $category; + } + + public function getUpdateEvent(&$category) + { + if (!$category instanceof \Thelia\Model\Category) { + $category = $this->getRandomCategory(); + } + + $event = new CategoryUpdateEvent($category->getId()); + + $event + ->setLocale('en_US') + ->setTitle('bar') + ->setDescription('bar description') + ->setChapo('bar chapo') + ->setPostscriptum('bar postscriptum') + ->setVisible(0) + ->setParent(0) + ->setDispatcher($this->getDispatcher()) + ; + } + + public function getUpdateSeoEvent(&$category) + { + if (!$category instanceof \Thelia\Model\Category) { + $category = $this->getRandomCategory(); + } + + $event = new UpdateSeoEvent($category->getId()); + $event->setDispatcher($this->getDispatcher()); + $event + ->setLocale($category->getLocale()) + ->setMetaTitle($category->getMetaTitle()) + ->setMetaDescription($category->getMetaDescription()) + ->setMetaKeywords($category->getMetaKeywords()); + + return $event; + } + + public function processUpdateAction($event) + { + $action = new Category(); + $action->update($event); + + return $event->getCategory(); + } + + public function processUpdateSeoAction($event) + { + $action = new Category(); + + return $action->updateSeo($event); + + } + + public function testCreate() + { + $event = new CategoryCreateEvent(); + + $event + ->setLocale('en_US') + ->setParent(0) + ->setTitle('foo') + ->setVisible(1) + ->setDispatcher($this->getDispatcher()); + + $action = new Category(); + $action->create($event); + + $createdCategory = $event->getCategory(); + + $this->assertInstanceOf('Thelia\Model\Category', $createdCategory); + + $this->assertFalse($createdCategory->isNew()); + + $this->assertEquals('en_US', $createdCategory->getLocale()); + $this->assertEquals('foo', $createdCategory->getTitle()); + $this->assertEquals(1, $createdCategory->getVisible()); + $this->assertEquals(0, $createdCategory->getParent()); + $this->assertNull($createdCategory->getDescription()); + $this->assertNull($createdCategory->getChapo()); + $this->assertNull($createdCategory->getPostscriptum()); + + return $createdCategory; + } + + /** + * @param CategoryModel $category + * @depends testCreate + */ + public function testUpdate(CategoryModel $category) + { + $event = new CategoryUpdateEvent($category->getId()); + + $event + ->setLocale('en_US') + ->setTitle('bar') + ->setDescription('bar description') + ->setChapo('bar chapo') + ->setPostscriptum('bar postscriptum') + ->setVisible(0) + ->setParent(0) + ->setDispatcher($this->getDispatcher()) + ; + + $action = new Category(); + $action->update($event); + + $updatedCategory = $event->getCategory(); + + $this->assertInstanceOf('Thelia\Model\Category', $updatedCategory); + + $this->assertEquals('en_US', $updatedCategory->getLocale()); + $this->assertEquals('bar', $updatedCategory->getTitle()); + $this->assertEquals('bar description', $updatedCategory->getDescription()); + $this->assertEquals('bar chapo', $updatedCategory->getChapo()); + $this->assertEquals('bar postscriptum', $updatedCategory->getPostscriptum()); + $this->assertEquals(0, $updatedCategory->getVisible()); + $this->assertEquals(0, $updatedCategory->getParent()); + + return $updatedCategory; + } + + /** + * @depends testUpdate + */ + public function testDelete(CategoryModel $category) + { + $event = new CategoryDeleteEvent($category->getId()); + $event->setDispatcher($this->getDispatcher()); + + $action = new Category(); + $action->delete($event); + + $deletedCategory = $event->getCategory(); + + $this->assertInstanceOf('Thelia\Model\Category', $deletedCategory); + $this->assertTrue($deletedCategory->isDeleted()); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Action/ContentTest.php b/core/lib/Thelia/Tests/Action/ContentTest.php index 1eca7d2ea..08e41815b 100644 --- a/core/lib/Thelia/Tests/Action/ContentTest.php +++ b/core/lib/Thelia/Tests/Action/ContentTest.php @@ -23,6 +23,7 @@ namespace Thelia\Tests\Action; use Propel\Runtime\ActiveQuery\Criteria; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Thelia\Action\Content; use Thelia\Core\Event\Content\ContentAddFolderEvent; use Thelia\Core\Event\Content\ContentCreateEvent; @@ -44,6 +45,15 @@ use Thelia\Tests\TestCaseWithURLToolSetup; */ class ContentTest extends TestCaseWithURLToolSetup { + /** + * @var EventDispatcherInterface + */ + protected $dispatcher; + + public function setUp() + { + $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + } public function getUpdateEvent(&$content) { @@ -52,6 +62,7 @@ class ContentTest extends TestCaseWithURLToolSetup } $event = new ContentUpdateEvent($content->getId()); + $event->setDispatcher($this->dispatcher); $event ->setVisible(1) ->setLocale($content->getLocale()) @@ -78,6 +89,7 @@ class ContentTest extends TestCaseWithURLToolSetup $folder = $this->getRandomFolder(); $event = new ContentCreateEvent(); + $event->setDispatcher($this->dispatcher); $event ->setVisible(1) ->setLocale('en_US') @@ -103,6 +115,7 @@ class ContentTest extends TestCaseWithURLToolSetup $folder = $this->getRandomFolder(); $event = new ContentUpdateEvent($content->getId()); + $event->setDispatcher($this->dispatcher); $event ->setVisible(1) ->setLocale('en_US') @@ -132,6 +145,7 @@ class ContentTest extends TestCaseWithURLToolSetup $content = $this->getRandomContent(); $event = new ContentDeleteEvent($content->getId()); + $event->setDispatcher($this->dispatcher); $contentAction = new Content($this->getContainer()); $contentAction->delete($event); @@ -150,6 +164,7 @@ class ContentTest extends TestCaseWithURLToolSetup $visibility = $content->getVisible(); $event = new ContentToggleVisibilityEvent($content); + $event->setDispatcher($this->dispatcher); $contentAction = new Content($this->getContainer()); $contentAction->toggleVisibility($event); @@ -173,6 +188,7 @@ class ContentTest extends TestCaseWithURLToolSetup $newPosition = $content->getPosition()-1; $event = new UpdatePositionEvent($content->getId(), UpdatePositionEvent::POSITION_UP); + $event->setDispatcher($this->dispatcher); $contentAction = new Content($this->getContainer()); $contentAction->updatePosition($event); @@ -195,6 +211,7 @@ class ContentTest extends TestCaseWithURLToolSetup $newPosition = $content->getPosition()+1; $event = new UpdatePositionEvent($content->getId(), UpdatePositionEvent::POSITION_DOWN); + $event->setDispatcher($this->dispatcher); $contentAction = new Content($this->getContainer()); $contentAction->updatePosition($event); @@ -215,6 +232,7 @@ class ContentTest extends TestCaseWithURLToolSetup } $event = new UpdatePositionEvent($content->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, 1); + $event->setDispatcher($this->dispatcher); $contentAction = new Content($this->getContainer()); $contentAction->updatePosition($event); @@ -237,6 +255,7 @@ class ContentTest extends TestCaseWithURLToolSetup } while ($test->count() > 0); $event = new ContentAddFolderEvent($content, $folder->getId()); + $event->setDispatcher($this->dispatcher); $contentAction = new Content($this->getContainer()); $contentAction->addFolder($event); @@ -260,6 +279,7 @@ class ContentTest extends TestCaseWithURLToolSetup public function testRemoveFolder(ContentFolder $association) { $event = new ContentRemoveFolderEvent($association->getContent(), $association->getFolder()->getId()); + $event->setDispatcher($this->dispatcher); $contentAction = new Content($this->getContainer()); $contentAction->removeFolder($event); diff --git a/core/lib/Thelia/Tests/Action/CustomerTest.php b/core/lib/Thelia/Tests/Action/CustomerTest.php index 396eb5257..21918d79d 100644 --- a/core/lib/Thelia/Tests/Action/CustomerTest.php +++ b/core/lib/Thelia/Tests/Action/CustomerTest.php @@ -24,6 +24,9 @@ namespace Thelia\Tests\Action\ImageTest; use Thelia\Action\Customer; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; +use Thelia\Core\HttpFoundation\Request; +use Thelia\Core\Security\SecurityContext; +use Thelia\Model\CustomerQuery; /** * Class CustomerTest @@ -32,15 +35,12 @@ use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; */ class CustomerTest extends \PHPUnit_Framework_TestCase { - public function getContainer() + + public static function setUpBeforeClass() { - $container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); - - $dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); - - $container->set("event_dispatcher", $dispatcher); - - return $container; + CustomerQuery::create() + ->filterByRef('testRef') + ->delete(); } public function testCreatedCustomer() @@ -67,7 +67,9 @@ class CustomerTest extends \PHPUnit_Framework_TestCase null ); - $customerAction = new Customer($this->getContainer()); + $customerCreateEvent->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $customerAction = new Customer(new SecurityContext(new Request())); $customerAction->create($customerCreateEvent); @@ -126,7 +128,9 @@ class CustomerTest extends \PHPUnit_Framework_TestCase 'testRef' ); - $customerAction = new Customer($this->getContainer()); + $customerCreateEvent->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); + + $customerAction = new Customer(new SecurityContext(new Request())); $customerAction->create($customerCreateEvent); diff --git a/core/lib/Thelia/Tests/Action/FolderTest.php b/core/lib/Thelia/Tests/Action/FolderTest.php index cbf9a7c1e..96e07ed52 100644 --- a/core/lib/Thelia/Tests/Action/FolderTest.php +++ b/core/lib/Thelia/Tests/Action/FolderTest.php @@ -43,6 +43,16 @@ class FolderTest extends TestCaseWithURLToolSetup { use RewrittenUrlTestTrait; + /** + * @var EventDispatcherInterface + */ + protected $dispatcher; + + public function setUp() + { + $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + } + public function getUpdateEvent(&$folder) { if (!$folder instanceof \Thelia\Model\Folder) { @@ -50,6 +60,7 @@ class FolderTest extends TestCaseWithURLToolSetup } $event = new FolderUpdateEvent($folder->getId()); + $event->setDispatcher($this->dispatcher); $event ->setVisible(1) ->setLocale($folder->getLocale()) @@ -70,7 +81,7 @@ class FolderTest extends TestCaseWithURLToolSetup } $event = new UpdateSeoEvent($folder->getId()); - + $event->setDispatcher($this->dispatcher); $event ->setLocale($folder->getLocale()) ->setMetaTitle($folder->getMetaTitle()) @@ -82,14 +93,14 @@ class FolderTest extends TestCaseWithURLToolSetup public function processUpdateSeoAction($event) { - $contentAction = new Folder($this->getContainer()); + $contentAction = new Folder(); return $contentAction->updateSeo($event); } public function processUpdateAction($event) { - $contentAction = new Folder($this->getContainer()); + $contentAction = new Folder(); $contentAction->update($event); return $event->getFolder(); @@ -103,13 +114,14 @@ class FolderTest extends TestCaseWithURLToolSetup { $event = new FolderCreateEvent(); + $event->setDispatcher($this->dispatcher); $event ->setParent(0) ->setVisible(1) ->setLocale('en_US') ->setTitle('folder creation test'); - $folderAction = new Folder($this->getContainer()); + $folderAction = new Folder(); $folderAction->create($event); @@ -131,7 +143,7 @@ class FolderTest extends TestCaseWithURLToolSetup $visible = !$folder->getVisible(); $event = new FolderUpdateEvent($folder->getId()); - + $event->setDispatcher($this->dispatcher); $event ->setLocale('en_US') ->setTitle('test update folder') @@ -142,7 +154,7 @@ class FolderTest extends TestCaseWithURLToolSetup ->setParent(0) ; - $folderAction = new Folder($this->getContainer()); + $folderAction = new Folder(); $folderAction->update($event); $updatedFolder = $event->getFolder(); @@ -165,8 +177,8 @@ class FolderTest extends TestCaseWithURLToolSetup $folder = $this->getRandomFolder(); $event = new FolderDeleteEvent($folder->getId()); - - $folderAction = new Folder($this->getContainer()); + $event->setDispatcher($this->dispatcher); + $folderAction = new Folder(); $folderAction->delete($event); $deletedFolder = $event->getFolder(); @@ -185,8 +197,9 @@ class FolderTest extends TestCaseWithURLToolSetup $visible = $folder->getVisible(); $event = new FolderToggleVisibilityEvent($folder); + $event->setDispatcher($this->dispatcher); - $folderAction = new Folder($this->getContainer()); + $folderAction = new Folder(); $folderAction->toggleVisibility($event); $updatedFolder = $event->getFolder(); @@ -208,8 +221,9 @@ class FolderTest extends TestCaseWithURLToolSetup $newPosition = $folder->getPosition()-1; $event = new UpdatePositionEvent($folder->getId(), UpdatePositionEvent::POSITION_UP); + $event->setDispatcher($this->dispatcher); - $folderAction = new Folder($this->getContainer()); + $folderAction = new Folder(); $folderAction->updatePosition($event); $updatedFolder = FolderQuery::create()->findPk($folder->getId()); @@ -239,8 +253,9 @@ class FolderTest extends TestCaseWithURLToolSetup $newPosition = $folder->getPosition()+1; $event = new UpdatePositionEvent($folder->getId(), UpdatePositionEvent::POSITION_DOWN); + $event->setDispatcher($this->dispatcher); - $folderAction = new Folder($this->getContainer()); + $folderAction = new Folder(); $folderAction->updatePosition($event); $updatedFolder = FolderQuery::create()->findPk($folder->getId()); @@ -259,8 +274,9 @@ class FolderTest extends TestCaseWithURLToolSetup } $event = new UpdatePositionEvent($folder->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, 1); + $event->setDispatcher($this->dispatcher); - $folderAction = new Folder($this->getContainer()); + $folderAction = new Folder(); $folderAction->updatePosition($event); $updatedFolder = FolderQuery::create()->findPk($folder->getId()); diff --git a/core/lib/Thelia/Tests/Action/OrderTest.php b/core/lib/Thelia/Tests/Action/OrderTest.php index f2fd00a32..41cd7cbac 100644 --- a/core/lib/Thelia/Tests/Action/OrderTest.php +++ b/core/lib/Thelia/Tests/Action/OrderTest.php @@ -30,11 +30,14 @@ use Thelia\Core\Event\Order\OrderEvent; use Thelia\Core\HttpFoundation\Request; use Thelia\Core\HttpFoundation\Session\Session; use Thelia\Core\Security\SecurityContext; +use Thelia\Core\Template\ParserContext; +use Thelia\Core\Template\Smarty\SmartyParser; +use Thelia\Mailer\MailerFactory; use Thelia\Model\AddressQuery; use Thelia\Model\Base\OrderAddressQuery; use Thelia\Model\Base\OrderProductQuery; use Thelia\Model\Base\OrderQuery; -use Thelia\Model\OrderAddress; + use Thelia\Model\OrderStatus; use Thelia\Model\ProductSaleElementsQuery; use Thelia\Model\Cart; @@ -85,25 +88,42 @@ class OrderTest extends \PHPUnit_Framework_TestCase */ protected $cartItems; + /** + * @var SecurityContext + */ + protected $securityContext; + + protected $request; + public function setUp() { - $container = new ContainerBuilder(); $session = new Session(new MockArraySessionStorage()); - $request = new Request(); + $dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); - $request->setSession($session); + $this->request = new Request(); + $this->request->setSession($session); - $container->set("event_dispatcher", $dispatcher); - $container->set('request', $request); - $container->set('thelia.securityContext', new SecurityContext($request)); + $this->securityContext = new SecurityContext($this->request); - $this->container = $container; + $this->container = new ContainerBuilder(); + + $this->container->set("event_dispatcher", $dispatcher); + $this->container->set('request', $this->request); $this->orderEvent = new OrderEvent(new OrderModel()); - $this->orderAction = new Order($this->container); + $this->orderEvent->setDispatcher($dispatcher); + + // public function __construct(Request $this->request, ParserInterface $parser, MailerFactory $mailer, SecurityContext $securityContext) + + $this->orderAction = new Order( + $this->request, + new SmartyParser($this->request, $dispatcher, new ParserContext($this->request)), + new MailerFactory($dispatcher), + $this->securityContext + ); /* load customer */ $this->customer = $this->loadCustomer(); @@ -123,7 +143,7 @@ class OrderTest extends \PHPUnit_Framework_TestCase return null; } - $this->container->get('thelia.securityContext')->setCustomerUser($customer); + $this->securityContext->setCustomerUser($customer); return $customer; } @@ -172,7 +192,7 @@ class OrderTest extends \PHPUnit_Framework_TestCase $this->cartItems[] = $cartItem; } - $this->container->get('request')->getSession()->setCart($cart->getId()); + $this->request->getSession()->setCart($cart->getId()); return $cart; } @@ -319,7 +339,7 @@ class OrderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(OrderStatus::CODE_NOT_PAID, $placedOrder->getOrderStatus()->getCode(), 'status does not match'); /* check lang */ - $this->assertEquals($this->container->get('request')->getSession()->getLang()->getId(), $placedOrder->getLangId(), 'lang does not match'); + $this->assertEquals($this->request->getSession()->getLang()->getId(), $placedOrder->getLangId(), 'lang does not match'); /* check ordered product */ foreach ($this->cartItems as $index => $cartItem) { diff --git a/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php b/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php index 3d5e757d1..4891e8b96 100644 --- a/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php +++ b/core/lib/Thelia/Tests/Action/RewrittenUrlTestTrait.php @@ -29,6 +29,7 @@ trait RewrittenUrlTestTrait { $object = null; $event = $this->getUpdateSeoEvent($object); + $event->setDispatcher($this->dispatcher); /* get an existing url */ $existingUrl = RewritingUrlQuery::create() @@ -50,6 +51,7 @@ trait RewrittenUrlTestTrait { $object = null; $event = $this->getUpdateSeoEvent($object); + $event->setDispatcher($this->dispatcher); $currentUrl = $object->getRewrittenUrl($object->getLocale()); diff --git a/core/lib/Thelia/Tests/Cart/CartTraitTest.php b/core/lib/Thelia/Tests/Cart/CartTraitTest.php index 039e4448e..a1531e2a1 100755 --- a/core/lib/Thelia/Tests/Cart/CartTraitTest.php +++ b/core/lib/Thelia/Tests/Cart/CartTraitTest.php @@ -47,6 +47,8 @@ class CartTraitTest extends \PHPUnit_Framework_TestCase protected $uniqid; + protected $dispatcher; + public function getContainer() { $container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); @@ -67,6 +69,8 @@ class CartTraitTest extends \PHPUnit_Framework_TestCase $this->uniqid = uniqid('', true); + $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + $this->cartTrait = new MockCartTrait($this->uniqid, $this->getContainer()); } @@ -79,7 +83,7 @@ class CartTraitTest extends \PHPUnit_Framework_TestCase { $cartTrait = $this->cartTrait; - $cart = $cartTrait->getCart($this->request); + $cart = $cartTrait->getCart($this->dispatcher, $this->request); $this->assertInstanceOf("Thelia\Model\Cart", $cart, '$cart must be an instance of cart model Thelia\Model\Cart'); $this->assertNull($cart->getCustomerId()); @@ -109,7 +113,7 @@ class CartTraitTest extends \PHPUnit_Framework_TestCase $request->getSession()->setCustomerUser($customer); - $cart = $cartTrait->getCart($request); + $cart = $cartTrait->getCart($this->dispatcher, $request); $this->assertInstanceOf("Thelia\Model\Cart", $cart, '$cart must be an instance of cart model Thelia\Model\Cart'); $this->assertNotNull($cart->getCustomerId()); $this->assertEquals($customer->getId(), $cart->getCustomerId()); @@ -137,7 +141,7 @@ class CartTraitTest extends \PHPUnit_Framework_TestCase $request->cookies->set("thelia_cart", $uniqid); - $getCart = $cartTrait->getCart($request); + $getCart = $cartTrait->getCart($this->dispatcher, $request); $this->assertInstanceOf("Thelia\Model\Cart", $getCart, '$cart must be an instance of cart model Thelia\Model\Cart'); $this->assertNull($getCart->getCustomerId()); $this->assertNull($getCart->getAddressDeliveryId()); @@ -159,7 +163,7 @@ class CartTraitTest extends \PHPUnit_Framework_TestCase $token = "WrongToken"; $request->cookies->set("thelia_cart", $token); - $cart = $cartTrait->getCart($request); + $cart = $cartTrait->getCart($this->dispatcher, $request); $this->assertInstanceOf("Thelia\Model\Cart", $cart, '$cart must be an instance of cart model Thelia\Model\Cart'); $this->assertNull($cart->getCustomerId()); $this->assertNull($cart->getAddressDeliveryId()); @@ -196,7 +200,7 @@ class CartTraitTest extends \PHPUnit_Framework_TestCase $request->getSession()->setCustomerUser($customer); - $getCart = $cartTrait->getCart($request); + $getCart = $cartTrait->getCart($this->dispatcher, $request); $this->assertInstanceOf("Thelia\Model\Cart", $getCart, '$cart must be an instance of cart model Thelia\Model\Cart'); $this->assertNotNull($getCart->getCustomerId()); $this->assertNull($getCart->getAddressDeliveryId()); @@ -234,7 +238,7 @@ class CartTraitTest extends \PHPUnit_Framework_TestCase $request->getSession()->setCustomerUser($customer); - $getCart = $cartTrait->getCart($request); + $getCart = $cartTrait->getCart($this->dispatcher, $request); $this->assertInstanceOf("Thelia\Model\Cart", $getCart, '$cart must be an instance of cart model Thelia\Model\Cart'); $this->assertNotNull($getCart->getCustomerId()); $this->assertNull($getCart->getAddressDeliveryId()); diff --git a/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneTest.php index a370dbd9a..95c49ce58 100644 --- a/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneTest.php +++ b/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneTest.php @@ -24,7 +24,7 @@ namespace Thelia\Condition\Implementation; use Thelia\Condition\ConditionEvaluator; -use Thelia\Condition\Operators; + use Thelia\Coupon\FacadeInterface; use Thelia\Model\Currency; diff --git a/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php index 2d741eb92..cd6d67364 100644 --- a/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php +++ b/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountTest.php @@ -28,7 +28,7 @@ use Thelia\Condition\ConditionFactory; use Thelia\Condition\Operators; use Thelia\Condition\ConditionCollection; use Thelia\Coupon\FacadeInterface; -use Thelia\Exception\InvalidConditionValueException; + use Thelia\Model\Currency; use Thelia\Model\CurrencyQuery; diff --git a/core/lib/Thelia/Tests/Core/HttpFoundation/RequestTest.php b/core/lib/Thelia/Tests/Core/HttpFoundation/RequestTest.php index d7437efb9..8de88328b 100755 --- a/core/lib/Thelia/Tests/Core/HttpFoundation/RequestTest.php +++ b/core/lib/Thelia/Tests/Core/HttpFoundation/RequestTest.php @@ -2,7 +2,7 @@ namespace Thelia\Tests\Core\HttpFoundation; -use Thelia\Core\HttpFoundation\Request; + /** * the the helpers addinf in Request class diff --git a/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php b/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php index 41a955f87..1320c3020 100644 --- a/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php +++ b/core/lib/Thelia/Tests/TestCaseWithURLToolSetup.php @@ -23,6 +23,9 @@ namespace Thelia\Tests; +use Symfony\Component\Routing\RequestContext; +use Thelia\Tools\URL; + /** * This class provides URL Tool class initialisation * @@ -31,21 +34,22 @@ namespace Thelia\Tests; class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase { private $container = null; + private $dispatcher = null; public function __construct() { $this->container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); - $dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); - $this->container->set("event_dispatcher", $dispatcher); + $this->container->set("event_dispatcher", $this->dispatcher); $this->setupURLTool(); } protected function setupURLTool() { - $context = new \Symfony\Component\Routing\RequestContext( + $context = new RequestContext( '/thelia/index.php', 'GET', 'localhost', @@ -65,11 +69,16 @@ class TestCaseWithURLToolSetup extends \PHPUnit_Framework_TestCase $this->container->set("router.admin", $router); - new \Thelia\Tools\URL($this->container); + new URL($this->container); } public function getContainer() { return $this->container; } + + public function getDispatcher() + { + return $this->dispatcher; + } } diff --git a/core/lib/Thelia/Tests/Tools/FileManagerTest.php b/core/lib/Thelia/Tests/Tools/FileManagerTest.php index ea8588b19..35573a2ac 100644 --- a/core/lib/Thelia/Tests/Tools/FileManagerTest.php +++ b/core/lib/Thelia/Tests/Tools/FileManagerTest.php @@ -11,9 +11,8 @@ namespace Thelia\Tests\Tools; use Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent; use Thelia\Core\Event\Image\ImageCreateOrUpdateEvent; -use Thelia\Core\Translation\Translator; -use Thelia\Exception\ImageException; -use Thelia\Model\Admin; + + use Thelia\Model\CategoryQuery; use Thelia\Model\ContentQuery; use Thelia\Model\FolderQuery; @@ -202,7 +201,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->method('getFile') ->will($this->returnValue('file')); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24); @@ -231,7 +230,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->method('getFile') ->will($this->returnValue('file')); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24); @@ -260,7 +259,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->method('getFile') ->will($this->returnValue('file')); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_CATEGORY, 24); @@ -289,7 +288,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->method('getFile') ->will($this->returnValue('file')); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_CATEGORY, 24); @@ -318,7 +317,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->method('getFile') ->will($this->returnValue('file')); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_FOLDER, 24); @@ -347,7 +346,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->method('getFile') ->will($this->returnValue('file')); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_FOLDER, 24); @@ -376,7 +375,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->method('getFile') ->will($this->returnValue('file')); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_CONTENT, 24); @@ -405,7 +404,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->method('getFile') ->will($this->returnValue('file')); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_CONTENT, 24); @@ -424,7 +423,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') ->disableOriginalConstructor() @@ -450,7 +449,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument') ->disableOriginalConstructor() @@ -476,7 +475,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage') ->disableOriginalConstructor() @@ -502,7 +501,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument') ->disableOriginalConstructor() @@ -528,7 +527,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $badFileName = 'a/ze\érà~çè§^"$*+-_°)(&é<>@#ty2/[\/:*?"<>|]/fi?.fUPPERile.exel../e*'; $expected = 'azer-_ty2fi.fupperile.exel..e'; @@ -546,7 +545,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $actual = $fileManager->getImageModel(FileManager::TYPE_PRODUCT); $this->assertInstanceOf('\Thelia\Model\ProductImage', $actual); $actual = $fileManager->getImageModel(FileManager::TYPE_CATEGORY); @@ -568,7 +567,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $actual = $fileManager->getDocumentModel(FileManager::TYPE_PRODUCT); $this->assertInstanceOf('\Thelia\Model\ProductDocument', $actual); $actual = $fileManager->getDocumentModel(FileManager::TYPE_CATEGORY); @@ -590,7 +589,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $actual = $fileManager->getImageModelQuery(FileManager::TYPE_PRODUCT); $this->assertInstanceOf('\Thelia\Model\ProductImageQuery', $actual); $actual = $fileManager->getImageModelQuery(FileManager::TYPE_CATEGORY); @@ -612,7 +611,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_PRODUCT); $this->assertInstanceOf('\Thelia\Model\ProductDocumentQuery', $actual); $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_CATEGORY); @@ -634,7 +633,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $actual = $fileManager->getParentFileModel(FileManager::TYPE_PRODUCT, ProductQuery::create()->findOne()->getId()); $this->assertInstanceOf('\Thelia\Model\Product', $actual); $actual = $fileManager->getParentFileModel(FileManager::TYPE_CATEGORY, CategoryQuery::create()->findOne()->getId()); @@ -677,7 +676,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $actual = $fileManager->getUploadDir(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_IMAGES); $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/product', $actual); @@ -714,7 +713,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_PRODUCT, 1, FileManager::FILE_TYPE_IMAGES); $this->assertEquals('/admin/products/update?product_id=1¤t_tab=images', $actual); @@ -751,7 +750,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $actual = $fileManager->getFormId(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_IMAGES); $this->assertEquals('thelia.admin.product.image.modification', $actual); @@ -795,7 +794,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->method('getClientOriginalName') ->will($this->returnValue('or1-g_n?al*/&é"filen@me#')); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $expected = 'or1-g_nalfilenme-1.yml'; $actual = $fileManager->renameFile(1, $stubUploadedFile); @@ -822,7 +821,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->method('getClientOriginalName') ->will($this->returnValue('or1-g_n?al*/&é"filen@me#')); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $expected = 'or1-g_nalfilenme-1'; $actual = $fileManager->renameFile(1, $stubUploadedFile); @@ -839,7 +838,7 @@ class FileManagerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $fileManager = new FileManager($stubContainer); + $fileManager = new FileManager(); $actual = $fileManager->isImage('image/jpeg'); $this->assertTrue($actual); diff --git a/core/lib/Thelia/Tools/FileManager.php b/core/lib/Thelia/Tools/FileManager.php index 53d63ce22..330019f99 100644 --- a/core/lib/Thelia/Tools/FileManager.php +++ b/core/lib/Thelia/Tools/FileManager.php @@ -22,12 +22,12 @@ /**********************************************************************************/ namespace Thelia\Tools; -use Symfony\Component\DependencyInjection\ContainerInterface; + use Symfony\Component\HttpFoundation\File\UploadedFile; use Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent; use Thelia\Core\Event\Image\ImageCreateOrUpdateEvent; use Thelia\Core\HttpFoundation\Request; -use Thelia\Core\Translation\Translator; + use Thelia\Exception\ImageException; use Thelia\Form\CategoryDocumentModification; use Thelia\Form\CategoryImageModification; @@ -81,23 +81,6 @@ class FileManager CONST FILE_TYPE_IMAGES = 'images'; CONST FILE_TYPE_DOCUMENTS = 'documents'; - /** @var ContainerInterface Service Container */ - protected $container = null; - - /** @var Translator Service Translator */ - protected $translator = null; - - /** - * Constructor - * - * @param ContainerInterface $container Service container - */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - $this->translator = $this->container->get('thelia.translator'); - } - /** * Copy UploadedFile into the server storage directory * diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index cf593bf06..0334ac72e 100644 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -29,7 +29,7 @@ use Thelia\Rewriting\RewritingRetriever; use Thelia\Core\HttpFoundation\Request; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\Routing\RequestContext; + class URL { @@ -145,7 +145,7 @@ class URL foreach ($parameters as $name => $value) { // Remove this parameter from base URL to prevent duplicate parameters - $base = preg_replace('/([?&])'.$name.'=([^&])*(&|$)/', '$1', $base); + $base = preg_replace('/([?&])'.$name.'=([^&])*(&|$)/', '', $base); $queryString .= sprintf("%s=%s&", urlencode($name), urlencode($value)); } diff --git a/core/lib/Thelia/Type/FloatToFloatArrayType.php b/core/lib/Thelia/Type/FloatToFloatArrayType.php index f55997f55..08a310ef0 100644 --- a/core/lib/Thelia/Type/FloatToFloatArrayType.php +++ b/core/lib/Thelia/Type/FloatToFloatArrayType.php @@ -41,8 +41,8 @@ class FloatToFloatArrayType extends BaseType return false; - foreach ($value as $key => $value) { - if ( filter_var($key, FILTER_VALIDATE_FLOAT) === false || filter_var($value, FILTER_VALIDATE_FLOAT) === false ) { + foreach ($value as $key => $val) { + if ( filter_var($key, FILTER_VALIDATE_FLOAT) === false || filter_var($val, FILTER_VALIDATE_FLOAT) === false ) { return false; } } diff --git a/install/faker.php b/install/faker.php index 4d2cc3c85..5df84b32f 100644 --- a/install/faker.php +++ b/install/faker.php @@ -101,6 +101,10 @@ try { ->find(); $customer->delete(); + $admin = Thelia\Model\AdminQuery::create() + ->find(); + $admin->delete(); + $folder = Thelia\Model\FolderQuery::create() ->find(); $folder->delete(); @@ -183,6 +187,17 @@ try { ; } + for ($i=0; $i<3; $i++) { + $admin = new Thelia\Model\Admin(); + $admin + ->setFirstname($faker->firstname) + ->setLastname($faker->lastname) + ->setLogin($faker->firstname) + ->setPassword('azerty') + ->setLocale('en_US') + ->save(); + } + for ($i = 0; $i < 50; $i++) { $customer = new Thelia\Model\Customer(); $customer->createOrUpdate( @@ -509,11 +524,11 @@ function createProduct($faker, Thelia\Model\Category $category, $position, $temp $image = new \Thelia\Model\ProductImage(); $image->setProductId($productId); - generate_image($image, 1, 'product', $productId); + generate_image($image, 'product', $productId); $document = new \Thelia\Model\ProductDocument(); $document->setProductId($productId); - generate_document($document, 1, 'product', $productId); + generate_document($document, 'product', $productId); return $product; } diff --git a/local/modules/Front/Controller/CartController.php b/local/modules/Front/Controller/CartController.php index 5750cb306..5985dedb5 100644 --- a/local/modules/Front/Controller/CartController.php +++ b/local/modules/Front/Controller/CartController.php @@ -121,7 +121,7 @@ class CartController extends BaseFrontController */ protected function getCartEvent() { - $cart = $this->getCart($this->getRequest()); + $cart = $this->getCart($this->getDispatcher(), $this->getRequest()); return new CartEvent($cart); } diff --git a/local/modules/Front/Controller/CustomerController.php b/local/modules/Front/Controller/CustomerController.php index 2b2d38696..e66a6e2a8 100644 --- a/local/modules/Front/Controller/CustomerController.php +++ b/local/modules/Front/Controller/CustomerController.php @@ -125,7 +125,7 @@ class CustomerController extends BaseFrontController $this->processLogin($customerCreateEvent->getCustomer()); - $cart = $this->getCart($this->getRequest()); + $cart = $this->getCart($this->getDispatcher(), $this->getRequest()); if ($cart->getCartItems()->count() > 0) { $this->redirectToRoute('cart.view'); } else { diff --git a/local/modules/TheliaDebugBar/Config/config.xml b/local/modules/TheliaDebugBar/Config/config.xml index 564c17e66..28a560de9 100644 --- a/local/modules/TheliaDebugBar/Config/config.xml +++ b/local/modules/TheliaDebugBar/Config/config.xml @@ -39,7 +39,9 @@ - + + %kernel.debug% + diff --git a/local/modules/TheliaDebugBar/Listeners/DebugBarListeners.php b/local/modules/TheliaDebugBar/Listeners/DebugBarListeners.php index 5ea75a1df..190844e40 100644 --- a/local/modules/TheliaDebugBar/Listeners/DebugBarListeners.php +++ b/local/modules/TheliaDebugBar/Listeners/DebugBarListeners.php @@ -24,12 +24,11 @@ namespace TheliaDebugBar\Listeners; use DebugBar\DataCollector\MemoryCollector; -use DebugBar\DataCollector\MessagesCollector; use DebugBar\DataCollector\PhpInfoCollector; +use DebugBar\DebugBar; use TheliaDebugBar\DataCollector\PropelCollector; use DebugBar\DataCollector\TimeDataCollector; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\KernelEvents; use Thelia\Action\BaseAction; use Thelia\Core\Event\TheliaEvents; @@ -41,21 +40,28 @@ use Thelia\Core\Event\TheliaEvents; */ class DebugBarListeners extends BaseAction implements EventSubscriberInterface { + protected $debugBar; + protected $debugMode; + + public function __construct(DebugBar $debugbar, $debugMode) + { + $this->debugBar = $debugbar; + $this->debugMode = $debugMode; + } + public function initDebugBar() { - $debugBar = $this->container->get("debugBar"); - $alternativelogger = null; - if($this->container->getParameter('kernel.debug')) { + if($this->debugMode) { $alternativelogger = \Thelia\Log\Tlog::getInstance(); } - $debugBar->addCollector(new PhpInfoCollector()); - //$debugBar->addCollector(new MessagesCollector()); - //$debugBar->addCollector(new RequestDataCollector()); - $debugBar->addCollector(new TimeDataCollector()); - $debugBar->addCollector(new MemoryCollector()); - $debugBar->addCollector(new PropelCollector($alternativelogger)); + $this->debugBar->addCollector(new PhpInfoCollector()); + //$this->debugBar->addCollector(new MessagesCollector()); + //$this->debugBar->addCollector(new RequestDataCollector()); + $this->debugBar->addCollector(new TimeDataCollector()); + $this->debugBar->addCollector(new MemoryCollector()); + $this->debugBar->addCollector(new PropelCollector($alternativelogger)); } /** diff --git a/templates/backOffice/default/category-edit.html b/templates/backOffice/default/category-edit.html index 1885d8201..8f3fc4e40 100644 --- a/templates/backOffice/default/category-edit.html +++ b/templates/backOffice/default/category-edit.html @@ -261,7 +261,23 @@
- {module_include location='category-edit'} +
+ {include + file = "includes/inner-form-toolbar.html" + hide_submit_buttons = true + page_url = {$pageUrl} + close_url = {$closeUrl} + current_tab = "modules" + } +
+ + {module_include location='category-edit' countvar='module_count'} + + {if $countvar == 0} +
+ {intl l="There is currently no active module here."} +
+ {/if}
diff --git a/templates/backOffice/default/content-edit.html b/templates/backOffice/default/content-edit.html index 1014d512c..49c8f6b66 100644 --- a/templates/backOffice/default/content-edit.html +++ b/templates/backOffice/default/content-edit.html @@ -97,7 +97,7 @@ {$myparent=$DEFAULT_FOLDER} {loop name="fold-parent" type="folder-tree" visible="*" folder="0"} - {/loop } + {/loop} @@ -156,7 +156,23 @@
- {module_include location='content-edit'} +
+ {include + file = "includes/inner-form-toolbar.html" + hide_submit_buttons = true + page_url = {$pageUrl} + close_url = {$closeUrl} + current_tab = "modules" + } +
+ + {module_include location='content-edit' countvar='module_count'} + + {if $countvar == 0} +
+ {intl l="There is currently no active module here."} +
+ {/if}
diff --git a/templates/backOffice/default/folder-edit.html b/templates/backOffice/default/folder-edit.html index e86790634..bff41f094 100644 --- a/templates/backOffice/default/folder-edit.html +++ b/templates/backOffice/default/folder-edit.html @@ -142,7 +142,23 @@
- {module_include location='folder-edit'} +
+ {include + file = "includes/inner-form-toolbar.html" + hide_submit_buttons = true + page_url = {$pageUrl} + close_url = {$closeUrl} + current_tab = "modules" + } +
+ + {module_include location='folder-edit' countvar='module_count'} + + {if $countvar == 0} +
+ {intl l="There is currently no active module here."} +
+ {/if}
diff --git a/templates/backOffice/default/includes/inner-form-toolbar.html b/templates/backOffice/default/includes/inner-form-toolbar.html index 6e7835e73..92bee1af8 100644 --- a/templates/backOffice/default/includes/inner-form-toolbar.html +++ b/templates/backOffice/default/includes/inner-form-toolbar.html @@ -16,7 +16,12 @@ Parameters: