From 101197c0de9b22332b1a7852213f8dd11d10ae84 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 18 Jun 2014 09:33:32 +0200 Subject: [PATCH 1/2] various fixes from insight --- core/bootstrap.php | 1 - .../Controller/Admin/BaseAdminController.php | 1 - .../Controller/Admin/CountryController.php | 5 ++- .../Controller/Admin/CouponController.php | 39 +++++++++++-------- .../Core/EventListener/ViewListener.php | 1 - core/lib/Thelia/Core/Template/Loop/Coupon.php | 2 - core/lib/Thelia/Core/TheliaHttpKernel.php | 1 - .../Thelia/Core/Translation/Translator.php | 6 --- core/lib/Thelia/Install/Update.php | 1 - core/lib/Thelia/Model/Cart.php | 1 - core/lib/Thelia/Model/Message.php | 2 - 11 files changed, 26 insertions(+), 34 deletions(-) diff --git a/core/bootstrap.php b/core/bootstrap.php index 87cbb2907..8c6042711 100644 --- a/core/bootstrap.php +++ b/core/bootstrap.php @@ -32,6 +32,5 @@ if (!file_exists(THELIA_CONF_DIR . 'database.yml') && !defined('THELIA_INSTALL_M } else { $request = \Thelia\Core\HttpFoundation\Request::createFromGlobals(); header('Location: '.$request->getUriForPath('/install')); - exit; } } diff --git a/core/lib/Thelia/Controller/Admin/BaseAdminController.php b/core/lib/Thelia/Controller/Admin/BaseAdminController.php index deba32d56..27bf724cc 100644 --- a/core/lib/Thelia/Controller/Admin/BaseAdminController.php +++ b/core/lib/Thelia/Controller/Admin/BaseAdminController.php @@ -23,7 +23,6 @@ use Thelia\Model\ConfigQuery; use Symfony\Component\HttpKernel\HttpKernelInterface; use Thelia\Core\Security\Exception\AuthenticationException; use Thelia\Tools\URL; -use Thelia\Tools\Redirect; use Thelia\Model\AdminLog; use Thelia\Model\LangQuery; diff --git a/core/lib/Thelia/Controller/Admin/CountryController.php b/core/lib/Thelia/Controller/Admin/CountryController.php index 888e8943a..bdd76bc82 100644 --- a/core/lib/Thelia/Controller/Admin/CountryController.php +++ b/core/lib/Thelia/Controller/Admin/CountryController.php @@ -20,6 +20,7 @@ use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Security\AccessManager; use Thelia\Form\CountryCreationForm; use Thelia\Form\CountryModificationForm; +use Thelia\Log\Tlog; use Thelia\Model\CountryQuery; /** @@ -228,7 +229,7 @@ class CountryController extends AbstractCrudController public function toggleDefaultAction() { if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) return $response; - $content = null; + if (null !== $country_id = $this->getRequest()->get('country_id')) { $toogleDefaultEvent = new CountryToggleDefaultEvent($country_id); try { @@ -238,7 +239,7 @@ class CountryController extends AbstractCrudController return $this->nullResponse(); } } catch (\Exception $ex) { - $content = $ex->getMessage(); + Tlog::getInstance()->error($ex->getMessage()); } } diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 81c6ba2f4..8fd5e49a9 100644 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -13,6 +13,7 @@ namespace Thelia\Controller\Admin; use Symfony\Component\Form\Form; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Router; @@ -35,6 +36,7 @@ use Thelia\Model\CouponModule; use Thelia\Model\CouponQuery; use Thelia\Model\LangQuery; use Thelia\Tools\Rest\ResponseRest; +use Thelia\Tools\URL; /** * Control View and Action (Model) via Events @@ -78,11 +80,13 @@ class CouponController extends BaseAdminController $eventToDispatch = TheliaEvents::COUPON_CREATE; if ($this->getRequest()->isMethod('POST')) { - $this->validateCreateOrUpdateForm( + if(null !== $response = $this->validateCreateOrUpdateForm( $eventToDispatch, 'created', 'creation' - ); + )){ + return $response; + } } else { // If no input for expirationDate, now + 2 months $defaultDate = new \DateTime(); @@ -137,12 +141,14 @@ class CouponController extends BaseAdminController // Update if ($this->getRequest()->isMethod('POST')) { - $this->validateCreateOrUpdateForm( + if (null !== $response = $this->validateCreateOrUpdateForm( $eventToDispatch, 'updated', 'update', $coupon - ); + )) { + return $response; + } } else { // Display // Prepare the data that will hydrate the form @@ -474,7 +480,7 @@ class CouponController extends BaseAdminController { // Create the form from the request $couponForm = new CouponCreationForm($this->getRequest()); - + $response = null; $message = false; try { // Check the form against conditions violations @@ -498,19 +504,20 @@ class CouponController extends BaseAdminController ); if ($this->getRequest()->get('save_mode') == 'stay') { - $this->redirect( - str_replace( - '{id}', - $couponEvent->getCouponModel()->getId(), - $couponForm->getSuccessUrl() - ) - ); + $response = RedirectResponse::create(str_replace( + '{id}', + $couponEvent->getCouponModel()->getId(), + $couponForm->getSuccessUrl() + )); - exit(); + } else { + // Redirect to the success URL + $response = RedirectResponse::create( + URL::getInstance()->absoluteUrl($this->getRoute('admin.coupon.list')) + ); } - // Redirect to the success URL - $this->redirectToRoute('admin.coupon.list'); + } catch (FormValidationException $ex) { // Invalid data entered @@ -533,7 +540,7 @@ class CouponController extends BaseAdminController ->setGeneralError($message); } - return $this; + return $response; } /** diff --git a/core/lib/Thelia/Core/EventListener/ViewListener.php b/core/lib/Thelia/Core/EventListener/ViewListener.php index b0ed5ce2f..c30ed9acb 100644 --- a/core/lib/Thelia/Core/EventListener/ViewListener.php +++ b/core/lib/Thelia/Core/EventListener/ViewListener.php @@ -25,7 +25,6 @@ use Thelia\Core\Template\Exception\ResourceNotFoundException; use Thelia\Core\Template\TemplateHelper; use Thelia\Exception\OrderException; -use Thelia\Tools\Redirect; use Thelia\Core\Security\Exception\AuthenticationException; diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index 14444726d..c46739aa9 100644 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -154,8 +154,6 @@ class Coupon extends BaseI18nLoop implements PropelSearchLoopInterface /** @var Request $request */ $request = $this->container->get('request'); - /** @var Lang $lang */ - $lang = $request->getSession()->getLang(); /** @var MCoupon $coupon */ foreach ($loopResult->getResultDataCollection() as $coupon) { diff --git a/core/lib/Thelia/Core/TheliaHttpKernel.php b/core/lib/Thelia/Core/TheliaHttpKernel.php index 2bf5a0004..a17e90484 100644 --- a/core/lib/Thelia/Core/TheliaHttpKernel.php +++ b/core/lib/Thelia/Core/TheliaHttpKernel.php @@ -20,7 +20,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\Session; use Thelia\Core\Event\Currency\CurrencyChangeEvent; use Thelia\Core\Event\SessionEvent; diff --git a/core/lib/Thelia/Core/Translation/Translator.php b/core/lib/Thelia/Core/Translation/Translator.php index bad4d4d99..28f370c1c 100644 --- a/core/lib/Thelia/Core/Translation/Translator.php +++ b/core/lib/Thelia/Core/Translation/Translator.php @@ -14,7 +14,6 @@ namespace Thelia\Core\Translation; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Translation\Translator as BaseTranslator; -use Thelia\Log\Tlog; class Translator extends BaseTranslator { @@ -74,14 +73,9 @@ class Translator extends BaseTranslator $this->loadCatalogue($locale); } - if (! $this->catalogues[$locale]->has((string) $id, $domain)) { - - } - if ($this->catalogues[$locale]->has((string) $id, $domain)) { return parent::trans($id, $parameters, $domain, $locale); } else { - //Tlog::getInstance()->addWarning("Undefined translation: locale: $locale, domain: $domain, ID: $id"); if ($return_default_if_not_available) return strtr($id, $parameters); diff --git a/core/lib/Thelia/Install/Update.php b/core/lib/Thelia/Install/Update.php index d84ce7b74..306a1906b 100644 --- a/core/lib/Thelia/Install/Update.php +++ b/core/lib/Thelia/Install/Update.php @@ -49,7 +49,6 @@ class Update $logger = Tlog::getInstance(); $logger->setLevel(Tlog::DEBUG); - $success = true; $updatedVersions = array(); $currentVersion = ConfigQuery::read('thelia_version'); diff --git a/core/lib/Thelia/Model/Cart.php b/core/lib/Thelia/Model/Cart.php index aab17db46..b789374a8 100644 --- a/core/lib/Thelia/Model/Cart.php +++ b/core/lib/Thelia/Model/Cart.php @@ -44,7 +44,6 @@ class Cart extends BaseCart } $cart->save(); - $currentDateTime = new \DateTime(); foreach ($cartItems as $cartItem) { $product = $cartItem->getProduct(); diff --git a/core/lib/Thelia/Model/Message.php b/core/lib/Thelia/Model/Message.php index b96887d07..3df786b0b 100644 --- a/core/lib/Thelia/Model/Message.php +++ b/core/lib/Thelia/Model/Message.php @@ -75,8 +75,6 @@ class Message extends BaseMessage { $body = false; - //$mail_template_path = TemplateHelper::getInstance()->getActiveMailTemplate()->getAbsolutePath() . DS; - // Try to get the body from template file, if a file is defined if (! empty($template)) { try { From d14a2d24f25a4c41f568b495ae03c22047ffa116 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Wed, 18 Jun 2014 10:06:10 +0200 Subject: [PATCH 2/2] fix cs --- core/lib/Thelia/Controller/Admin/CouponController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 8fd5e49a9..06f81aaaa 100644 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -517,8 +517,6 @@ class CouponController extends BaseAdminController ); } - - } catch (FormValidationException $ex) { // Invalid data entered $message = $this->createStandardFormValidationErrorMessage($ex);