Merge branch 'master' of https://github.com/thelia/thelia
Conflicts: core/lib/Thelia/Controller/BaseController.php
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,28 @@ 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());
|
||||
|
||||
var_dump($ex);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
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 +173,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 +197,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 +234,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 +245,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 +270,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 +326,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()
|
||||
|
||||
Reference in New Issue
Block a user