apply php-cs-fiwer on Action directory
This commit is contained in:
@@ -23,43 +23,38 @@
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Thelia\Form\CategoryDeletionForm;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Action\Exception\FormValidationException;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
|
||||
abstract class BaseAction
|
||||
{
|
||||
protected function validateForm(BaseForm $aBaseForm, $expectedMethod = null)
|
||||
{
|
||||
$form = $aBaseForm->getForm();
|
||||
protected function validateForm(BaseForm $aBaseForm, $expectedMethod = null)
|
||||
{
|
||||
$form = $aBaseForm->getForm();
|
||||
|
||||
if ($aBaseForm->getRequest()->isMethod($expectedMethod)) {
|
||||
if ($aBaseForm->getRequest()->isMethod($expectedMethod)) {
|
||||
|
||||
$form->bind($aBaseForm->getRequest());
|
||||
$form->bind($aBaseForm->getRequest());
|
||||
|
||||
if ($form->isValid()) {
|
||||
|
||||
return $form;
|
||||
}
|
||||
else {
|
||||
throw new FormValidationException("Missing or invalid data");
|
||||
if ($form->isValid()) {
|
||||
return $form;
|
||||
} else {
|
||||
throw new FormValidationException("Missing or invalid data");
|
||||
}
|
||||
} else {
|
||||
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
|
||||
}
|
||||
else {
|
||||
throw new FormValidationException(sprintf("Wrong form method, %s expected.", $expectedMethod));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param BaseForm $aBaseForm
|
||||
* @param string $error_message
|
||||
* @param ActionEvent $event
|
||||
*/
|
||||
protected function propagateFormError(BaseForm $aBaseForm, $error_message, ActionEvent $event) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param BaseForm $aBaseForm
|
||||
* @param string $error_message
|
||||
* @param ActionEvent $event
|
||||
*/
|
||||
protected function propagateFormError(BaseForm $aBaseForm, $error_message, ActionEvent $event)
|
||||
{
|
||||
// The form has an error
|
||||
$aBaseForm->setError(true);
|
||||
$aBaseForm->setErrorMessage($error_message);
|
||||
@@ -69,7 +64,7 @@ abstract class BaseAction
|
||||
|
||||
// Stop event propagation
|
||||
$event->stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
protected function redirect($url, $status = 302)
|
||||
{
|
||||
@@ -79,4 +74,4 @@ abstract class BaseAction
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,26 +40,26 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
public function create(ActionEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
$request = $event->getRequest();
|
||||
|
||||
try {
|
||||
$categoryCreationForm = new CategoryCreationForm($request);
|
||||
try {
|
||||
$categoryCreationForm = new CategoryCreationForm($request);
|
||||
|
||||
$form = $this->validateForm($categoryCreationForm, "POST");
|
||||
$form = $this->validateForm($categoryCreationForm, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
$data = $form->getData();
|
||||
|
||||
$category = new CategoryModel();
|
||||
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CREATECATEGORY, $event);
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CREATECATEGORY, $event);
|
||||
|
||||
$category->create(
|
||||
$category->create(
|
||||
$data["title"],
|
||||
$data["parent"],
|
||||
$data["locale"]
|
||||
);
|
||||
|
||||
AdminLog::append(sprintf("Category %s (ID %s) created", $category->getTitle(), $category->getId()), $request, $request->getSession()->getAdminUser());
|
||||
AdminLog::append(sprintf("Category %s (ID %s) created", $category->getTitle(), $category->getId()), $request, $request->getSession()->getAdminUser());
|
||||
|
||||
$categoryEvent = new CategoryEvent($category);
|
||||
|
||||
@@ -68,8 +68,8 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
// Substitute _ID_ in the URL with the ID of the created category
|
||||
$successUrl = str_replace('_ID_', $category->getId(), $categoryCreationForm->getSuccessUrl());
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($successUrl);
|
||||
// Redirect to the success URL
|
||||
$this->redirect($successUrl);
|
||||
|
||||
} catch (PropelException $e) {
|
||||
Tlog::getInstance()->error(sprintf('error during creating category with message "%s"', $e->getMessage()));
|
||||
@@ -83,7 +83,7 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
public function modify(ActionEvent $event)
|
||||
{
|
||||
/*
|
||||
/*
|
||||
$request = $event->getRequest();
|
||||
|
||||
$customerModification = new CustomerModification($request);
|
||||
@@ -100,9 +100,9 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
$customer = CustomerQuery::create()->findPk(1);
|
||||
try {
|
||||
$customerEvent = new CustomerEvent($customer);
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CHANGECUSTOMER, $customerEvent);
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CHANGECUSTOMER, $customerEvent);
|
||||
|
||||
$data = $form->getData();
|
||||
$data = $form->getData();
|
||||
|
||||
$customer->createOrUpdate(
|
||||
$data["title"],
|
||||
@@ -123,20 +123,17 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
// Update the logged-in user, and redirect to the success URL (exits)
|
||||
// We don-t send the login event, as the customer si already logged.
|
||||
$this->processSuccessfullLogin($event, $customer, $customerModification);
|
||||
}
|
||||
catch(PropelException $e) {
|
||||
} catch (PropelException $e) {
|
||||
|
||||
Tlog::getInstance()->error(sprintf('error during modifying customer on action/modifyCustomer with message "%s"', $e->getMessage()));
|
||||
|
||||
$message = "Failed to change your account, please try again.";
|
||||
}
|
||||
} else {
|
||||
$message = "Missing or invalid data";
|
||||
}
|
||||
else {
|
||||
$message = "Missing or invalid data";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$message = "Wrong form method !";
|
||||
} else {
|
||||
$message = "Wrong form method !";
|
||||
}
|
||||
|
||||
// The form has an error
|
||||
@@ -155,44 +152,42 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function delete(ActionEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
$request = $event->getRequest();
|
||||
|
||||
try {
|
||||
$categoryDeletionForm = new CategoryDeletionForm($request);
|
||||
try {
|
||||
$categoryDeletionForm = new CategoryDeletionForm($request);
|
||||
|
||||
$form = $this->validateForm($categoryDeletionForm, "POST");
|
||||
$form = $this->validateForm($categoryDeletionForm, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
$data = $form->getData();
|
||||
|
||||
$category = CategoryQuery::create()->findPk($data['id']);
|
||||
$category = CategoryQuery::create()->findPk($data['id']);
|
||||
|
||||
$categoryEvent = new CategoryEvent($category);
|
||||
$categoryEvent = new CategoryEvent($category);
|
||||
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_DELETECATEGORY, $categoryEvent);
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_DELETECATEGORY, $categoryEvent);
|
||||
|
||||
$category->delete();
|
||||
$category->delete();
|
||||
|
||||
AdminLog::append(sprintf("Category %s (ID %s) deleted", $category->getTitle(), $category->getId()), $request, $request->getSession()->getAdminUser());
|
||||
AdminLog::append(sprintf("Category %s (ID %s) deleted", $category->getTitle(), $category->getId()), $request, $request->getSession()->getAdminUser());
|
||||
|
||||
$categoryEvent->category = $category;
|
||||
$categoryEvent->category = $category;
|
||||
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_DELETECATEGORY, $categoryEvent);
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_DELETECATEGORY, $categoryEvent);
|
||||
|
||||
// Substitute _ID_ in the URL with the ID of the created category
|
||||
$successUrl = str_replace('_ID_', $category->getParent(), $categoryDeletionForm->getSuccessUrl());
|
||||
// Substitute _ID_ in the URL with the ID of the created category
|
||||
$successUrl = str_replace('_ID_', $category->getParent(), $categoryDeletionForm->getSuccessUrl());
|
||||
|
||||
// Redirect to the success URL
|
||||
Redirect::exec($successUrl);
|
||||
}
|
||||
catch(PropelException $e) {
|
||||
// Redirect to the success URL
|
||||
Redirect::exec($successUrl);
|
||||
} catch (PropelException $e) {
|
||||
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf('error during deleting category ID=%s on action/modifyCustomer with message "%s"', $data['id'], $e->getMessage()));
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf('error during deleting category ID=%s on action/modifyCustomer with message "%s"', $data['id'], $e->getMessage()));
|
||||
|
||||
$message = "Failed to change your account, please try again.";
|
||||
}
|
||||
catch(FormValidationException $e) {
|
||||
$message = "Failed to change your account, please try again.";
|
||||
} catch (FormValidationException $e) {
|
||||
|
||||
$message = $e->getMessage();
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
$this->propagateFormError($categoryDeletionForm, $message, $event);
|
||||
@@ -205,20 +200,20 @@ class Category extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function toggleVisibility(ActionEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
$request = $event->getRequest();
|
||||
|
||||
$category = CategoryQuery::create()->findPk($request->get('id', 0));
|
||||
$category = CategoryQuery::create()->findPk($request->get('id', 0));
|
||||
|
||||
if ($category !== null) {
|
||||
if ($category !== null) {
|
||||
|
||||
$category->setVisible($category->getVisible() ? false : true);
|
||||
$category->setVisible($category->getVisible() ? false : true);
|
||||
|
||||
$category->save();
|
||||
$category->save();
|
||||
|
||||
$categoryEvent = new CategoryEvent($category);
|
||||
$categoryEvent = new CategoryEvent($category);
|
||||
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_CHANGECATEGORY, $categoryEvent);
|
||||
}
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_CHANGECATEGORY, $categoryEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Core\Event\CustomerEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Form\CustomerCreation;
|
||||
@@ -36,14 +35,12 @@ use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Form\CustomerLogin;
|
||||
use Thelia\Core\Security\Authentication\CustomerUsernamePasswordFormAuthenticator;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Thelia\Core\Security\Exception\UsernameNotFoundException;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Action\Exception\FormValidationException;
|
||||
|
||||
|
||||
class Customer extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
@@ -51,25 +48,26 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
protected $securityContext;
|
||||
|
||||
public function __construct(SecurityContext $securityContext) {
|
||||
public function __construct(SecurityContext $securityContext)
|
||||
{
|
||||
$this->securityContext = $securityContext;
|
||||
}
|
||||
|
||||
public function create(ActionEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
$request = $event->getRequest();
|
||||
|
||||
try {
|
||||
$customerCreationForm = new CustomerCreation($request);
|
||||
try {
|
||||
$customerCreationForm = new CustomerCreation($request);
|
||||
|
||||
$form = $this->validateForm($customerCreationForm, "POST");
|
||||
$form = $this->validateForm($customerCreationForm, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
$customer = new CustomerModel();
|
||||
$customer = new CustomerModel();
|
||||
$customer->setDispatcher($event->getDispatcher());
|
||||
|
||||
$customer->createOrUpdate(
|
||||
$data["title"],
|
||||
$data["title"],
|
||||
$data["firstname"],
|
||||
$data["lastname"],
|
||||
$data["address1"],
|
||||
@@ -84,40 +82,34 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
$request->getSession()->getLang()
|
||||
);
|
||||
|
||||
|
||||
|
||||
// Connect the newly created user,and redirect to the success URL
|
||||
$this->processSuccessfullLogin($event, $customer, $customerCreationForm, true);
|
||||
}
|
||||
catch (PropelException $e) {
|
||||
} catch (PropelException $e) {
|
||||
Tlog::getInstance()->error(sprintf('error during creating customer on action/createCustomer with message "%s"', $e->getMessage()));
|
||||
|
||||
$message = "Failed to create your account, please try again.";
|
||||
}
|
||||
catch(FormValidationException $e) {
|
||||
} catch (FormValidationException $e) {
|
||||
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
// The form has errors, propagate it.
|
||||
$this->propagateFormError($customerCreationForm, $message, $event);
|
||||
}
|
||||
}
|
||||
|
||||
public function modify(ActionEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
$request = $event->getRequest();
|
||||
|
||||
try {
|
||||
$customerModification = new CustomerModification($request);
|
||||
try {
|
||||
$customerModification = new CustomerModification($request);
|
||||
|
||||
$form = $this->validateForm($customerModification, "POST");
|
||||
$form = $this->validateForm($customerModification, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
$customer = CustomerQuery::create()->findPk(1);
|
||||
|
||||
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
$customer->createOrUpdate(
|
||||
@@ -131,29 +123,24 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
$data["cellphone"],
|
||||
$data["zipcode"],
|
||||
$data["country"]
|
||||
);
|
||||
|
||||
|
||||
);
|
||||
|
||||
// Update the logged-in user, and redirect to the success URL (exits)
|
||||
// We don-t send the login event, as the customer si already logged.
|
||||
$this->processSuccessfullLogin($event, $customer, $customerModification);
|
||||
}
|
||||
catch(PropelException $e) {
|
||||
} catch (PropelException $e) {
|
||||
|
||||
Tlog::getInstance()->error(sprintf('error during modifying customer on action/modifyCustomer with message "%s"', $e->getMessage()));
|
||||
Tlog::getInstance()->error(sprintf('error during modifying customer on action/modifyCustomer with message "%s"', $e->getMessage()));
|
||||
|
||||
$message = "Failed to change your account, please try again.";
|
||||
}
|
||||
catch(FormValidationException $e) {
|
||||
} catch (FormValidationException $e) {
|
||||
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
// The form has errors, propagate it.
|
||||
$this->propagateFormError($customerModification, $message, $event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform user logout. The user is redirected to the provided view, if any.
|
||||
@@ -162,9 +149,9 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function logout(ActionEvent $event)
|
||||
{
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_LOGOUT, $event);
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_LOGOUT, $event);
|
||||
|
||||
$this->getSecurityContext()->clear();
|
||||
$this->getSecurityContext()->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,36 +164,32 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
*/
|
||||
public function login(ActionEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
$request = $event->getRequest();
|
||||
|
||||
$customerLoginForm = new CustomerLogin($request);
|
||||
$customerLoginForm = new CustomerLogin($request);
|
||||
|
||||
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
|
||||
$authenticator = new CustomerUsernamePasswordFormAuthenticator($request, $customerLoginForm);
|
||||
|
||||
try {
|
||||
$user = $authenticator->getAuthentifiedUser();
|
||||
try {
|
||||
$user = $authenticator->getAuthentifiedUser();
|
||||
|
||||
$this->processSuccessfullLogin($event, $user, $customerLoginForm);
|
||||
}
|
||||
catch (ValidatorException $ex) {
|
||||
$message = "Missing or invalid information. Please check your input.";
|
||||
}
|
||||
catch (UsernameNotFoundException $ex) {
|
||||
$message = "This email address was not found.";
|
||||
}
|
||||
catch (AuthenticationException $ex) {
|
||||
$message = "Login failed. Please check your username and password.";
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
$message = sprintf("Unable to process your request. Please try again (%s in %s).", $ex->getMessage(), $ex->getFile());
|
||||
}
|
||||
$this->processSuccessfullLogin($event, $user, $customerLoginForm);
|
||||
} catch (ValidatorException $ex) {
|
||||
$message = "Missing or invalid information. Please check your input.";
|
||||
} catch (UsernameNotFoundException $ex) {
|
||||
$message = "This email address was not found.";
|
||||
} catch (AuthenticationException $ex) {
|
||||
$message = "Login failed. Please check your username and password.";
|
||||
} catch (\Exception $ex) {
|
||||
$message = sprintf("Unable to process your request. Please try again (%s in %s).", $ex->getMessage(), $ex->getFile());
|
||||
}
|
||||
|
||||
// The for has an error
|
||||
$customerLoginForm->setError(true);
|
||||
$customerLoginForm->setErrorMessage($message);
|
||||
// The for has an error
|
||||
$customerLoginForm->setError(true);
|
||||
$customerLoginForm->setErrorMessage($message);
|
||||
|
||||
// Dispatch the errored form
|
||||
$event->setErrorForm($customerLoginForm);
|
||||
// Dispatch the errored form
|
||||
$event->setErrorForm($customerLoginForm);
|
||||
|
||||
// A this point, the same view is displayed again.
|
||||
}
|
||||
@@ -250,10 +233,10 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
*
|
||||
* Stores the current user in the security context, and redirect to the
|
||||
* success_url.
|
||||
* @param ActionEvent $event
|
||||
* @param ActionEvent $event
|
||||
* @param CustomerModel $user
|
||||
* @param BaseForm $form
|
||||
* @param bool $sendLoginEvent
|
||||
* @param BaseForm $form
|
||||
* @param bool $sendLoginEvent
|
||||
*/
|
||||
protected function processSuccessfullLogin(ActionEvent $event, CustomerModel $user, BaseForm $form, $sendLoginEvent = false)
|
||||
{
|
||||
@@ -275,7 +258,6 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
if ($sendLoginEvent) $event->getDispatcher()->dispatch(TheliaEvents::CUSTOMER_LOGIN, $event);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,9 +265,9 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
*
|
||||
* @return SecurityContext the security context
|
||||
*/
|
||||
protected function getSecurityContext() {
|
||||
//$this->securityContext->setContext(SecurityContext::CONTEXT_FRONT_OFFICE);
|
||||
|
||||
return $this->securityContext;
|
||||
protected function getSecurityContext()
|
||||
{
|
||||
//$this->securityContext->setContext(SecurityContext::CONTEXT_FRONT_OFFICE);
|
||||
return $this->securityContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Action\Exception;
|
||||
|
||||
|
||||
class ActionException extends \RuntimeException
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
namespace Thelia\Action\Exception;
|
||||
|
||||
|
||||
class FormValidationException extends ActionException
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
namespace Thelia\Action\Exception;
|
||||
|
||||
|
||||
class ProductNotFoundException extends ActionException {
|
||||
|
||||
}
|
||||
class ProductNotFoundException extends ActionException
|
||||
{
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
|
||||
namespace Thelia\Action\Exception;
|
||||
|
||||
|
||||
class StockNotFoundException extends ActionException
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user