Merge branch 'master' into rewrite
Conflicts: core/lib/Thelia/Controller/BaseController.php install/insert.sql
This commit is contained in:
@@ -150,6 +150,27 @@ class BaseAdminController extends BaseController
|
||||
return $this->container->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the route path defined for the givent route ID
|
||||
*
|
||||
* @param string $routeId a route ID, as defines in Config/Resources/routing/admin.xml
|
||||
*
|
||||
* @see \Thelia\Controller\BaseController::getRouteFromRouter()
|
||||
*/
|
||||
protected function getRoute($routeId) {
|
||||
return $this->getRouteFromRouter('router.admin', $routeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to à route ID related URL
|
||||
*
|
||||
* @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml
|
||||
* @param unknown $urlParameters the URL parametrs, as a var/value pair array
|
||||
*/
|
||||
public function redirectToRoute($routeId, $urlParameters = array()) {
|
||||
$this->redirect(URL::absoluteUrl($this->getRoute($routeId), $urlParameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current edition lang ID, checking if a change was requested in the current request
|
||||
*/
|
||||
|
||||
@@ -239,10 +239,11 @@ class ConfigController extends BaseAdminController
|
||||
// If we have to stay on the same page, do not redirect to the succesUrl,
|
||||
// just redirect to the edit page again.
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
$this->redirect(URL::absoluteUrl(
|
||||
"admin/configuration/variables/change",
|
||||
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.variables.change",
|
||||
array('variable_id' => $variable_id)
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
@@ -295,7 +296,7 @@ class ConfigController extends BaseAdminController
|
||||
$this->dispatch(TheliaEvents::CONFIG_SETVALUE, $event);
|
||||
}
|
||||
|
||||
$this->redirect(URL::absoluteUrl('/admin/configuration/variables'));
|
||||
$this->redirectToRoute('admin.configuration.variables.default');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -313,6 +314,6 @@ class ConfigController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::CONFIG_DELETE, $event);
|
||||
|
||||
$this->redirect(URL::absoluteUrl('/admin/configuration/variables'));
|
||||
$this->redirectToRoute('admin.configuration.variables.default');
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ class CurrencyController extends BaseAdminController
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.create")) return $response;
|
||||
|
||||
$currency = false;
|
||||
$error_msg = false;
|
||||
|
||||
// Create the Creation Form
|
||||
$creationForm = new CurrencyCreationForm($this->getRequest());
|
||||
@@ -120,24 +120,24 @@ class CurrencyController extends BaseAdminController
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$currency = sprintf("Please check your input: %s", $ex->getCurrency());
|
||||
$error_msg = sprintf("Please check your input: %s", $ex->getMessage());
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$currency = sprintf("Sorry, an error occured: %s", $ex->getCurrency());
|
||||
$error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage());
|
||||
}
|
||||
|
||||
if ($currency !== false) {
|
||||
if ($error_msg !== false) {
|
||||
// An error has been detected: log it
|
||||
Tlog::getInstance()->error(sprintf("Error during currency creation process : %s. Exception was %s", $currency, $ex->getCurrency()));
|
||||
Tlog::getInstance()->error(sprintf("Error during currency creation process : %s. Exception was %s", $error_msg, $ex->getMessage()));
|
||||
|
||||
// Mark the form as errored
|
||||
$creationForm->setErrorCurrency($currency);
|
||||
$creationForm->setErrorMessage($error_msg);
|
||||
|
||||
// Pass it to the parser, along with the error currency
|
||||
$this->getParserContext()
|
||||
->addForm($creationForm)
|
||||
->setGeneralError($currency)
|
||||
->setGeneralError($error_msg)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ class CurrencyController extends BaseAdminController
|
||||
'locale' => $currency->getLocale(),
|
||||
'code' => $currency->getCode(),
|
||||
'symbol' => $currency->getSymbol(),
|
||||
'rate' => $currency->getSubject()
|
||||
'rate' => $currency->getRate()
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
@@ -193,7 +193,7 @@ class CurrencyController extends BaseAdminController
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
|
||||
|
||||
$currency = false;
|
||||
$error_msg = false;
|
||||
|
||||
// Create the form from the request
|
||||
$changeForm = new CurrencyModificationForm($this->getRequest());
|
||||
@@ -230,10 +230,10 @@ class CurrencyController extends BaseAdminController
|
||||
// If we have to stay on the same page, do not redirect to the succesUrl,
|
||||
// just redirect to the edit page again.
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
$this->redirect(URL::absoluteUrl(
|
||||
"admin/configuration/currencies/change",
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.currencies.change",
|
||||
array('currency_id' => $currency_id)
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
@@ -241,24 +241,24 @@ class CurrencyController extends BaseAdminController
|
||||
}
|
||||
catch (FormValidationException $ex) {
|
||||
// Invalid data entered
|
||||
$currency = sprintf("Please check your input: %s", $ex->getCurrency());
|
||||
$error_msg = sprintf("Please check your input: %s", $ex->getMessage());
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$currency = sprintf("Sorry, an error occured: %s", $ex->getCurrency());
|
||||
$error_msg = sprintf("Sorry, an error occured: %s", $ex->getMessage());
|
||||
}
|
||||
|
||||
if ($currency !== false) {
|
||||
if ($error_msg !== false) {
|
||||
// Log error currency
|
||||
Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $currency, $ex->getCurrency()));
|
||||
Tlog::getInstance()->error(sprintf("Error during currency modification process : %s. Exception was %s", $error_msg, $ex->getMessage()));
|
||||
|
||||
// Mark the form as errored
|
||||
$changeForm->setErrorCurrency($currency);
|
||||
$changeForm->setErrorMessage($error_msg);
|
||||
|
||||
// Pas the form and the error to the parser
|
||||
$this->getParserContext()
|
||||
->addForm($changeForm)
|
||||
->setGeneralError($currency)
|
||||
->setGeneralError($error_msg)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -266,6 +266,47 @@ class CurrencyController extends BaseAdminController
|
||||
return $this->render('currency-edit', array('currency_id' => $currency_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default currency
|
||||
*/
|
||||
public function setDefaultAction() {
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
|
||||
|
||||
$changeEvent = new CurrencyChangeEvent($this->getRequest()->get('currency_id', 0));
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent->setIsDefault(true);
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CURRENCY_SET_DEFAULT, $changeEvent);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage(sprintf("Sorry, an error occured: %s", $ex->getMessage()));
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.configuration.currencies.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update currencies rates
|
||||
*/
|
||||
public function updateRatesAction() {
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth("admin.configuration.currencies.change")) return $response;
|
||||
|
||||
try {
|
||||
$this->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage(sprintf("Sorry, an error occured: %s", $ex->getMessage()));
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.configuration.currencies.default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a currency object
|
||||
*
|
||||
@@ -281,6 +322,6 @@ class CurrencyController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::CURRENCY_DELETE, $event);
|
||||
|
||||
$this->redirect(URL::adminViewUrl('currencies'));
|
||||
$this->redirectToRoute('admin.configuration.currencies.default');
|
||||
}
|
||||
}
|
||||
@@ -214,10 +214,10 @@ class MessageController extends BaseAdminController
|
||||
// If we have to stay on the same page, do not redirect to the succesUrl,
|
||||
// just redirect to the edit page again.
|
||||
if ($this->getRequest()->get('save_mode') == 'stay') {
|
||||
$this->redirect(URL::absoluteUrl(
|
||||
"admin/configuration/messages/change",
|
||||
$this->redirectToRoute(
|
||||
"admin.configuration.messages.change",
|
||||
array('message_id' => $message_id)
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
|
||||
@@ -46,7 +46,7 @@ class SessionController extends BaseAdminController
|
||||
$this->getSecurityContext()->clearAdminUser();
|
||||
|
||||
// Go back to login page.
|
||||
return Redirect::exec(URL::absoluteUrl('/admin/login')); // FIXME - should be a parameter
|
||||
$this->redirectToRoute('admin.login');
|
||||
}
|
||||
|
||||
public function checkLoginAction()
|
||||
|
||||
@@ -31,14 +31,13 @@ use Thelia\Tools\Redirect;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Thelia\Core\Factory\ActionEventFactory;
|
||||
use Thelia\Form\BaseForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Thelia\Core\Event\DefaultActionEvent;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* The defaut administration controller. Basically, display the login form if
|
||||
@@ -203,6 +202,25 @@ class BaseController extends ContainerAware
|
||||
if (null !== $url) $this->redirect($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a route path from the route id.
|
||||
*
|
||||
* @param $routerName
|
||||
* @param $routeId
|
||||
*
|
||||
* @return mixed
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function getRouteFromRouter($routerName, $routeId) {
|
||||
$route = $this->container->get($routerName)->getRouteCollection()->get($routeId);
|
||||
|
||||
if ($route == null) {
|
||||
throw new InvalidArgumentException(sprintf("Route ID '%s' does not exists.", $routeId));
|
||||
}
|
||||
|
||||
return $route->getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 404 error
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||
@@ -211,4 +229,4 @@ class BaseController extends ContainerAware
|
||||
{
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,4 +26,24 @@ use Thelia\Controller\BaseController;
|
||||
|
||||
class BaseFrontController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Return the route path defined for the givent route ID
|
||||
*
|
||||
* @param string $routeId a route ID, as defines in Config/Resources/routing/front.xml
|
||||
*
|
||||
* @see \Thelia\Controller\BaseController::getRouteFromRouter()
|
||||
*/
|
||||
protected function getRoute($routeId) {
|
||||
return $this->getRouteFromRouter('router.front', $routeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to à route ID related URL
|
||||
*
|
||||
* @param unknown $routeId the route ID, as found in Config/Resources/routing/admin.xml
|
||||
* @param unknown $urlParameters the URL parametrs, as a var/value pair array
|
||||
*/
|
||||
public function redirectToRoute($routeId, $urlParameters = array()) {
|
||||
$this->redirect(URL::absoluteUrl($this->getRoute($routeId), $urlParameters));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user