Merge branch 'master' of https://github.com/thelia/thelia into coupon

# By Manuel Raynaud (22) and others
# Via Manuel Raynaud (7) and others
* 'master' of https://github.com/thelia/thelia: (32 commits)
  refactor name for updating actions
  choose UPDATE word for name actions
  add update address action and create tests
  404 not found management
  Working Fix unset namespace
  modify travis script
  test rewriting exception
  Fixed minor bug in Currencies
  Finished currency edition
  Added route methods
  address action implementation
  hot fix
  rewriting
  add address create controller and event
  Added AdminUtilities Smarty plugin, optimized templates
  update customer model createOrUpdate method
  update address model
  fix redirect process in viewListener
  refactor reset_install script
  refactor install process, database management in dedicated class
  ...

Conflicts:
	local/config/schema.xml
	reset_install.sh
This commit is contained in:
gmorel
2013-09-04 15:42:38 +02:00
103 changed files with 4436 additions and 1827 deletions

View File

@@ -150,12 +150,33 @@ 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
*/
protected function getCurrentEditionLangId() {
return $this->getRequest()->get(
'edition_language',
'edit_language_id',
$this->getSession()->getAdminEditionLangId()
);
}
@@ -196,29 +217,32 @@ class BaseAdminController extends BaseController
$session = $this->getSession();
// Find the current edit language ID
$edition_language = $this->getCurrentEditionLangId();
// Current back-office (not edition) language
$current_lang = LangQuery::create()->findOneById($session->getLangId());
$current_lang = LangQuery::create()->findOneById($session->getLangId());
// Find the current edit language ID
$edition_language = LangQuery::create()->findOneById($this->getCurrentEditionLangId());
// Prepare common template variables
$args = array_merge($args, array(
'locale' => $session->getLocale(),
'lang_code' => $session->getLang(),
'lang_id' => $session->getLangId(),
'locale' => $session->getLocale(),
'lang_code' => $session->getLang(),
'lang_id' => $session->getLangId(),
'datetime_format' => $current_lang->getDateTimeFormat(),
'date_format' => $current_lang->getDateFormat(),
'time_format' => $current_lang->getTimeFormat(),
'datetime_format' => $current_lang->getDateTimeFormat(),
'date_format' => $current_lang->getDateFormat(),
'time_format' => $current_lang->getTimeFormat(),
'edition_language' => $edition_language,
'edit_language_id' => $edition_language->getId(),
'edit_language_locale' => $edition_language->getLocale(),
'current_url' => htmlspecialchars($this->getRequest()->getUri())
'current_url' => htmlspecialchars($this->getRequest()->getUri())
));
// Update the current edition language in session
$this->getSession()->setAdminEditionLangId($edition_language);
$this->getSession()->setAdminEditionLangId($edition_language->getId());
// Render the template.
try {

View File

@@ -188,7 +188,7 @@ class CategoryController extends BaseAdminController
// Find the current order
$category_order = $this->getRequest()->get(
'category_order',
'order',
$this->getSession()->get('admin.category_order', 'manual')
);

View File

@@ -42,6 +42,25 @@ use Thelia\Form\ConfigCreationForm;
*/
class ConfigController extends BaseAdminController
{
/**
* Render the currencies list, ensuring the sort order is set.
*
* @return Symfony\Component\HttpFoundation\Response the response
*/
protected function renderList() {
// Find the current order
$order = $this->getRequest()->get(
'order',
$this->getSession()->get('admin.variables_order', 'name')
);
// Store the current sort order in session
$this->getSession()->set('admin.variables_order', $order);
return $this->render('variables', array('order' => $order));
}
/**
* The default action is displaying the variables list.
*
@@ -51,7 +70,7 @@ class ConfigController extends BaseAdminController
if (null !== $response = $this->checkAuth("admin.configuration.variables.view")) return $response;
return $this->render('variables');
return $this->renderList();
}
/**
@@ -124,7 +143,7 @@ class ConfigController extends BaseAdminController
}
// At this point, the form has error, and should be redisplayed.
return $this->render('variables');
return $this->renderList();
}
/**
@@ -210,7 +229,7 @@ class ConfigController extends BaseAdminController
->setPostscriptum($data['postscriptum'])
;
$this->dispatch(TheliaEvents::CONFIG_MODIFY, $changeEvent);
$this->dispatch(TheliaEvents::CONFIG_UPDATE, $changeEvent);
// Log config modification
$changedObject = $changeEvent->getConfig();
@@ -220,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
@@ -276,7 +296,7 @@ class ConfigController extends BaseAdminController
$this->dispatch(TheliaEvents::CONFIG_SETVALUE, $event);
}
$this->redirect(URL::adminViewUrl('variables'));
$this->redirectToRoute('admin.configuration.variables.default');
}
/**
@@ -294,6 +314,6 @@ class ConfigController extends BaseAdminController
$this->dispatch(TheliaEvents::CONFIG_DELETE, $event);
$this->redirect(URL::adminViewUrl('variables'));
$this->redirectToRoute('admin.configuration.variables.default');
}
}

View File

@@ -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());
@@ -101,7 +101,9 @@ class CurrencyController extends BaseAdminController
->setCurrencyName($data['name'])
->setLocale($data["locale"])
->setSymbol($data['symbol'])
;
->setCode($data['code'])
->setRate($data['rate'])
;
$this->dispatch(TheliaEvents::CURRENCY_CREATE, $createEvent);
@@ -118,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)
;
}
@@ -167,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
@@ -191,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());
@@ -218,7 +220,7 @@ class CurrencyController extends BaseAdminController
->setRate($data['rate'])
;
$this->dispatch(TheliaEvents::CURRENCY_MODIFY, $changeEvent);
$this->dispatch(TheliaEvents::CURRENCY_UPDATE, $changeEvent);
// Log currency modification
$changedObject = $changeEvent->getCurrency();
@@ -228,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
@@ -239,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)
;
}
@@ -264,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
*
@@ -279,6 +322,6 @@ class CurrencyController extends BaseAdminController
$this->dispatch(TheliaEvents::CURRENCY_DELETE, $event);
$this->redirect(URL::adminViewUrl('currencies'));
$this->redirectToRoute('admin.configuration.currencies.default');
}
}

View File

@@ -204,7 +204,7 @@ class MessageController extends BaseAdminController
->setTextMessage($data['text_message'])
;
$this->dispatch(TheliaEvents::MESSAGE_MODIFY, $changeEvent);
$this->dispatch(TheliaEvents::MESSAGE_UPDATE, $changeEvent);
// Log message modification
$changedObject = $changeEvent->getMessage();
@@ -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

View File

@@ -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()