From c0f5002db966dd654f8ab775d13a60decc212fa3 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 23 Jan 2014 17:13:48 +0100 Subject: [PATCH 01/45] create a dedicated method for count loop function --- .../Thelia/Core/Template/Element/BaseLoop.php | 22 +++++++++++++++++++ .../Template/Smarty/Plugins/TheliaLoop.php | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index bbeb57e45..80220474b 100644 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -333,6 +333,28 @@ abstract class BaseLoop } } + public function count() + { + $count = 0; + if ($this instanceof PropelSearchLoopInterface) { + $searchModelCriteria = $this->buildModelCriteria(); + if (null === $searchModelCriteria) { + $count = 0; + } else { + $count = $searchModelCriteria->count(); + } + } elseif ($this instanceof ArraySearchLoopInterface) { + $searchArray = $this->buildArray(); + if (null === $searchArray) { + $count = 0; + } else { + $count = count($searchArray); + } + } + + return $count; + } + /** * @param $pagination * @return LoopResult diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php index 64bce76d3..1b75f2096 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php @@ -91,7 +91,7 @@ class TheliaLoop extends AbstractSmartyPlugin $dummy = null; - return $loop->exec($dummy, true); + return $loop->count(); } /** From f8460901b3fd23382218b6b2fac8e3cd7e606260 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 23 Jan 2014 19:49:36 +0100 Subject: [PATCH 02/45] Added a way to create orders outside of the front-office context. --- core/lib/Thelia/Action/Order.php | 111 ++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 38 deletions(-) diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index fe467609b..276f2103d 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -42,6 +42,14 @@ use Thelia\Model\Map\OrderTableMap; use Thelia\Model\OrderAddress; use Thelia\Model\OrderStatusQuery; use Thelia\Tools\I18n; +use Thelia\Model\Currency; +use Thelia\Model\Lang; +use Thelia\Model\Country; +use Thelia\Model\Customer; +use Thelia\Core\Event\Order\OrderManualEvent; + +use Thelia\Model\Cart as CartModel; +use Thelia\Model\Order as ModelOrder; /** * @@ -113,36 +121,23 @@ class Order extends BaseAction implements EventSubscriberInterface $event->setOrder($order); } - /** - * @param OrderEvent $event - * - * @throws \Thelia\Exception\TheliaProcessException - */ - public function create(OrderEvent $event) + protected function createOrder(ModelOrder $sessionOrder, Currency $currency, Lang $lang, CartModel $cart, Customer $customer) { $con = \Propel\Runtime\Propel::getConnection( - OrderTableMap::DATABASE_NAME + OrderTableMap::DATABASE_NAME ); $con->beginTransaction(); - $sessionOrder = $event->getOrder(); - /* use a copy to avoid errored reccord in session */ $placedOrder = $sessionOrder->copy(); $placedOrder->setDispatcher($this->getDispatcher()); - $customer = $this->getSecurityContext()->getCustomerUser(); - $currency = $this->getSession()->getCurrency(); - $lang = $this->getSession()->getLang(); $deliveryAddress = AddressQuery::create()->findPk($sessionOrder->chosenDeliveryAddress); $taxCountry = $deliveryAddress->getCountry(); $invoiceAddress = AddressQuery::create()->findPk($sessionOrder->chosenInvoiceAddress); - $cart = $this->getSession()->getCart(); $cartItems = $cart->getCartItems(); - $paymentModule = ModuleQuery::create()->findPk($placedOrder->getPaymentModuleId()); - /* fulfill order */ $placedOrder->setCustomerId($customer->getId()); $placedOrder->setCurrencyId($currency->getId()); @@ -163,7 +158,7 @@ class Order extends BaseAction implements EventSubscriberInterface ->setCity($deliveryAddress->getCity()) ->setPhone($deliveryAddress->getPhone()) ->setCountryId($deliveryAddress->getCountryId()) - ->save($con) + ->save($con) ; $invoiceOrderAddress = new OrderAddress(); @@ -179,19 +174,19 @@ class Order extends BaseAction implements EventSubscriberInterface ->setCity($invoiceAddress->getCity()) ->setPhone($invoiceAddress->getPhone()) ->setCountryId($invoiceAddress->getCountryId()) - ->save($con) + ->save($con) ; $placedOrder->setDeliveryOrderAddressId($deliveryOrderAddress->getId()); $placedOrder->setInvoiceOrderAddressId($invoiceOrderAddress->getId()); $placedOrder->setStatusId( - OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_NOT_PAID)->getId() + OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_NOT_PAID)->getId() ); /* memorize discount */ $placedOrder->setDiscount( - $cart->getDiscount() + $cart->getDiscount() ); $placedOrder->save($con); @@ -202,7 +197,7 @@ class Order extends BaseAction implements EventSubscriberInterface $product = $cartItem->getProduct(); /* get translation */ - $productI18n = I18n::forceI18nRetrieving($this->getSession()->getLang()->getLocale(), 'Product', $product->getId()); + $productI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'Product', $product->getId()); $pse = $cartItem->getProductSaleElements(); @@ -213,19 +208,19 @@ class Order extends BaseAction implements EventSubscriberInterface /* decrease stock */ $pse->setQuantity( - $pse->getQuantity() - $cartItem->getQuantity() + $pse->getQuantity() - $cartItem->getQuantity() ); $pse->save($con); /* get tax */ - $taxRuleI18n = I18n::forceI18nRetrieving($this->getSession()->getLang()->getLocale(), 'TaxRule', $product->getTaxRuleId()); + $taxRuleI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'TaxRule', $product->getTaxRuleId()); $taxDetail = $product->getTaxRule()->getTaxDetail( - $product, - $taxCountry, - $cartItem->getPrice(), - $cartItem->getPromoPrice(), - $this->getSession()->getLang()->getLocale() + $product, + $taxCountry, + $cartItem->getPrice(), + $cartItem->getPromoPrice(), + $lang->getLocale() ); $orderProduct = new OrderProduct(); @@ -246,9 +241,9 @@ class Order extends BaseAction implements EventSubscriberInterface ->setTaxRuleTitle($taxRuleI18n->getTitle()) ->setTaxRuleDescription($taxRuleI18n->getDescription()) ->setEanCode($pse->getEanCode()) + ->setDispatcher($this->getDispatcher()) + ->save($con) ; - $orderProduct->setDispatcher($this->getDispatcher()); - $orderProduct->save($con); /* fulfill order_product_tax */ foreach ($taxDetail as $tax) { @@ -258,8 +253,8 @@ class Order extends BaseAction implements EventSubscriberInterface /* fulfill order_attribute_combination and decrease stock */ foreach ($pse->getAttributeCombinations() as $attributeCombination) { - $attribute = I18n::forceI18nRetrieving($this->getSession()->getLang()->getLocale(), 'Attribute', $attributeCombination->getAttributeId()); - $attributeAv = I18n::forceI18nRetrieving($this->getSession()->getLang()->getLocale(), 'AttributeAv', $attributeCombination->getAttributeAvId()); + $attribute = I18n::forceI18nRetrieving($lang->getLocale(), 'Attribute', $attributeCombination->getAttributeId()); + $attributeAv = I18n::forceI18nRetrieving($lang->getLocale(), 'AttributeAv', $attributeCombination->getAttributeAvId()); $orderAttributeCombination = new OrderProductAttributeCombination(); $orderAttributeCombination @@ -272,28 +267,67 @@ class Order extends BaseAction implements EventSubscriberInterface ->setAttributeAvChapo($attributeAv->getChapo()) ->setAttributeAvDescription($attributeAv->getDescription()) ->setAttributeAvPostscriptum($attributeAv->getPostscriptum()) - ; - - $orderAttributeCombination->save($con); + ->save($con); } } $con->commit(); + return $placedOrder; + } + + /** + * Create an order outside of the front-office context, e.g. manually from the back-office. + */ + public function createManual(OrderManualEvent $event) { + + $placedOrder = $this->createOrder( + $event->getOrder(), + $event->getCurrency(), + $event->getLang(), + $event->getCart(), + $event->getCustomer() + ); + } + + /** + * @param OrderEvent $event + * + * @throws \Thelia\Exception\TheliaProcessException + */ + public function create(OrderEvent $event) + { + $session = $this->getSession(); + + $placedOrder = $this->createOrder( + $event->getOrder(), + $session->getCurrency(), + $session->getLang(), + $session->getCart(), + $this->getSecurityContext()->getCustomerUser() + ); + + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder)); + /* clear session */ + $session + ->setProcessedOrder($placedOrder) + ->setOrder(new \Thelia\Model\Order()) + ; + /* but memorize placed order */ - $sessionOrder = new \Thelia\Model\Order(); - $event->setOrder($sessionOrder); + $event->setOrder(new \Thelia\Model\Order()); $event->setPlacedOrder($placedOrder); - $this->getSession()->setProcessedOrder($placedOrder); - $this->getSession()->setOrder(new \Thelia\Model\Order()); /* empty cart */ $this->getDispatcher()->dispatch(TheliaEvents::CART_CLEAR, new CartEvent($this->getCart($this->getRequest()))); /* call pay method */ + + $paymentModule = ModuleQuery::create()->findPk($placedOrder->getPaymentModuleId()); + $paymentModuleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode())); $paymentModuleInstance->pay($placedOrder); } @@ -435,6 +469,7 @@ class Order extends BaseAction implements EventSubscriberInterface TheliaEvents::ORDER_UPDATE_STATUS => array("updateStatus", 128), TheliaEvents::ORDER_UPDATE_DELIVERY_REF => array("updateDeliveryRef", 128), TheliaEvents::ORDER_UPDATE_ADDRESS => array("updateAddress", 128), + TheliaEvents::ORDER_CREATE_MANUAL => array("createManual", 128), ); } From 485816cc4cbdff45d375a254d2e91d00fe7e7b5d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 29 Jan 2014 21:21:27 +0100 Subject: [PATCH 03/45] change argument hash creation --- core/lib/Thelia/Core/Template/Element/BaseLoop.php | 4 ++-- core/lib/Thelia/Core/Template/Loop/Argument/Argument.php | 6 ++++++ .../Core/Template/Loop/Argument/ArgumentCollection.php | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Element/BaseLoop.php b/core/lib/Thelia/Core/Template/Element/BaseLoop.php index 2aa5e874f..215537431 100644 --- a/core/lib/Thelia/Core/Template/Element/BaseLoop.php +++ b/core/lib/Thelia/Core/Template/Element/BaseLoop.php @@ -339,7 +339,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 +370,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/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); } } From 3fb0dfe1db6c8e756c4bdd037c94e39befd82fa7 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 31 Jan 2014 11:03:53 +0100 Subject: [PATCH 04/45] Remove container in Customer listener. #198 --- core/lib/Thelia/Action/Customer.php | 15 ++++++++---- core/lib/Thelia/Config/Resources/action.xml | 4 ++-- core/lib/Thelia/Tests/Action/CustomerTest.php | 24 +++++++++++-------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php index 4fe5d0f72..84dc8f97f 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; @@ -39,8 +40,14 @@ use Thelia\Core\Event\Customer\CustomerLoginEvent; * @package Thelia\Action * @author Manuel Raynaud */ -class Customer extends BaseAction implements EventSubscriberInterface +class Customer 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(), @@ -140,7 +147,7 @@ class Customer extends BaseAction implements EventSubscriberInterface */ protected function getSecurityContext() { - return $this->container->get('thelia.securityContext'); + return $this->securityContext; } /** diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index d8252f11b..118d96d2a 100644 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -16,8 +16,8 @@ - - + + 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); From bf49aa24ddec760c3ddb36da40127e1dca88420e Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 31 Jan 2014 11:28:06 +0100 Subject: [PATCH 05/45] Remove container from Adress listenet. #198 --- core/lib/Thelia/Action/Address.php | 4 ++-- core/lib/Thelia/Config/Resources/action.xml | 1 - core/lib/Thelia/Tests/Action/AddressTest.php | 6 ++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index 2195d946f..d5e245b97 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -36,7 +36,7 @@ use Thelia\Model\Map\AddressTableMap; * @package Thelia\Action * @author Manuel Raynaud */ -class Address extends BaseAction implements EventSubscriberInterface +class Address implements EventSubscriberInterface { public function create(AddressCreateOrUpdateEvent $event) @@ -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/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 118d96d2a..e2a6ce72b 100644 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -22,7 +22,6 @@ - diff --git a/core/lib/Thelia/Tests/Action/AddressTest.php b/core/lib/Thelia/Tests/Action/AddressTest.php index 9c4198c06..ac74acec5 100644 --- a/core/lib/Thelia/Tests/Action/AddressTest.php +++ b/core/lib/Thelia/Tests/Action/AddressTest.php @@ -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,6 +107,7 @@ class AddressTest extends BaseAction "" ); $addressEvent->setAddress($address); + $addressEvent->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface")); $actionAddress = new Address($this->getContainer()); $actionAddress->update($addressEvent); From 58ae3bb619a8f49fe83d27df6c0f933458ffc382 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 31 Jan 2014 12:02:45 +0100 Subject: [PATCH 06/45] remove container from administrator listener and create test for this event. #198 --- core/lib/Thelia/Action/Administrator.php | 6 +- core/lib/Thelia/Config/Resources/action.xml | 1 - .../Administrator/AdministratorEvent.php | 12 ++++ core/lib/Thelia/Tests/Action/AddressTest.php | 2 +- .../Thelia/Tests/Action/AdministratorTest.php | 70 +++++++++++++++++++ 5 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 core/lib/Thelia/Tests/Action/AdministratorTest.php diff --git a/core/lib/Thelia/Action/Administrator.php b/core/lib/Thelia/Action/Administrator.php index 5c34e2c59..bbd4e3336 100644 --- a/core/lib/Thelia/Action/Administrator.php +++ b/core/lib/Thelia/Action/Administrator.php @@ -30,7 +30,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Admin as AdminModel; use Thelia\Model\AdminQuery; -class Administrator extends BaseAction implements EventSubscriberInterface +class Administrator implements EventSubscriberInterface { /** * @param AdministratorEvent $event @@ -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/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index e2a6ce72b..c64e606a8 100644 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -155,7 +155,6 @@ - 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/Tests/Action/AddressTest.php b/core/lib/Thelia/Tests/Action/AddressTest.php index ac74acec5..b570959e0 100644 --- a/core/lib/Thelia/Tests/Action/AddressTest.php +++ b/core/lib/Thelia/Tests/Action/AddressTest.php @@ -109,7 +109,7 @@ class AddressTest extends \PHPUnit_Framework_TestCase $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..9fdf8f70d --- /dev/null +++ b/core/lib/Thelia/Tests/Action/AdministratorTest.php @@ -0,0 +1,70 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Thelia\Action\Administrator; +use Thelia\Core\Event\Administrator\AdministratorEvent; +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())); + } + + +} \ No newline at end of file From b3cc5e3f8051e3c349cf5f7239369cb94adc237d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 31 Jan 2014 12:27:42 +0100 Subject: [PATCH 07/45] create test for admin modification listener --- .../Thelia/Tests/Action/AdministratorTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/lib/Thelia/Tests/Action/AdministratorTest.php b/core/lib/Thelia/Tests/Action/AdministratorTest.php index 9fdf8f70d..99160c073 100644 --- a/core/lib/Thelia/Tests/Action/AdministratorTest.php +++ b/core/lib/Thelia/Tests/Action/AdministratorTest.php @@ -25,6 +25,7 @@ namespace Thelia\Tests\Action; use Thelia\Action\Administrator; use Thelia\Core\Event\Administrator\AdministratorEvent; +use Thelia\Model\AdminQuery; use Thelia\Model\LangQuery; @@ -66,5 +67,38 @@ class AdministratorTest extends \PHPUnit_Framework_TestCase $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())); + } + } \ No newline at end of file From 64f89d07a9f2f0ae992d617136eb6f549a43002c Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 31 Jan 2014 12:51:15 +0100 Subject: [PATCH 08/45] create test for updatePassword event --- .../AdministratorUpdatePasswordEvent.php | 4 ++ .../Thelia/Tests/Action/AdministratorTest.php | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) 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/Tests/Action/AdministratorTest.php b/core/lib/Thelia/Tests/Action/AdministratorTest.php index 99160c073..bfaee0d6b 100644 --- a/core/lib/Thelia/Tests/Action/AdministratorTest.php +++ b/core/lib/Thelia/Tests/Action/AdministratorTest.php @@ -25,6 +25,7 @@ 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; @@ -100,5 +101,43 @@ class AdministratorTest extends \PHPUnit_Framework_TestCase $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 From cb47041e1f376b03ff4aba7dc7874c60ad2a3c09 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 31 Jan 2014 13:05:04 +0100 Subject: [PATCH 09/45] create admin in the faker for the test suite --- install/faker.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/install/faker.php b/install/faker.php index 4d2cc3c85..5432021b7 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( From f8e3553924f92726f8fef038e60658d5c07b2fa8 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 31 Jan 2014 15:55:21 +0100 Subject: [PATCH 10/45] Removed unused container dependency from the FileManager class --- core/lib/Thelia/Action/Document.php | 6 +-- core/lib/Thelia/Action/Image.php | 6 +-- core/lib/Thelia/Config/Resources/action.xml | 16 +++---- .../Controller/Admin/FileController.php | 20 ++++---- .../Thelia/Tests/Tools/FileManagerTest.php | 48 +++++++++---------- core/lib/Thelia/Tools/FileManager.php | 17 ------- 6 files changed, 48 insertions(+), 65 deletions(-) diff --git a/core/lib/Thelia/Action/Document.php b/core/lib/Thelia/Action/Document.php index 35dc3e540..0e3b4a854 100644 --- a/core/lib/Thelia/Action/Document.php +++ b/core/lib/Thelia/Action/Document.php @@ -144,7 +144,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 +180,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 @@ -211,7 +211,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/Image.php b/core/lib/Thelia/Action/Image.php index e5beb2823..7272f9579 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 @@ -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); } diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index c64e606a8..8f1f50531 100644 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -6,6 +6,14 @@ + + + + + + + + @@ -21,10 +29,6 @@ - - - - @@ -154,10 +158,6 @@ - - - - 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/Tests/Tools/FileManagerTest.php b/core/lib/Thelia/Tests/Tools/FileManagerTest.php index ea8588b19..0c0f0e4e7 100644 --- a/core/lib/Thelia/Tests/Tools/FileManagerTest.php +++ b/core/lib/Thelia/Tests/Tools/FileManagerTest.php @@ -202,7 +202,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 +231,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 +260,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 +289,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 +318,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 +347,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 +376,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 +405,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 +424,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 +450,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 +476,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 +502,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 +528,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 +546,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 +568,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 +590,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 +612,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 +634,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 +677,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 +714,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 +751,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 +795,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 +822,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 +839,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..89365c49e 100644 --- a/core/lib/Thelia/Tools/FileManager.php +++ b/core/lib/Thelia/Tools/FileManager.php @@ -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 * From dfd34bad495ee124d4eb5070c4f3fd86ed7677b1 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 31 Jan 2014 16:03:02 +0100 Subject: [PATCH 11/45] Fixed wrong namespace --- core/lib/Thelia/Action/Order.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index 2b2c9b7a6..000e5b2c3 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -35,7 +35,7 @@ use Thelia\Model\AddressQuery; use Thelia\Model\Cart as CartModel; use Thelia\Model\ConfigQuery; use Thelia\Model\Currency; -use Thelia\Model\Customer; +use Thelia\Model\Customer as CustomerModel; use Thelia\Model\Lang; use Thelia\Model\Map\OrderTableMap; use Thelia\Model\MessageQuery; @@ -118,7 +118,7 @@ class Order extends BaseAction implements EventSubscriberInterface $event->setOrder($order); } - protected function createOrder(ModelOrder $sessionOrder, Currency $currency, Lang $lang, CartModel $cart, Customer $customer) + protected function createOrder(ModelOrder $sessionOrder, Currency $currency, Lang $lang, CartModel $cart, CustomerModel $customer) { $con = \Propel\Runtime\Propel::getConnection( OrderTableMap::DATABASE_NAME @@ -304,7 +304,7 @@ class Order extends BaseAction implements EventSubscriberInterface $this->getSecurityContext()->getCustomerUser() ); - $event->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder)); + $this->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder)); /* clear session */ $session @@ -317,7 +317,7 @@ class Order extends BaseAction implements EventSubscriberInterface $event->setPlacedOrder($placedOrder); /* empty cart */ - $event->getDispatcher()->dispatch(TheliaEvents::CART_CLEAR, new CartEvent($this->getCart($this->getRequest()))); + $this->getDispatcher()->dispatch(TheliaEvents::CART_CLEAR, new CartEvent($this->getCart($this->getRequest()))); /* call pay method */ From 89653f452bfa25958a04a010d7f34fb3cc436baa Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 31 Jan 2014 20:04:25 +0100 Subject: [PATCH 12/45] Removes container from all Thelia actions, but Modules (#198) --- core/lib/Thelia/Action/Address.php | 2 +- core/lib/Thelia/Action/Administrator.php | 2 +- core/lib/Thelia/Action/Area.php | 12 +-- core/lib/Thelia/Action/Attribute.php | 8 +- core/lib/Thelia/Action/AttributeAv.php | 8 +- core/lib/Thelia/Action/BaseAction.php | 40 +++------ core/lib/Thelia/Action/Cart.php | 15 ++-- core/lib/Thelia/Action/Category.php | 16 ++-- core/lib/Thelia/Action/Config.php | 8 +- core/lib/Thelia/Action/Content.php | 22 +---- core/lib/Thelia/Action/Coupon.php | 78 +++++++++------- core/lib/Thelia/Action/Currency.php | 15 ++-- core/lib/Thelia/Action/Customer.php | 4 +- core/lib/Thelia/Action/Document.php | 16 +--- core/lib/Thelia/Action/Feature.php | 10 +-- core/lib/Thelia/Action/FeatureAv.php | 10 +-- core/lib/Thelia/Action/Folder.php | 10 +-- core/lib/Thelia/Action/HttpException.php | 17 +++- core/lib/Thelia/Action/Image.php | 4 +- core/lib/Thelia/Action/Lang.php | 8 +- core/lib/Thelia/Action/Message.php | 6 +- core/lib/Thelia/Action/Module.php | 63 ++++++++++--- core/lib/Thelia/Action/Newsletter.php | 2 +- core/lib/Thelia/Action/Order.php | 90 ++++++++++--------- core/lib/Thelia/Action/Product.php | 20 ++--- core/lib/Thelia/Action/ProductSaleElement.php | 2 +- core/lib/Thelia/Action/Profile.php | 4 +- core/lib/Thelia/Action/Tax.php | 4 +- core/lib/Thelia/Action/TaxRule.php | 4 +- core/lib/Thelia/Action/Template.php | 6 +- core/lib/Thelia/Cart/CartTrait.php | 15 ++-- core/lib/Thelia/Command/CacheClear.php | 4 +- core/lib/Thelia/Command/ClearImageCache.php | 2 +- core/lib/Thelia/Command/CreateAdminUser.php | 2 +- core/lib/Thelia/Command/GenerateResources.php | 4 +- core/lib/Thelia/Command/Install.php | 2 +- .../Thelia/Command/ModuleGenerateCommand.php | 2 +- .../Thelia/Command/ReloadDatabaseCommand.php | 2 +- .../Module/{Class.php => Class.php.template} | 1 - .../Thelia/Condition/ConditionEvaluator.php | 3 +- .../lib/Thelia/Condition/ConditionFactory.php | 2 +- .../Implementation/ConditionAbstract.php | 2 +- .../Implementation/MatchForEveryone.php | 2 +- .../Implementation/MatchForTotalAmount.php | 2 +- .../Implementation/MatchForXArticles.php | 2 +- core/lib/Thelia/Config/Resources/action.xml | 78 +++++++--------- .../Controller/Admin/AttributeController.php | 2 +- .../Controller/Admin/BaseAdminController.php | 2 +- .../Controller/Admin/CategoryController.php | 2 +- .../Controller/Admin/CustomerController.php | 3 +- .../Controller/Admin/FeatureController.php | 2 +- .../Controller/Admin/OrderController.php | 8 +- .../Controller/Admin/SessionController.php | 6 +- core/lib/Thelia/Controller/BaseController.php | 6 +- .../Controller/Front/BaseFrontController.php | 2 +- .../Controller/Front/DefaultController.php | 2 +- .../Core/Event/Order/OrderPaymentEvent.php | 53 +++++++++++ core/lib/Thelia/Core/Event/TheliaEvents.php | 4 + .../Core/EventListener/ViewListener.php | 4 +- ...AdminUsernamePasswordFormAuthenticator.php | 4 +- ...tomerUsernamePasswordFormAuthenticator.php | 2 +- .../Authentication/TokenAuthenticator.php | 2 +- .../UsernamePasswordFormAuthenticator.php | 4 +- .../UserProvider/AdminUserProvider.php | 2 +- .../UserProvider/CustomerUserProvider.php | 2 +- .../Core/Template/Element/BaseI18nLoop.php | 2 +- .../Core/Template/Element/LoopResult.php | 2 +- .../Thelia/Core/Template/Loop/Accessory.php | 2 +- .../Core/Template/Loop/AssociatedContent.php | 2 +- core/lib/Thelia/Core/Template/Loop/Cart.php | 4 +- .../Thelia/Core/Template/Loop/Delivery.php | 2 +- core/lib/Thelia/Core/Template/Loop/Order.php | 2 +- .../Thelia/Core/Template/Loop/OrderCoupon.php | 2 +- .../lib/Thelia/Core/Template/Loop/Product.php | 2 +- .../Template/Loop/ProductSaleElements.php | 2 +- .../Thelia/Core/Template/ParserInterface.php | 8 ++ .../Smarty/Assets/SmartyAssetsManager.php | 2 +- .../Smarty/Plugins/DataAccessFunctions.php | 4 +- .../Core/Template/Smarty/Plugins/Form.php | 2 +- .../Core/Template/Smarty/SmartyParser.php | 4 +- core/lib/Thelia/Core/Thelia.php | 2 +- core/lib/Thelia/Coupon/BaseFacade.php | 2 +- .../lib/Thelia/Coupon/Type/CouponAbstract.php | 2 +- core/lib/Thelia/Coupon/Type/RemoveXAmount.php | 2 +- .../lib/Thelia/Coupon/Type/RemoveXPercent.php | 3 +- .../Thelia/Form/AdministratorCreationForm.php | 2 +- .../Thelia/Form/Area/AreaModificationForm.php | 2 +- core/lib/Thelia/Form/CustomerCreateForm.php | 2 +- core/lib/Thelia/Form/CustomerLogin.php | 4 +- .../Form/Image/DocumentModification.php | 2 +- .../Form/MailingSystemModificationForm.php | 4 +- .../Form/ProductCombinationGenerationForm.php | 2 +- .../Form/ProfileUpdateModuleAccessForm.php | 2 +- .../Form/ProfileUpdateResourceAccessForm.php | 2 +- .../Form/StandardDescriptionFieldsTrait.php | 3 - core/lib/Thelia/Install/CheckPermission.php | 3 + .../TlogDestinationRotatingFile.php | 2 +- core/lib/Thelia/Model/Address.php | 4 +- core/lib/Thelia/Model/AttributeAv.php | 2 +- core/lib/Thelia/Model/Cart.php | 7 +- core/lib/Thelia/Model/CartItem.php | 2 +- core/lib/Thelia/Model/CartQuery.php | 2 +- core/lib/Thelia/Model/Category.php | 5 +- core/lib/Thelia/Model/CategoryImage.php | 3 +- core/lib/Thelia/Model/Content.php | 4 +- core/lib/Thelia/Model/Customer.php | 4 +- core/lib/Thelia/Model/Folder.php | 2 +- core/lib/Thelia/Model/Lang.php | 2 +- core/lib/Thelia/Model/Module.php | 2 +- core/lib/Thelia/Model/Order.php | 6 +- core/lib/Thelia/Model/OrderQuery.php | 6 +- core/lib/Thelia/Model/Product.php | 4 +- core/lib/Thelia/Model/RewritingUrl.php | 2 +- core/lib/Thelia/Model/TaxRuleQuery.php | 2 +- core/lib/Thelia/TaxEngine/TaxEngine.php | 4 +- core/lib/Thelia/Tests/Action/AddressTest.php | 2 +- core/lib/Thelia/Tests/Action/ContentTest.php | 20 +++++ core/lib/Thelia/Tests/Action/FolderTest.php | 40 ++++++--- core/lib/Thelia/Tests/Action/OrderTest.php | 44 ++++++--- .../Tests/Action/RewrittenUrlTestTrait.php | 2 + core/lib/Thelia/Tests/Cart/CartTraitTest.php | 16 ++-- .../Implementation/MatchForEveryoneTest.php | 2 +- .../MatchForTotalAmountTest.php | 2 +- .../Tests/Core/HttpFoundation/RequestTest.php | 2 +- .../Thelia/Tests/Tools/FileManagerTest.php | 5 +- core/lib/Thelia/Tools/FileManager.php | 4 +- core/lib/Thelia/Tools/URL.php | 2 +- .../lib/Thelia/Type/FloatToFloatArrayType.php | 4 +- .../Front/Controller/CartController.php | 2 +- .../Front/Controller/CustomerController.php | 2 +- .../modules/TheliaDebugBar/Config/config.xml | 4 +- .../Listeners/DebugBarListeners.php | 28 +++--- 132 files changed, 603 insertions(+), 467 deletions(-) rename core/lib/Thelia/Command/Skeleton/Module/{Class.php => Class.php.template} (98%) create mode 100644 core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php diff --git a/core/lib/Thelia/Action/Address.php b/core/lib/Thelia/Action/Address.php index d5e245b97..9e278d899 100644 --- a/core/lib/Thelia/Action/Address.php +++ b/core/lib/Thelia/Action/Address.php @@ -36,7 +36,7 @@ use Thelia\Model\Map\AddressTableMap; * @package Thelia\Action * @author Manuel Raynaud */ -class Address implements EventSubscriberInterface +class Address extends BaseAction implements EventSubscriberInterface { public function create(AddressCreateOrUpdateEvent $event) diff --git a/core/lib/Thelia/Action/Administrator.php b/core/lib/Thelia/Action/Administrator.php index bbd4e3336..77078df0b 100644 --- a/core/lib/Thelia/Action/Administrator.php +++ b/core/lib/Thelia/Action/Administrator.php @@ -30,7 +30,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Admin as AdminModel; use Thelia\Model\AdminQuery; -class Administrator implements EventSubscriberInterface +class Administrator extends BaseAction implements EventSubscriberInterface { /** * @param AdministratorEvent $event diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php index 92eb75634..51d9ef04d 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,7 @@ class Area extends BaseAction implements EventSubscriberInterface public function removeCountry(AreaRemoveCountryEvent $event) { if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { - $country->setDispatcher($this->getDispatcher()); + $country->setDispatcher($event->getDispatcher()); $country->setAreaId(null) ->save(); } @@ -65,7 +65,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 +77,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 +89,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 84dc8f97f..d02f895d4 100644 --- a/core/lib/Thelia/Action/Customer.php +++ b/core/lib/Thelia/Action/Customer.php @@ -40,7 +40,7 @@ use Thelia\Core\Event\Customer\CustomerLoginEvent; * @package Thelia\Action * @author Manuel Raynaud */ -class Customer implements EventSubscriberInterface +class Customer extends BaseAction implements EventSubscriberInterface { protected $securityContext; @@ -143,7 +143,7 @@ class Customer implements EventSubscriberInterface /** * Return the security context * - * @return Thelia\Core\Security\SecurityContext + * @return \Thelia\Core\Security\SecurityContext */ protected function getSecurityContext() { diff --git a/core/lib/Thelia/Action/Document.php b/core/lib/Thelia/Action/Document.php index 0e3b4a854..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 @@ -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); } /** 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 7272f9579..7b5ef0138 100644 --- a/core/lib/Thelia/Action/Image.php +++ b/core/lib/Thelia/Action/Image.php @@ -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); } /** @@ -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..4468c7bce 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -23,12 +23,15 @@ namespace Thelia\Action; use Propel\Runtime\Propel; +use Propel\Runtime\ServiceContainer\ServiceContainerInterface; +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\Module\OrderPaymentEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Map\ModuleTableMap; use Thelia\Model\ModuleQuery; @@ -44,6 +47,15 @@ use Thelia\Core\Translation\Translator; */ class Module extends BaseAction implements EventSubscriberInterface { + /** + * @var \Propel\Runtime\ServiceContainer\ServiceContainerInterface + */ + protected $container; + + public function __construct(ServiceContainerInterface $container) + { + $this->container = $container; + } public function toggleActivation(ModuleToggleActivationEvent $event) { @@ -53,7 +65,7 @@ class Module extends BaseAction implements EventSubscriberInterface $moduleInstance = $moduleClass->newInstance(); if ( method_exists($moduleInstance, 'setContainer')) { - $moduleInstance->setContainer($this->container); + $moduleInstance->setContainer($this->getContainer()); if ($module->getActivate() == BaseModule::IS_ACTIVATED) { $moduleInstance->deActivate($module); } else { @@ -63,7 +75,7 @@ class Module extends BaseAction implements EventSubscriberInterface $event->setModule($module); - $this->cacheClear(); + $this->cacheClear($event->getDispatcher()); } } @@ -86,7 +98,7 @@ class Module extends BaseAction implements EventSubscriberInterface $reflected = new \ReflectionClass($module->getFullNamespace()); $instance = $reflected->newInstance(); - $instance->setContainer($this->container); + $instance->setContainer($this->getContainer()); $path = dirname($reflected->getFileName()); @@ -108,7 +120,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 +137,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 +151,51 @@ 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( + $dispatcher, + $this->getContainer()->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 000e5b2c3..d217bfbf8 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\Module\OrderPaymentEvent; use Thelia\Core\Event\Order\OrderAddressEvent; use Thelia\Core\Event\Order\OrderEvent; use Thelia\Core\Event\Order\OrderManualEvent; 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; @@ -58,6 +63,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 +148,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 @@ -128,7 +158,7 @@ class Order extends BaseAction implements EventSubscriberInterface /* 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 +268,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 +309,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 +328,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 */ $session @@ -317,14 +349,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); } /** @@ -347,10 +381,8 @@ 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()); @@ -361,7 +393,7 @@ class Order extends BaseAction implements EventSubscriberInterface ; // Build subject and body - $message->build($parser, $instance); + $message->build($this->parser, $instance); $this->getMailer()->send($instance); } @@ -375,9 +407,7 @@ class Order extends BaseAction implements EventSubscriberInterface */ public function getMailer() { - $mailer = $this->container->get('mailer'); - - return $mailer->getSwiftMailer(); + return $this->mailer->getSwiftMailer(); } /** @@ -468,24 +498,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 * @@ -493,8 +505,6 @@ class Order extends BaseAction implements EventSubscriberInterface */ protected function getSession() { - $request = $this->getRequest(); - - return $request->getSession(); + return $this->request->getSession(); } } 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 8f1f50531..514ff5ceb 100644 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -6,6 +6,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -15,161 +44,114 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - 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/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/Order/OrderPaymentEvent.php b/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php new file mode 100644 index 000000000..780d5a12c --- /dev/null +++ b/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php @@ -0,0 +1,53 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event\Module; + +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Module; +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/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/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/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 c3e48dc8e..c6d049651 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 13335d4c8..a9779ab15 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..46440cc52 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php +++ b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php @@ -23,7 +23,7 @@ namespace Thelia\Core\Template\Smarty\Assets; -use Thelia\Core\Template\TemplateDefinition; + use Thelia\Tools\URL; use Thelia\Core\Template\Assets\AssetManagerInterface; 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/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/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..6ce7cb7c1 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -398,10 +398,13 @@ class CheckPermission extends BaseInstall // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; + break; case 'm': $val *= 1024; + break; case 'k': $val *= 1024; + break; } return $val; 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/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 b570959e0..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; + /** * 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/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/Tools/FileManagerTest.php b/core/lib/Thelia/Tests/Tools/FileManagerTest.php index 0c0f0e4e7..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; diff --git a/core/lib/Thelia/Tools/FileManager.php b/core/lib/Thelia/Tools/FileManager.php index 89365c49e..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; diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index cf593bf06..575ec545a 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 { 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/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)); } /** From dfbbf90e0fda68d03b3f51e5c9e62994480e47d6 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Sat, 1 Feb 2014 14:42:09 +0100 Subject: [PATCH 13/45] Fixed returnBytes (breaks are removed) --- core/lib/Thelia/Install/CheckPermission.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index 6ce7cb7c1..4ace03c8b 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -394,17 +394,15 @@ 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': $val *= 1024; - break; case 'm': $val *= 1024; - break; case 'k': $val *= 1024; - break; } return $val; From 1e4eaf1093a98616024cd77c63d87d80b6b2d6f2 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Sat, 1 Feb 2014 19:07:02 +0100 Subject: [PATCH 14/45] Fixed wrong namespace --- core/lib/Thelia/Action/Module.php | 8 ++++---- core/lib/Thelia/Action/Order.php | 2 +- core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 4468c7bce..47cf10759 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -31,14 +31,14 @@ 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\Module\OrderPaymentEvent; +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 diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index d217bfbf8..e4e6a7620 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -27,10 +27,10 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Cart\CartTrait; use Thelia\Core\Event\Cart\CartEvent; -use Thelia\Core\Event\Module\OrderPaymentEvent; 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; diff --git a/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php b/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php index 780d5a12c..e5e1b34c0 100644 --- a/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php +++ b/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php @@ -21,11 +21,9 @@ /* */ /*************************************************************************************/ -namespace Thelia\Core\Event\Module; +namespace Thelia\Core\Event\Order; use Thelia\Core\Event\ActionEvent; -use Thelia\Model\Module; -use Thelia\Model\Order; /** * Class PaymentEvent From 220d4051425648109fdc535cb3575f3af2a76ff0 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Sat, 1 Feb 2014 19:17:28 +0100 Subject: [PATCH 15/45] Fixed typo --- core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php b/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php index e5e1b34c0..0447c0a3e 100644 --- a/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php +++ b/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php @@ -24,6 +24,7 @@ namespace Thelia\Core\Event\Order; use Thelia\Core\Event\ActionEvent; +use Thelia\Model\Order; /** * Class PaymentEvent From 0c87b7606c5f573c1016b5c4ccdb5f514976f8f6 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 09:13:26 +0100 Subject: [PATCH 16/45] start creating test for Area action --- .../Core/Event/Area/AreaCreateEvent.php | 2 + core/lib/Thelia/Core/Event/Area/AreaEvent.php | 5 +- core/lib/Thelia/Tests/Action/AreaTest.php | 57 +++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 core/lib/Thelia/Tests/Action/AreaTest.php 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/Tests/Action/AreaTest.php b/core/lib/Thelia/Tests/Action/AreaTest.php new file mode 100644 index 000000000..a67ebc205 --- /dev/null +++ b/core/lib/Thelia/Tests/Action/AreaTest.php @@ -0,0 +1,57 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +use Thelia\Action\Area; +use Thelia\Core\Event\Area\AreaCreateEvent; + + +/** + * 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()); + } + +} \ No newline at end of file From c18718254c126594d15447415fe4976740fc91bd Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 11:40:12 +0100 Subject: [PATCH 17/45] test area listener (#198] --- core/lib/Thelia/Action/Area.php | 2 + core/lib/Thelia/Tests/Action/AreaTest.php | 95 +++++++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/core/lib/Thelia/Action/Area.php b/core/lib/Thelia/Action/Area.php index 51d9ef04d..19037c9e4 100644 --- a/core/lib/Thelia/Action/Area.php +++ b/core/lib/Thelia/Action/Area.php @@ -56,6 +56,8 @@ class Area extends BaseAction implements EventSubscriberInterface public function removeCountry(AreaRemoveCountryEvent $event) { if (null !== $country = CountryQuery::create()->findPk($event->getCountryId())) { + $event->setArea($country->getArea()); + $country->setDispatcher($event->getDispatcher()); $country->setAreaId(null) ->save(); diff --git a/core/lib/Thelia/Tests/Action/AreaTest.php b/core/lib/Thelia/Tests/Action/AreaTest.php index a67ebc205..bfc756e5b 100644 --- a/core/lib/Thelia/Tests/Action/AreaTest.php +++ b/core/lib/Thelia/Tests/Action/AreaTest.php @@ -24,7 +24,13 @@ 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; /** @@ -52,6 +58,95 @@ class AreaTest extends \PHPUnit_Framework_TestCase $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 From bc61ca3d191566957e88bed887f2cff1868feb87 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 13:41:40 +0100 Subject: [PATCH 18/45] fix send mail order --- core/lib/Thelia/Action/Order.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index 69d8645ac..b90f49537 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -333,7 +333,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) { @@ -358,11 +358,11 @@ class Order extends BaseAction implements EventSubscriberInterface $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($parser, $instance); $this->getMailer()->send($instance); } From 4e691eea278573f87ae109a572ed0ab7b136efc2 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 30 Jan 2014 09:42:14 +0100 Subject: [PATCH 19/45] remive double POSTAGE setting in order loop --- core/lib/Thelia/Core/Template/Loop/Order.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/lib/Thelia/Core/Template/Loop/Order.php b/core/lib/Thelia/Core/Template/Loop/Order.php index c6d049651..870ce2121 100644 --- a/core/lib/Thelia/Core/Template/Loop/Order.php +++ b/core/lib/Thelia/Core/Template/Loop/Order.php @@ -265,7 +265,6 @@ class Order extends BaseLoop implements SearchLoopInterface, PropelSearchLoopInt ->set("DELIVERY_MODULE", $order->getDeliveryModuleId()) ->set("STATUS", $order->getStatusId()) ->set("LANG", $order->getLangId()) - ->set("POSTAGE", $order->getPostage()) ->set("DISCOUNT", $order->getDiscount()) ->set("TOTAL_TAX", $tax) ->set("TOTAL_AMOUNT", $amount - $tax) From ce80360a23a6a7e6f33b71fd23ae480cafdfa267 Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Thu, 30 Jan 2014 15:13:29 +0100 Subject: [PATCH 20/45] remove useless code --- core/lib/Thelia/Core/Template/Loop/OrderCoupon.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php b/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php index a9779ab15..449cc1e29 100644 --- a/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php +++ b/core/lib/Thelia/Core/Template/Loop/OrderCoupon.php @@ -78,17 +78,17 @@ class OrderCoupon extends BaseLoop implements PropelSearchLoopInterface /** @var OrderCoupon $orderCoupon */ foreach ($loopResult->getResultDataCollection() as $orderCoupon) { $loopResultRow = new LoopResultRow($orderCoupon); - $conditions = $conditionFactory->unserializeConditionCollection( + /*$conditions = $conditionFactory->unserializeConditionCollection( $orderCoupon->getSerializedConditions() - ); + );*/ $now = time(); $datediff = $orderCoupon->getExpirationDate()->getTimestamp() - $now; $daysLeftBeforeExpiration = floor($datediff/(60*60*24)); - $cleanedConditions = array(); + /*$cleanedConditions = array(); - /*foreach ($conditions->getConditions() as $condition) { + foreach ($conditions->getConditions() as $condition) { $cleanedConditions[] = $condition->getToolTip(); }*/ $loopResultRow->set("ID", $orderCoupon->getId()) From 1548194a1c7c791998e67fb6dda42745f9b56b37 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 13:41:40 +0100 Subject: [PATCH 21/45] fix send mail order --- core/lib/Thelia/Action/Order.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index e4e6a7620..f7ddf487b 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -366,7 +366,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) { @@ -389,11 +389,11 @@ class Order extends BaseAction implements EventSubscriberInterface $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($this->parser, $instance); + $message->buildMessage($this->parser, $instance); $this->getMailer()->send($instance); } From a28e50c7e2b124ada1df1a5feaaec7cbb43501ad Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 23 Jan 2014 19:49:36 +0100 Subject: [PATCH 22/45] Added a way to create orders outside of the front-office context. --- core/lib/Thelia/Action/Order.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index f7ddf487b..672d312a8 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -52,6 +52,8 @@ use Thelia\Model\OrderProductAttributeCombination; use Thelia\Model\OrderStatus; use Thelia\Model\OrderStatusQuery; use Thelia\Tools\I18n; +use Thelia\Model\Country; + /** * @@ -149,6 +151,7 @@ class Order extends BaseAction implements EventSubscriberInterface } protected function createOrder(EventDispatcherInterface $dispatcher, ModelOrder $sessionOrder, Currency $currency, Lang $lang, CartModel $cart, CustomerModel $customer) + { $con = \Propel\Runtime\Propel::getConnection( OrderTableMap::DATABASE_NAME @@ -156,7 +159,7 @@ class Order extends BaseAction implements EventSubscriberInterface $con->beginTransaction(); - /* use a copy to avoid errored record in session */ + $placedOrder = $sessionOrder->copy(); $placedOrder->setDispatcher($dispatcher); @@ -338,6 +341,7 @@ class Order extends BaseAction implements EventSubscriberInterface $event->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder)); + /* clear session */ $session ->setProcessedOrder($placedOrder) From 779c33ac79b839450c3b8d588179708d319290e6 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 31 Jan 2014 16:03:02 +0100 Subject: [PATCH 23/45] Fixed wrong namespace --- core/lib/Thelia/Action/Order.php | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index 672d312a8..d1e5fb40c 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -342,6 +342,7 @@ class Order extends BaseAction implements EventSubscriberInterface $event->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder)); + /* clear session */ $session ->setProcessedOrder($placedOrder) From 3fd8f5adbb759c8586a9310dd5ff8c7b2ec4b9b6 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Fri, 31 Jan 2014 20:04:25 +0100 Subject: [PATCH 24/45] Removes container from all Thelia actions, but Modules (#198) --- core/lib/Thelia/Action/Module.php | 1 + core/lib/Thelia/Action/Order.php | 3 +- .../Core/Event/Order/OrderPaymentEvent.php | 102 +++++++++--------- core/lib/Thelia/Install/CheckPermission.php | 3 + 4 files changed, 56 insertions(+), 53 deletions(-) diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 47cf10759..049edcbb0 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -32,6 +32,7 @@ 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; diff --git a/core/lib/Thelia/Action/Order.php b/core/lib/Thelia/Action/Order.php index d1e5fb40c..7366358db 100644 --- a/core/lib/Thelia/Action/Order.php +++ b/core/lib/Thelia/Action/Order.php @@ -151,7 +151,6 @@ class Order extends BaseAction implements EventSubscriberInterface } protected function createOrder(EventDispatcherInterface $dispatcher, ModelOrder $sessionOrder, Currency $currency, Lang $lang, CartModel $cart, CustomerModel $customer) - { $con = \Propel\Runtime\Propel::getConnection( OrderTableMap::DATABASE_NAME @@ -342,7 +341,6 @@ class Order extends BaseAction implements EventSubscriberInterface $event->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder)); - /* clear session */ $session ->setProcessedOrder($placedOrder) @@ -400,6 +398,7 @@ class Order extends BaseAction implements EventSubscriberInterface // Build subject and body $message->buildMessage($this->parser, $instance); + $this->getMailer()->send($instance); } } diff --git a/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php b/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php index 0447c0a3e..13211092e 100644 --- a/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php +++ b/core/lib/Thelia/Core/Event/Order/OrderPaymentEvent.php @@ -1,52 +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; - } +. */ +/* */ +/*************************************************************************************/ + +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/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index 4ace03c8b..a9059bf73 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -399,10 +399,13 @@ class CheckPermission extends BaseInstall // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; + break; case 'm': $val *= 1024; + break; case 'k': $val *= 1024; + break; } return $val; From 31dc5238de4770366a7b05b852fa15664b5c9b5a Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 14:07:23 +0100 Subject: [PATCH 25/45] change container interface, using good one --- core/lib/Thelia/Action/Module.php | 4 ++-- core/lib/Thelia/Install/CheckPermission.php | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 049edcbb0..01a54b1ab 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -23,7 +23,7 @@ namespace Thelia\Action; use Propel\Runtime\Propel; -use Propel\Runtime\ServiceContainer\ServiceContainerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Filesystem\Filesystem; @@ -53,7 +53,7 @@ class Module extends BaseAction implements EventSubscriberInterface */ protected $container; - public function __construct(ServiceContainerInterface $container) + public function __construct(ContainerInterface $container) { $this->container = $container; } diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index a9059bf73..4ace03c8b 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -399,13 +399,10 @@ class CheckPermission extends BaseInstall // The 'G' modifier is available since PHP 5.1.0 case 'g': $val *= 1024; - break; case 'm': $val *= 1024; - break; case 'k': $val *= 1024; - break; } return $val; From 923055826ab2c8dfeabd463bffd5e4e516ac42fe Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 15:04:37 +0100 Subject: [PATCH 26/45] create test suite for attribute listener --- .../lib/Thelia/Tests/Action/AttributeTest.php | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 core/lib/Thelia/Tests/Action/AttributeTest.php 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 From 1a72594dac8cc2865310b240e61292f60440fd35 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Mon, 3 Feb 2014 15:30:03 +0100 Subject: [PATCH 27/45] Using protected member $securityContext instez of a protected getter --- core/lib/Thelia/Action/Customer.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php index d02f895d4..1903cc45a 100644 --- a/core/lib/Thelia/Action/Customer.php +++ b/core/lib/Thelia/Action/Customer.php @@ -127,7 +127,7 @@ class Customer extends BaseAction implements EventSubscriberInterface public function login(CustomerLoginEvent $event) { - $this->getSecurityContext()->setCustomerUser($event->getCustomer()); + $this->securityContext->setCustomerUser($event->getCustomer()); } /** @@ -137,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->securityContext; + $this->securityContext->clearCustomerUser(); } /** From 84f8a15faca874b80de75e6cbd47071c0578a278 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Mon, 3 Feb 2014 15:31:05 +0100 Subject: [PATCH 28/45] Fixed Customer action configuration, the secutiry context was missing --- core/lib/Thelia/Config/Resources/action.xml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/action.xml b/core/lib/Thelia/Config/Resources/action.xml index 514ff5ceb..717c96975 100644 --- a/core/lib/Thelia/Config/Resources/action.xml +++ b/core/lib/Thelia/Config/Resources/action.xml @@ -34,6 +34,11 @@ + + + + + @@ -47,10 +52,6 @@ - - - - From aa993b0cf99c5d7a984aff16fe33496b8fdf4bf1 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Mon, 3 Feb 2014 15:31:34 +0100 Subject: [PATCH 29/45] Using protected $container instead of (missing) getContainer() method --- core/lib/Thelia/Action/Module.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index 01a54b1ab..f882c6daa 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -49,7 +49,7 @@ use Thelia\Module\BaseModule; class Module extends BaseAction implements EventSubscriberInterface { /** - * @var \Propel\Runtime\ServiceContainer\ServiceContainerInterface + * @var ContainerInterface */ protected $container; @@ -66,7 +66,7 @@ class Module extends BaseAction implements EventSubscriberInterface $moduleInstance = $moduleClass->newInstance(); if ( method_exists($moduleInstance, 'setContainer')) { - $moduleInstance->setContainer($this->getContainer()); + $moduleInstance->setContainer($this->container); if ($module->getActivate() == BaseModule::IS_ACTIVATED) { $moduleInstance->deActivate($module); } else { @@ -99,7 +99,7 @@ class Module extends BaseAction implements EventSubscriberInterface $reflected = new \ReflectionClass($module->getFullNamespace()); $instance = $reflected->newInstance(); - $instance->setContainer($this->getContainer()); + $instance->setContainer($this->container); $path = dirname($reflected->getFileName()); @@ -193,7 +193,7 @@ class Module extends BaseAction implements EventSubscriberInterface { $cacheEvent = new CacheEvent( $dispatcher, - $this->getContainer()->getParameter('kernel.cache_dir') + $this->container->getParameter('kernel.cache_dir') ); $dispatcher->dispatch(TheliaEvents::CACHE_CLEAR, $cacheEvent); From 01950e455680f4f14ff6668c254d0aa5a8a8a9f8 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 15:57:43 +0100 Subject: [PATCH 30/45] create test suite pour AttributeAv listener --- .../Thelia/Tests/Action/AttributeAvTest.php | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 core/lib/Thelia/Tests/Action/AttributeAvTest.php 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 From ee5cf9af4de7940edf00c646b6b77f0b09147fea Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 16:05:22 +0100 Subject: [PATCH 31/45] create test for cache clear listener --- .../Thelia/Tests/Action/assets/CacheTest.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 core/lib/Thelia/Tests/Action/assets/CacheTest.php diff --git a/core/lib/Thelia/Tests/Action/assets/CacheTest.php b/core/lib/Thelia/Tests/Action/assets/CacheTest.php new file mode 100644 index 000000000..dd5390c32 --- /dev/null +++ b/core/lib/Thelia/Tests/Action/assets/CacheTest.php @@ -0,0 +1,59 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action\assets; + +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 From 437e5826c5e9099d0b1ce2f1853d47f8b5337582 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 16:08:33 +0100 Subject: [PATCH 32/45] refactor CacheTest, moving it in good directory --- core/lib/Thelia/Tests/Action/{assets => }/CacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename core/lib/Thelia/Tests/Action/{assets => }/CacheTest.php (98%) diff --git a/core/lib/Thelia/Tests/Action/assets/CacheTest.php b/core/lib/Thelia/Tests/Action/CacheTest.php similarity index 98% rename from core/lib/Thelia/Tests/Action/assets/CacheTest.php rename to core/lib/Thelia/Tests/Action/CacheTest.php index dd5390c32..5768581e5 100644 --- a/core/lib/Thelia/Tests/Action/assets/CacheTest.php +++ b/core/lib/Thelia/Tests/Action/CacheTest.php @@ -21,7 +21,7 @@ /* */ /*************************************************************************************/ -namespace Thelia\Tests\Action\assets; +namespace Thelia\Tests\Action; use Symfony\Component\Filesystem\Filesystem; use Thelia\Action\Cache; From 6f4ef3b45a82bc0b45fb844209cd93b87510d38d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 16:11:38 +0100 Subject: [PATCH 33/45] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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 From 643099c1b6bc3b7f95b73c650f54cc24388d9da9 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Feb 2014 18:03:09 +0100 Subject: [PATCH 34/45] create test suite for category listener --- core/lib/Thelia/Tests/Action/CategoryTest.php | 208 ++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 core/lib/Thelia/Tests/Action/CategoryTest.php diff --git a/core/lib/Thelia/Tests/Action/CategoryTest.php b/core/lib/Thelia/Tests/Action/CategoryTest.php new file mode 100644 index 000000000..480c6f437 --- /dev/null +++ b/core/lib/Thelia/Tests/Action/CategoryTest.php @@ -0,0 +1,208 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Action; + +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\Tools\URL; + + +/** + * Class CategoryTest + * @package Thelia\Tests\Action + * @author Manuel Raynaud + */ +class CategoryTest extends \PHPUnit_Framework_TestCase +{ + use RewrittenUrlTestTrait; + + /** + * @var EventDispatcherInterface + */ + protected $dispatcher; + + public function setUp() + { + $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); + } + + 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->dispatcher) + ; + } + + public function getUpdateSeoEvent(&$category) + { + if (!$category instanceof \Thelia\Model\Category) { + $category = $this->getRandomCategory(); + } + + $event = new UpdateSeoEvent($category->getId()); + $event->setDispatcher($this->dispatcher); + $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->dispatcher); + + $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->dispatcher) + ; + + $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->dispatcher); + + $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 From 312e4a93f3f4a61c25e653a800d56cf07290e33b Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Mon, 3 Feb 2014 18:53:01 +0100 Subject: [PATCH 35/45] Fixed URL class initialization proble in Unit Test --- core/lib/Thelia/Tests/Action/CategoryTest.php | 29 ++++++------------- .../Thelia/Tests/TestCaseWithURLToolSetup.php | 17 ++++++++--- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/core/lib/Thelia/Tests/Action/CategoryTest.php b/core/lib/Thelia/Tests/Action/CategoryTest.php index 480c6f437..50d60f01a 100644 --- a/core/lib/Thelia/Tests/Action/CategoryTest.php +++ b/core/lib/Thelia/Tests/Action/CategoryTest.php @@ -23,6 +23,8 @@ 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; @@ -30,6 +32,7 @@ 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; @@ -38,19 +41,8 @@ use Thelia\Tools\URL; * @package Thelia\Tests\Action * @author Manuel Raynaud */ -class CategoryTest extends \PHPUnit_Framework_TestCase +class CategoryTest extends TestCaseWithURLToolSetup { - use RewrittenUrlTestTrait; - - /** - * @var EventDispatcherInterface - */ - protected $dispatcher; - - public function setUp() - { - $this->dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); - } protected function getRandomCategory() { @@ -81,7 +73,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase ->setPostscriptum('bar postscriptum') ->setVisible(0) ->setParent(0) - ->setDispatcher($this->dispatcher) + ->setDispatcher($this->getDispatcher()) ; } @@ -92,7 +84,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase } $event = new UpdateSeoEvent($category->getId()); - $event->setDispatcher($this->dispatcher); + $event->setDispatcher($this->getDispatcher()); $event ->setLocale($category->getLocale()) ->setMetaTitle($category->getMetaTitle()) @@ -127,7 +119,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase ->setParent(0) ->setTitle('foo') ->setVisible(1) - ->setDispatcher($this->dispatcher); + ->setDispatcher($this->getDispatcher()); $action = new Category(); $action->create($event); @@ -165,7 +157,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase ->setPostscriptum('bar postscriptum') ->setVisible(0) ->setParent(0) - ->setDispatcher($this->dispatcher) + ->setDispatcher($this->getDispatcher()) ; $action = new Category(); @@ -192,7 +184,7 @@ class CategoryTest extends \PHPUnit_Framework_TestCase public function testDelete(CategoryModel $category) { $event = new CategoryDeleteEvent($category->getId()); - $event->setDispatcher($this->dispatcher); + $event->setDispatcher($this->getDispatcher()); $action = new Category(); $action->delete($event); @@ -201,8 +193,5 @@ class CategoryTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('Thelia\Model\Category', $deletedCategory); $this->assertTrue($deletedCategory->isDeleted()); - - } - } \ No newline at end of file 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; + } } From 726d7ffe91085add5e1400caa44769e5090a9934 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Mon, 3 Feb 2014 23:17:52 +0100 Subject: [PATCH 36/45] Fixed image generation for products, which was broken. --- install/faker.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/faker.php b/install/faker.php index 5432021b7..5df84b32f 100644 --- a/install/faker.php +++ b/install/faker.php @@ -524,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; } From b18718293f3ba7d72fdf5b35031fd27f38ec69f0 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 4 Feb 2014 00:20:45 +0100 Subject: [PATCH 37/45] Fixed a wrong CacheEvent instanciation. --- core/lib/Thelia/Action/Module.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/lib/Thelia/Action/Module.php b/core/lib/Thelia/Action/Module.php index f882c6daa..249aab3b2 100644 --- a/core/lib/Thelia/Action/Module.php +++ b/core/lib/Thelia/Action/Module.php @@ -192,7 +192,6 @@ class Module extends BaseAction implements EventSubscriberInterface protected function cacheClear(EventDispatcherInterface $dispatcher) { $cacheEvent = new CacheEvent( - $dispatcher, $this->container->getParameter('kernel.cache_dir') ); From 102d5239a9a60e70edf868ea13222d749056a6e9 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 4 Feb 2014 00:51:38 +0100 Subject: [PATCH 38/45] Added a specific handling for a proper outpur of Exceptions in the log. --- core/lib/Thelia/Log/Tlog.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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; } From f9be7d19637e169a93111a28b7bf00e2ff68c801 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 4 Feb 2014 00:55:02 +0100 Subject: [PATCH 39/45] Imporved exception logging --- .../Controller/Admin/ModuleController.php | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) 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) { From e08ea4e14fc24160ffa57cd4477236989f310318 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 4 Feb 2014 00:56:50 +0100 Subject: [PATCH 40/45] Improved template pathes management: no more \ and / mix --- .../Core/Template/Assets/AsseticAssetManager.php | 11 ++++++++--- .../Smarty/Assets/SmartyAssetsManager.php | 6 ++++++ .../Thelia/Core/Template/TemplateDefinition.php | 16 ++++++++-------- core/lib/Thelia/Core/Template/TemplateHelper.php | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) 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/Smarty/Assets/SmartyAssetsManager.php b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php index 46440cc52..d595fdbe4 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php +++ b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php @@ -24,6 +24,7 @@ namespace Thelia\Core\Template\Smarty\Assets; +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/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); } From 15c5532bff3e54e6f085a7f0da07d31f2dd4f528 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 4 Feb 2014 01:09:11 +0100 Subject: [PATCH 41/45] Added the countvar param to module_include plugin, to get the number of found modules in the calling template (optional) --- .../Core/Template/Smarty/Plugins/Module.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 ""; } From 3efc724101643c575c83e54a62fe2fa5c0b0af23 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 4 Feb 2014 01:31:39 +0100 Subject: [PATCH 42/45] Improved empty "Modules" tab in products, folders, categories and content. --- .../backOffice/default/assets/less/thelia/thelia.less | 4 ++++ templates/backOffice/default/category-edit.html | 10 ++++++++-- templates/backOffice/default/content-edit.html | 10 ++++++++-- templates/backOffice/default/folder-edit.html | 11 +++++++++-- templates/backOffice/default/product-edit.html | 10 ++++++++-- 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/templates/backOffice/default/assets/less/thelia/thelia.less b/templates/backOffice/default/assets/less/thelia/thelia.less index ce9da65a9..849d6caf3 100644 --- a/templates/backOffice/default/assets/less/thelia/thelia.less +++ b/templates/backOffice/default/assets/less/thelia/thelia.less @@ -222,6 +222,10 @@ } } +.module-tab { + margin-top: 1.5em; +} + .tab-content { // Center loading indicator .loading { diff --git a/templates/backOffice/default/category-edit.html b/templates/backOffice/default/category-edit.html index 1885d8201..d6d7f6e1d 100644 --- a/templates/backOffice/default/category-edit.html +++ b/templates/backOffice/default/category-edit.html @@ -260,8 +260,14 @@ {include file='includes/document-upload-form.html' documentType='category' parentId=$ID} -
- {module_include location='category-edit'} +
+ {module_include location='category-edit' countvar='module_count'} + + {if $countvar == 0} +
+ {intl l="There are currently no active module here."} +
+ {/if}
diff --git a/templates/backOffice/default/content-edit.html b/templates/backOffice/default/content-edit.html index 1014d512c..fba40a1e1 100644 --- a/templates/backOffice/default/content-edit.html +++ b/templates/backOffice/default/content-edit.html @@ -155,8 +155,14 @@ {include file='includes/document-upload-form.html' documentType='content' parentId=$content_id} -
- {module_include location='content-edit'} +
+ {module_include location='content-edit' countvar='module_count'} + + {if $countvar == 0} +
+ {intl l="There are currently no active module here."} +
+ {/if}
diff --git a/templates/backOffice/default/folder-edit.html b/templates/backOffice/default/folder-edit.html index e86790634..30dde9a2b 100644 --- a/templates/backOffice/default/folder-edit.html +++ b/templates/backOffice/default/folder-edit.html @@ -141,8 +141,15 @@ {include file='includes/document-upload-form.html' documentType='folder' parentId=$ID} -
- {module_include location='folder-edit'} +
+ + {module_include location='folder-edit' countvar='module_count'} + + {if $countvar == 0} +
+ {intl l="There are currently no active module here."} +
+ {/if}
diff --git a/templates/backOffice/default/product-edit.html b/templates/backOffice/default/product-edit.html index 7a91f2647..f3deaa993 100644 --- a/templates/backOffice/default/product-edit.html +++ b/templates/backOffice/default/product-edit.html @@ -108,8 +108,14 @@
{intl l="Please wait, loading"}
-
- {module_include location='product-edit'} +
+ {module_include location='product-edit' countvar='module_count'} + + {if $countvar == 0} +
+ {intl l="There are currently no active module here."} +
+ {/if}
From 5381bb2f44a42bdf621a2cce8f5772121996c2ed Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 4 Feb 2014 01:37:56 +0100 Subject: [PATCH 43/45] Fixed typo (are -> is) --- templates/backOffice/default/category-edit.html | 2 +- templates/backOffice/default/content-edit.html | 4 ++-- templates/backOffice/default/folder-edit.html | 2 +- templates/backOffice/default/product-edit.html | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/backOffice/default/category-edit.html b/templates/backOffice/default/category-edit.html index d6d7f6e1d..5286e3ac9 100644 --- a/templates/backOffice/default/category-edit.html +++ b/templates/backOffice/default/category-edit.html @@ -265,7 +265,7 @@ {if $countvar == 0}
- {intl l="There are currently no active module here."} + {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 fba40a1e1..3d8f778fe 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} @@ -160,7 +160,7 @@ {if $countvar == 0}
- {intl l="There are currently no active module here."} + {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 30dde9a2b..22523bc7a 100644 --- a/templates/backOffice/default/folder-edit.html +++ b/templates/backOffice/default/folder-edit.html @@ -147,7 +147,7 @@ {if $countvar == 0}
- {intl l="There are currently no active module here."} + {intl l="There is currently no active module here."}
{/if} diff --git a/templates/backOffice/default/product-edit.html b/templates/backOffice/default/product-edit.html index f3deaa993..d8a95d9a6 100644 --- a/templates/backOffice/default/product-edit.html +++ b/templates/backOffice/default/product-edit.html @@ -113,7 +113,7 @@ {if $countvar == 0}
- {intl l="There are currently no active module here."} + {intl l="There is currently no active module here."}
{/if} From 6618d2c57130ff3b507ba6bc9c4b88060914e279 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 4 Feb 2014 02:14:56 +0100 Subject: [PATCH 44/45] Fixed an extra '&' when removing a duplicate parameter from query string --- core/lib/Thelia/Tools/URL.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/Thelia/Tools/URL.php b/core/lib/Thelia/Tools/URL.php index 575ec545a..0334ac72e 100644 --- a/core/lib/Thelia/Tools/URL.php +++ b/core/lib/Thelia/Tools/URL.php @@ -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)); } From 02da205a52d4c09fa2c6f58905ef0d101333ad9a Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 4 Feb 2014 02:15:58 +0100 Subject: [PATCH 45/45] Added the flag bar to the "Modules" tab of products, categories, folders and contents. --- .../default/assets/less/thelia/thelia.less | 4 ---- templates/backOffice/default/category-edit.html | 12 +++++++++++- templates/backOffice/default/content-edit.html | 12 +++++++++++- templates/backOffice/default/folder-edit.html | 11 ++++++++++- .../default/includes/inner-form-toolbar.html | 7 ++++++- templates/backOffice/default/includes/seo-tab.html | 1 + templates/backOffice/default/product-edit.html | 12 +++++++++++- 7 files changed, 50 insertions(+), 9 deletions(-) diff --git a/templates/backOffice/default/assets/less/thelia/thelia.less b/templates/backOffice/default/assets/less/thelia/thelia.less index 849d6caf3..ce9da65a9 100644 --- a/templates/backOffice/default/assets/less/thelia/thelia.less +++ b/templates/backOffice/default/assets/less/thelia/thelia.less @@ -222,10 +222,6 @@ } } -.module-tab { - margin-top: 1.5em; -} - .tab-content { // Center loading indicator .loading { diff --git a/templates/backOffice/default/category-edit.html b/templates/backOffice/default/category-edit.html index 5286e3ac9..8f3fc4e40 100644 --- a/templates/backOffice/default/category-edit.html +++ b/templates/backOffice/default/category-edit.html @@ -260,7 +260,17 @@ {include file='includes/document-upload-form.html' documentType='category' parentId=$ID} -
+
+
+ {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} diff --git a/templates/backOffice/default/content-edit.html b/templates/backOffice/default/content-edit.html index 3d8f778fe..49c8f6b66 100644 --- a/templates/backOffice/default/content-edit.html +++ b/templates/backOffice/default/content-edit.html @@ -155,7 +155,17 @@ {include file='includes/document-upload-form.html' documentType='content' parentId=$content_id}
-
+
+
+ {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} diff --git a/templates/backOffice/default/folder-edit.html b/templates/backOffice/default/folder-edit.html index 22523bc7a..bff41f094 100644 --- a/templates/backOffice/default/folder-edit.html +++ b/templates/backOffice/default/folder-edit.html @@ -141,7 +141,16 @@ {include file='includes/document-upload-form.html' documentType='folder' parentId=$ID}
-
+
+
+ {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'} 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:
-
+
+
+ {include + file = "includes/inner-form-toolbar.html" + hide_submit_buttons = true + page_url = {$pageUrl} + close_url = {$closeUrl} + current_tab = "modules" + } +
+ {module_include location='product-edit' countvar='module_count'} {if $countvar == 0}