MAJ en Thelia 2.3.4
This commit is contained in:
@@ -366,8 +366,6 @@ class BaseAdminController extends BaseController
|
||||
// Add the template standard extension
|
||||
$templateName .= '.html';
|
||||
|
||||
$session = $this->getSession();
|
||||
|
||||
// Find the current edit language ID
|
||||
$edition_language = $this->getCurrentEditionLang();
|
||||
|
||||
@@ -376,16 +374,9 @@ class BaseAdminController extends BaseController
|
||||
|
||||
// Prepare common template variables
|
||||
$args = array_merge($args, array(
|
||||
'locale' => $session->getLang()->getLocale(),
|
||||
'lang_code' => $session->getLang()->getCode(),
|
||||
'lang_id' => $session->getLang()->getId(),
|
||||
|
||||
'edit_language_id' => $edition_language->getId(),
|
||||
'edit_language_locale' => $edition_language->getLocale(),
|
||||
|
||||
'edit_currency_id' => $edition_currency->getId(),
|
||||
|
||||
'current_url' => $this->getRequest()->getUri()
|
||||
));
|
||||
|
||||
// Update the current edition language & currency in session
|
||||
|
||||
@@ -43,6 +43,29 @@ class ConfigStoreController extends BaseAdminController
|
||||
return $this->renderTemplate();
|
||||
}
|
||||
|
||||
protected function getAndWriteStoreMediaFileInConfig($form, $inputName, $configKey, $storeMediaUploadDir)
|
||||
{
|
||||
$file = $form->get($inputName)->getData();
|
||||
|
||||
if ($file != null) {
|
||||
// Delete the old file
|
||||
$fs = new \Symfony\Component\Filesystem\Filesystem();
|
||||
$oldFileName = ConfigQuery::read($configKey);
|
||||
|
||||
if ($oldFileName !== null) {
|
||||
$oldFilePath = $storeMediaUploadDir . DS . $oldFileName;
|
||||
if ($fs->exists($oldFilePath)) {
|
||||
$fs->remove($oldFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
// Write the new file
|
||||
$newFileName = uniqid() . '-' . $file->getClientOriginalName();
|
||||
$file->move($storeMediaUploadDir, $newFileName);
|
||||
ConfigQuery::write($configKey, $newFileName, false);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::STORE, array(), AccessManager::UPDATE)) {
|
||||
@@ -56,11 +79,33 @@ class ConfigStoreController extends BaseAdminController
|
||||
try {
|
||||
$form = $this->validateForm($configStoreForm);
|
||||
|
||||
$storeMediaUploadDir = ConfigQuery::read('images_library_path');
|
||||
|
||||
if ($storeMediaUploadDir === null) {
|
||||
$storeMediaUploadDir = THELIA_LOCAL_DIR . 'media' . DS . 'images';
|
||||
} else {
|
||||
$storeMediaUploadDir = THELIA_ROOT . $storeMediaUploadDir;
|
||||
}
|
||||
|
||||
$storeMediaUploadDir .= DS . 'store';
|
||||
|
||||
// List of medias that can be uploaded through this form.
|
||||
// [Name of the form input] => [Key in the config table]
|
||||
$storeMediaList = [
|
||||
'favicon_file' => 'favicon_file',
|
||||
'logo_file' => 'logo_file',
|
||||
'banner_file' => 'banner_file'
|
||||
];
|
||||
|
||||
foreach ($storeMediaList as $input_name => $config_key) {
|
||||
$this->getAndWriteStoreMediaFileInConfig($form, $input_name, $config_key, $storeMediaUploadDir);
|
||||
}
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
// Update store
|
||||
foreach ($data as $name => $value) {
|
||||
if (! $configStoreForm->isTemplateDefinedHiddenFieldName($name)) {
|
||||
if (!array_key_exists($name, $storeMediaList) && !$configStoreForm->isTemplateDefinedHiddenFieldName($name)) {
|
||||
ConfigQuery::write($name, $value, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,6 @@ class CountryController extends AbstractCrudController
|
||||
;
|
||||
|
||||
return $event;
|
||||
|
||||
}
|
||||
|
||||
protected function hydrateEvent($event, $formData)
|
||||
|
||||
@@ -647,7 +647,7 @@ class CouponController extends BaseAdminController
|
||||
$this->pageNotFound();
|
||||
}
|
||||
|
||||
$response = new ResponseRest($couponManager->drawBackOfficeInputs());
|
||||
$response = new ResponseRest($couponManager->drawBackOfficeInputs(), 'text');
|
||||
} else {
|
||||
// Return an empty response if the service ID is not defined
|
||||
// Typically, when the user chooses "Please select a coupon type"
|
||||
@@ -815,7 +815,7 @@ class CouponController extends BaseAdminController
|
||||
|
||||
protected function getDefaultDateFormat()
|
||||
{
|
||||
return LangQuery::create()->findOneByByDefault(true)->getDateFormat();
|
||||
return LangQuery::create()->findOneByByDefault(true)->getDatetimeFormat();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -205,7 +205,6 @@ class CurrencyController extends AbstractCrudController
|
||||
'undefined_rates' => $event->getUndefinedRates()
|
||||
]);
|
||||
}
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
|
||||
@@ -435,7 +435,6 @@ class LangController extends BaseAdminController
|
||||
),
|
||||
$changedObject->getId()
|
||||
);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Tlog::getInstance()->error(sprintf("Error on changing languages with message : %s", $e->getMessage()));
|
||||
$errorMessage = $e->getMessage();
|
||||
|
||||
@@ -22,7 +22,7 @@ use Thelia\Model\ConfigQuery;
|
||||
|
||||
class MailingSystemController extends BaseAdminController
|
||||
{
|
||||
const RESOURCE_CODE = "admin.mailing-system";
|
||||
const RESOURCE_CODE = "admin.configuration.mailing-system";
|
||||
|
||||
public function defaultAction()
|
||||
{
|
||||
@@ -130,7 +130,7 @@ class MailingSystemController extends BaseAdminController
|
||||
|
||||
$htmlMessage = "<p>$message</p>";
|
||||
|
||||
$instance = \Swift_Message::newInstance()
|
||||
$instance = $this->getMailer()->getMessageInstance()
|
||||
->addTo($emailTest, $storeName)
|
||||
->addFrom($contactEmail, $storeName)
|
||||
->setSubject($message)
|
||||
|
||||
@@ -22,6 +22,7 @@ use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
use Thelia\Form\Definition\AdminForm;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Model\Message;
|
||||
use Thelia\Model\MessageQuery;
|
||||
use Thelia\Model\Module;
|
||||
@@ -48,35 +49,35 @@ class MessageController extends AbstractCrudController
|
||||
null // No position update
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
protected function getCreationForm()
|
||||
{
|
||||
return $this->createForm(AdminForm::MESSAGE_CREATION);
|
||||
}
|
||||
|
||||
|
||||
protected function getUpdateForm()
|
||||
{
|
||||
return $this->createForm(AdminForm::MESSAGE_MODIFICATION);
|
||||
}
|
||||
|
||||
|
||||
protected function getCreationEvent($formData)
|
||||
{
|
||||
$createEvent = new MessageCreateEvent();
|
||||
|
||||
|
||||
$createEvent
|
||||
->setMessageName($formData['name'])
|
||||
->setLocale($formData["locale"])
|
||||
->setTitle($formData['title'])
|
||||
->setSecured($formData['secured'] ? true : false)
|
||||
;
|
||||
|
||||
;
|
||||
|
||||
return $createEvent;
|
||||
}
|
||||
|
||||
|
||||
protected function getUpdateEvent($formData)
|
||||
{
|
||||
$changeEvent = new MessageUpdateEvent($formData['id']);
|
||||
|
||||
|
||||
// Create and dispatch the change event
|
||||
$changeEvent
|
||||
->setMessageName($formData['name'])
|
||||
@@ -91,20 +92,20 @@ class MessageController extends AbstractCrudController
|
||||
->setHtmlMessage($formData['html_message'])
|
||||
->setTextMessage($formData['text_message'])
|
||||
;
|
||||
|
||||
|
||||
return $changeEvent;
|
||||
}
|
||||
|
||||
|
||||
protected function getDeleteEvent()
|
||||
{
|
||||
return new MessageDeleteEvent($this->getRequest()->get('message_id'));
|
||||
}
|
||||
|
||||
|
||||
protected function eventContainsObject($event)
|
||||
{
|
||||
return $event->hasMessage();
|
||||
}
|
||||
|
||||
|
||||
protected function hydrateObjectForm($object)
|
||||
{
|
||||
// Prepare the data that will hydrate the form
|
||||
@@ -117,34 +118,34 @@ class MessageController extends AbstractCrudController
|
||||
'subject' => $object->getSubject(),
|
||||
'html_message' => $object->getHtmlMessage(),
|
||||
'text_message' => $object->getTextMessage(),
|
||||
|
||||
|
||||
'html_layout_file_name' => $object->getHtmlLayoutFileName(),
|
||||
'html_template_file_name' => $object->getHtmlTemplateFileName(),
|
||||
'text_layout_file_name' => $object->getTextLayoutFileName(),
|
||||
'text_template_file_name' => $object->getTextTemplateFileName(),
|
||||
);
|
||||
|
||||
|
||||
// Setup the object form
|
||||
return $this->createForm(AdminForm::MESSAGE_MODIFICATION, "form", $data);
|
||||
}
|
||||
|
||||
|
||||
protected function getObjectFromEvent($event)
|
||||
{
|
||||
return $event->hasMessage() ? $event->getMessage() : null;
|
||||
}
|
||||
|
||||
|
||||
protected function getExistingObject()
|
||||
{
|
||||
$message = MessageQuery::create()
|
||||
->findOneById($this->getRequest()->get('message_id', 0));
|
||||
|
||||
->findOneById($this->getRequest()->get('message_id', 0));
|
||||
|
||||
if (null !== $message) {
|
||||
$message->setLocale($this->getCurrentEditionLocale());
|
||||
}
|
||||
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Message $object
|
||||
* @return string
|
||||
@@ -153,7 +154,7 @@ class MessageController extends AbstractCrudController
|
||||
{
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Message $object
|
||||
* @return int
|
||||
@@ -162,30 +163,30 @@ class MessageController extends AbstractCrudController
|
||||
{
|
||||
return $object->getId();
|
||||
}
|
||||
|
||||
|
||||
protected function renderListTemplate($currentOrder)
|
||||
{
|
||||
return $this->render('messages');
|
||||
}
|
||||
|
||||
|
||||
protected function listDirectoryContent($requiredExtension)
|
||||
{
|
||||
$list = array();
|
||||
|
||||
|
||||
$dir = $this->getTemplateHelper()->getActiveMailTemplate()->getAbsolutePath();
|
||||
|
||||
|
||||
$finder = Finder::create()->files()->in($dir)->ignoreDotFiles(true)->sortByName()->name("*.$requiredExtension");
|
||||
|
||||
|
||||
foreach ($finder as $file) {
|
||||
$list[] = $file->getBasename();
|
||||
}
|
||||
|
||||
|
||||
// Add modules templates
|
||||
$modules = ModuleQuery::getActivated();
|
||||
/** @var Module $module */
|
||||
foreach ($modules as $module) {
|
||||
$dir = $module->getAbsoluteTemplateBasePath() . DS . TemplateDefinition::EMAIL_SUBDIR . DS . 'default';
|
||||
|
||||
|
||||
if (file_exists($dir)) {
|
||||
$finder = Finder::create()
|
||||
->files()
|
||||
@@ -193,7 +194,7 @@ class MessageController extends AbstractCrudController
|
||||
->ignoreDotFiles(true)
|
||||
->sortByName()
|
||||
->name("*.$requiredExtension");
|
||||
|
||||
|
||||
foreach ($finder as $file) {
|
||||
$fileName = $file->getBasename();
|
||||
if (!in_array($fileName, $list)) {
|
||||
@@ -202,20 +203,20 @@ class MessageController extends AbstractCrudController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
protected function renderEditionTemplate()
|
||||
{
|
||||
return $this->render('message-edit', array(
|
||||
'message_id' => $this->getRequest()->get('message_id'),
|
||||
'layout_list' => $this->listDirectoryContent('tpl'),
|
||||
'html_template_list' => $this->listDirectoryContent('html'),
|
||||
'text_template_list' => $this->listDirectoryContent('txt'),
|
||||
'message_id' => $this->getRequest()->get('message_id'),
|
||||
'layout_list' => $this->listDirectoryContent('tpl'),
|
||||
'html_template_list' => $this->listDirectoryContent('html'),
|
||||
'text_template_list' => $this->listDirectoryContent('txt'),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
protected function redirectToEditionTemplate()
|
||||
{
|
||||
return $this->generateRedirectFromRoute(
|
||||
@@ -225,47 +226,95 @@ class MessageController extends AbstractCrudController
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
protected function redirectToListTemplate()
|
||||
{
|
||||
return $this->generateRedirectFromRoute('admin.configuration.messages.default');
|
||||
}
|
||||
|
||||
|
||||
public function previewAction($messageId, $html = true)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::MESSAGE, [], AccessManager::VIEW)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
if (null === $message = MessageQuery::create()->findPk($messageId)) {
|
||||
$this->pageNotFound();
|
||||
}
|
||||
|
||||
|
||||
$parser = $this->getParser($this->getTemplateHelper()->getActiveMailTemplate());
|
||||
|
||||
|
||||
foreach ($this->getRequest()->query->all() as $key => $value) {
|
||||
$parser->assign($key, $value);
|
||||
}
|
||||
|
||||
|
||||
if ($html) {
|
||||
$content = $message->setLocale($this->getCurrentEditionLocale())->getHtmlMessageBody($parser);
|
||||
} else {
|
||||
$content = $message->setLocale($this->getCurrentEditionLocale())->getTextMessageBody($parser);
|
||||
}
|
||||
|
||||
|
||||
return new Response($content);
|
||||
}
|
||||
|
||||
|
||||
public function previewAsHtmlAction($messageId)
|
||||
{
|
||||
return $this->previewAction($messageId);
|
||||
}
|
||||
|
||||
|
||||
public function previewAsTextAction($messageId)
|
||||
{
|
||||
$response = $this->previewAction($messageId, false);
|
||||
$response->headers->add(["Content-Type" => "text/plain"]);
|
||||
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function sendSampleByEmailAction($messageId)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::MESSAGE, [], AccessManager::VIEW)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if (null !== $message = MessageQuery::create()->findPk($messageId)) {
|
||||
// Ajax submission: prevent CRSF control, as page is not refreshed
|
||||
$baseForm = $this->createForm(AdminForm::MESSAGE_SEND_SAMPLE, 'form', [], ['csrf_protection' => false]);
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($baseForm, "POST");
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
$messageParameters = [];
|
||||
|
||||
foreach ($this->getRequest()->request->all() as $key => $value) {
|
||||
$messageParameters[$key] = $value;
|
||||
}
|
||||
|
||||
$this->getMailer()->sendEmailMessage(
|
||||
$message->getName(),
|
||||
[ConfigQuery::getStoreEmail() => ConfigQuery::getStoreName()],
|
||||
[ $data['recipient_email'] => $data['recipient_email'] ],
|
||||
$messageParameters,
|
||||
$this->getCurrentEditionLocale()
|
||||
);
|
||||
|
||||
return new Response(
|
||||
$this->getTranslator()->trans(
|
||||
"The message has been successfully sent to %recipient.",
|
||||
[ '%recipient' => $data['recipient_email'] ]
|
||||
)
|
||||
);
|
||||
} catch (\Exception $ex) {
|
||||
return new Response(
|
||||
$this->getTranslator()->trans(
|
||||
"Something goes wrong, the message was not sent to recipient. Error is : %err",
|
||||
[ '%err' => $ex->getMessage() ]
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class OrderController extends BaseAdminController
|
||||
|
||||
$order = OrderQuery::create()->findPk($order_id);
|
||||
|
||||
$statusId = $this->getRequest()->request->get("status_id");
|
||||
$statusId = $this->getRequest()->get("status_id");
|
||||
$status = OrderStatusQuery::create()->findPk($statusId);
|
||||
|
||||
if (null === $order) {
|
||||
|
||||
@@ -329,7 +329,6 @@ class ProductController extends AbstractSeoCrudController
|
||||
$this->appendValue($combinationPseData, "isdefault", $saleElement->getIsDefault() > 0 ? 1 : 0);
|
||||
$this->appendValue($combinationPseData, "ean_code", $saleElement->getEanCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$defaultPseForm = $this->createForm(AdminForm::PRODUCT_DEFAULT_SALE_ELEMENT_UPDATE, "form", $defaultPseData);
|
||||
|
||||
@@ -81,7 +81,7 @@ class SaleController extends AbstractCrudController
|
||||
/** @var SaleProduct $saleProduct */
|
||||
foreach ($saleProducts as $saleProduct) {
|
||||
$categories[] = $saleProduct->getProduct()->getDefaultCategoryId();
|
||||
$products[] = $saleProduct->getProduct()->getId();
|
||||
$products[$saleProduct->getProduct()->getId()] = $saleProduct->getProduct()->getId();
|
||||
}
|
||||
|
||||
$dateFormat = SaleModificationForm::PHP_DATE_FORMAT;
|
||||
|
||||
@@ -185,7 +185,6 @@ class SessionController extends BaseAdminController
|
||||
$this->getSession()->set(self::ADMIN_TOKEN_SESSION_VAR_NAME, null);
|
||||
|
||||
return $this->generateSuccessRedirect($adminCreatePasswordForm);
|
||||
|
||||
} catch (FormValidationException $ex) {
|
||||
// Validation problem
|
||||
$message = $this->createStandardFormValidationErrorMessage($ex);
|
||||
|
||||
@@ -241,5 +241,4 @@ class StateController extends AbstractCrudController
|
||||
{
|
||||
return new StateToggleVisibilityEvent($this->getExistingObject());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -332,7 +332,6 @@ class TaxRuleController extends AbstractCrudController
|
||||
);
|
||||
|
||||
return $this->jsonResponse(json_encode($responseData));
|
||||
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
@@ -411,7 +410,6 @@ class TaxRuleController extends AbstractCrudController
|
||||
|
||||
$taxRuleCountry = $taxRuleCountries->getNext();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data = [
|
||||
|
||||
@@ -18,8 +18,10 @@ use Thelia\Core\Event\Template\TemplateCreateEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteAttributeEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteFeatureEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDuplicateEvent;
|
||||
use Thelia\Core\Event\Template\TemplateUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Form\Definition\AdminForm;
|
||||
@@ -157,13 +159,18 @@ class TemplateController extends AbstractCrudController
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function redirectToEditionTemplate()
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function redirectToEditionTemplate($request = null, $id = null)
|
||||
{
|
||||
return $this->generateRedirectFromRoute(
|
||||
"admin.configuration.templates.update",
|
||||
[
|
||||
'template_id' => $this->getRequest()->get('template_id'),
|
||||
'template_id' => $id ?: $this->getRequest()->get('template_id'),
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -195,6 +202,33 @@ class TemplateController extends AbstractCrudController
|
||||
return null;
|
||||
}
|
||||
|
||||
public function duplicateAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth(AdminResources::TEMPLATE, array(), AccessManager::CREATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$template_id = intval($this->getRequest()->get('template_id'));
|
||||
|
||||
if ($template_id > 0) {
|
||||
try {
|
||||
$event = new TemplateDuplicateEvent($template_id, $this->getCurrentEditionLocale());
|
||||
|
||||
$this->dispatch(TheliaEvents::TEMPLATE_DUPLICATE, $event);
|
||||
|
||||
if ($event->hasTemplate()) {
|
||||
$template_id = $event->getTemplate()->getId();
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
// Any error
|
||||
return $this->errorPage($ex);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectToEditionTemplate(null, $template_id);
|
||||
}
|
||||
|
||||
public function getAjaxFeaturesAction()
|
||||
{
|
||||
return $this->render(
|
||||
|
||||
@@ -126,18 +126,7 @@ class BaseFrontController extends BaseController
|
||||
// Add the template standard extension
|
||||
$templateName .= '.html';
|
||||
|
||||
$session = $this->getSession();
|
||||
|
||||
// Prepare common template variables
|
||||
$args = array_merge($args, array(
|
||||
'locale' => $session->getLang()->getLocale(),
|
||||
'lang_code' => $session->getLang()->getCode(),
|
||||
'lang_id' => $session->getLang()->getId(),
|
||||
'current_url' => $this->getRequest()->getUri()
|
||||
));
|
||||
|
||||
// Render the template.
|
||||
|
||||
$data = $this->getParser($templateDir)->render($templateName, $args);
|
||||
|
||||
return $data;
|
||||
|
||||
Reference in New Issue
Block a user