Merge branch 'master' into frontend
This commit is contained in:
@@ -253,7 +253,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Render the object list, ensuring the sort order is set.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
* @return Thelia\Core\HttpFoundation\Response the response
|
||||
*/
|
||||
protected function renderList()
|
||||
{
|
||||
@@ -263,7 +263,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* The default action is displaying the list.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
* @return Thelia\Core\HttpFoundation\Response the response
|
||||
*/
|
||||
public function defaultAction()
|
||||
{
|
||||
@@ -274,7 +274,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Create a new object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
* @return Thelia\Core\HttpFoundation\Response the response
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
@@ -303,7 +303,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
if (null !== $createdObject = $this->getObjectFromEvent($createEvent)) {
|
||||
// Log object creation
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject)));
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::CREATE, sprintf("%s %s (ID %s) created", ucfirst($this->objectName), $this->getObjectLabel($createdObject), $this->getObjectId($createdObject)));
|
||||
}
|
||||
|
||||
$response = $this->performAdditionalCreateAction($createEvent);
|
||||
@@ -335,7 +335,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Load a object for modification, and display the edit template.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
* @return Thelia\Core\HttpFoundation\Response the response
|
||||
*/
|
||||
public function updateAction()
|
||||
{
|
||||
@@ -361,7 +361,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Save changes on a modified object, and either go back to the object list, or stay on the edition page.
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
* @return Thelia\Core\HttpFoundation\Response the response
|
||||
*/
|
||||
public function processUpdateAction()
|
||||
{
|
||||
@@ -391,7 +391,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) {
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
$response = $this->performAdditionalUpdateAction($changeEvent);
|
||||
@@ -516,7 +516,7 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
/**
|
||||
* Delete an object
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
* @return Thelia\Core\HttpFoundation\Response the response
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
@@ -530,7 +530,8 @@ abstract class AbstractCrudController extends BaseAdminController
|
||||
|
||||
if (null !== $deletedObject = $this->getObjectFromEvent($deleteEvent)) {
|
||||
$this->adminLogAppend(
|
||||
sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject)));
|
||||
$this->resourceCode, AccessManager::DELETE,
|
||||
sprintf("%s %s (ID %s) deleted", ucfirst($this->objectName), $this->getObjectLabel($deletedObject), $this->getObjectId($deletedObject)));
|
||||
}
|
||||
|
||||
$response = $this->performAdditionalDeleteAction($deleteEvent);
|
||||
|
||||
@@ -74,9 +74,9 @@ class AddressController extends AbstractCrudController
|
||||
|
||||
$this->dispatch(TheliaEvents::ADDRESS_DEFAULT, $addressEvent);
|
||||
|
||||
$this->adminLogAppend(sprintf("address %d for customer %d removal", $address_id, $address->getCustomerId()));
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("address %d for customer %d set as default address", $address_id, $address->getCustomerId()));
|
||||
} catch (\Exception $e) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during address removal with message %s", $e->getMessage()));
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("error during address setting as default with message %s", $e->getMessage()));
|
||||
}
|
||||
|
||||
$this->redirectToRoute('admin.customer.update.view', array(), array('customer_id' => $address->getCustomerId()));
|
||||
|
||||
72
core/lib/Thelia/Controller/Admin/AdminLogsController.php
Normal file
72
core/lib/Thelia/Controller/Admin/AdminLogsController.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Model\AdminLogQuery;
|
||||
|
||||
class AdminLogsController extends BaseAdminController
|
||||
{
|
||||
const RESOURCE_CODE = "admin.admin-logs";
|
||||
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(self::RESOURCE_CODE, AccessManager::VIEW)) return $response;
|
||||
|
||||
// Render the edition template.
|
||||
return $this->render('admin-logs');
|
||||
}
|
||||
|
||||
public function loadLoggerAjaxAction()
|
||||
{
|
||||
$entries = array();
|
||||
|
||||
foreach( AdminLogQuery::getEntries(
|
||||
$this->getRequest()->request->get('admins', array()),
|
||||
$this->getRequest()->request->get('fromDate', null),
|
||||
$this->getRequest()->request->get('toDate', null),
|
||||
array_merge($this->getRequest()->request->get('resources', array()), $this->getRequest()->request->get('modules', array())),
|
||||
null
|
||||
) as $entry) {
|
||||
|
||||
$entries[] = array(
|
||||
"head" => sprintf(
|
||||
"[%s][%s][%s:%s]",
|
||||
date('Y-m-d H:i:s', $entry->getCreatedAt()->getTimestamp()),
|
||||
$entry->getAdminLogin(),
|
||||
$entry->getResource(),
|
||||
$entry->getAction()
|
||||
),
|
||||
"data" => $entry->getMessage(),
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'ajax/logger',
|
||||
array(
|
||||
'entries' => $entries,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -249,7 +249,7 @@ class AreaController extends AbstractCrudController
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($event)) {
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified, new country added", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified, new country added", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
@@ -303,7 +303,7 @@ class AreaController extends AbstractCrudController
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($event)) {
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified, country remove", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified, country remove", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
// Redirect to the success URL
|
||||
|
||||
@@ -157,23 +157,6 @@ class AttributeController extends AbstractCrudController
|
||||
'postscriptum' => $object->getPostscriptum()
|
||||
);
|
||||
|
||||
// Setup attributes values
|
||||
/*
|
||||
* FIXME : doesn't work. "We get a This form should not contain extra fields." error
|
||||
$attr_av_list = AttributeAvQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->filterByAttributeId($object->getId())
|
||||
->find();
|
||||
|
||||
$attr_array = array();
|
||||
|
||||
foreach ($attr_av_list as $attr_av) {
|
||||
$attr_array[$attr_av->getId()] = $attr_av->getTitle();
|
||||
}
|
||||
|
||||
$data['attribute_values'] = $attr_array;
|
||||
*/
|
||||
|
||||
// Setup the object form
|
||||
return new AttributeModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ use Symfony\Component\Routing\Exception\InvalidParameterException;
|
||||
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
|
||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||
use Thelia\Controller\BaseController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
@@ -51,18 +51,20 @@ class BaseAdminController extends BaseController
|
||||
/**
|
||||
* Helper to append a message to the admin log.
|
||||
*
|
||||
* @param string $resource
|
||||
* @param string $action
|
||||
* @param string $message
|
||||
*/
|
||||
public function adminLogAppend($message)
|
||||
public function adminLogAppend($resource, $action, $message)
|
||||
{
|
||||
AdminLog::append($message, $this->getRequest(), $this->getSecurityContext()->getAdminUser());
|
||||
AdminLog::append($resource, $action, $message, $this->getRequest(), $this->getSecurityContext()->getAdminUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method process the rendering of view called from an admin page
|
||||
*
|
||||
* @param unknown $template
|
||||
* @return Response the reponse which contains the rendered view
|
||||
* @return Response the response which contains the rendered view
|
||||
*/
|
||||
public function processTemplateAction($template)
|
||||
{
|
||||
@@ -83,7 +85,7 @@ class BaseAdminController extends BaseController
|
||||
/**
|
||||
* Return a 404 error
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
protected function pageNotFound()
|
||||
{
|
||||
@@ -95,7 +97,7 @@ class BaseAdminController extends BaseController
|
||||
*
|
||||
* @param mixed $message a message string, or an exception instance
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
protected function errorPage($message, $status = 500)
|
||||
{
|
||||
@@ -131,7 +133,7 @@ class BaseAdminController extends BaseController
|
||||
}
|
||||
|
||||
// Log the problem
|
||||
$this->adminLogAppend("User is not granted for resources %s with accesses %s", implode(", ", $resources), implode(", ", $accesses));
|
||||
$this->adminLogAppend(implode(",", $resources), implode(",", $accesses), "User is not granted for resources %s with accesses %s", implode(", ", $resources), implode(", ", $accesses));
|
||||
|
||||
// Generate the proper response
|
||||
$response = new Response();
|
||||
@@ -197,7 +199,7 @@ class BaseAdminController extends BaseController
|
||||
$parser = $this->container->get("thelia.parser");
|
||||
|
||||
// Define the template thant shoud be used
|
||||
$parser->setTemplate($template ?: ConfigQuery::read('base_admin_template', 'admin/default'));
|
||||
$parser->setTemplate($template ?: ConfigQuery::read('base-admin-template', 'admin/default'));
|
||||
|
||||
return $parser;
|
||||
}
|
||||
@@ -371,7 +373,7 @@ class BaseAdminController extends BaseController
|
||||
* @param $templateName the complete template name, with extension
|
||||
* @param array $args the template arguments
|
||||
* @param int $status http code status
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
protected function render($templateName, $args = array(), $status = 200)
|
||||
{
|
||||
@@ -385,7 +387,7 @@ class BaseAdminController extends BaseController
|
||||
* @param array $args the template arguments
|
||||
* @param null $templateDir
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
protected function renderRaw($templateName, $args = array(), $templateDir = null)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Event\Category\CategoryDeleteEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
@@ -320,7 +320,7 @@ class CategoryController extends AbstractCrudController
|
||||
/**
|
||||
* Add category pictures
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function addRelatedPictureAction()
|
||||
{
|
||||
|
||||
@@ -181,7 +181,7 @@ class ConfigController extends AbstractCrudController
|
||||
/**
|
||||
* Change values modified directly from the variable list
|
||||
*
|
||||
* @return Symfony\Component\HttpFoundation\Response the response
|
||||
* @return Thelia\Core\HttpFoundation\Response the response
|
||||
*/
|
||||
public function changeValuesAction()
|
||||
{
|
||||
|
||||
@@ -64,7 +64,7 @@ class ContentController extends AbstractCrudController
|
||||
/**
|
||||
* controller adding content to additional folder
|
||||
*
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
* @return mixed|\Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function addAdditionalFolderAction()
|
||||
{
|
||||
@@ -92,7 +92,7 @@ class ContentController extends AbstractCrudController
|
||||
/**
|
||||
* controller removing additional folder to a content
|
||||
*
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
* @return mixed|\Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function removeAdditionalFolderAction()
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ class CouponController extends BaseAdminController
|
||||
/**
|
||||
* Manage Coupons list display
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function browseAction()
|
||||
{
|
||||
@@ -90,7 +90,7 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @param int $couponId Coupon Id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function readAction($couponId)
|
||||
{
|
||||
@@ -117,7 +117,7 @@ class CouponController extends BaseAdminController
|
||||
/**
|
||||
* Manage Coupons creation display
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
@@ -165,7 +165,7 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @param int $couponId Coupon id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function updateAction($couponId)
|
||||
{
|
||||
@@ -270,7 +270,7 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @param string $conditionId Condition service id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function getConditionInputAction($conditionId)
|
||||
{
|
||||
@@ -300,7 +300,7 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @param int $couponId Coupon id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function updateConditionsAction($couponId)
|
||||
{
|
||||
@@ -356,6 +356,7 @@ class CouponController extends BaseAdminController
|
||||
);
|
||||
|
||||
$this->adminLogAppend(
|
||||
AdminResources::COUPON, AccessManager::UPDATE,
|
||||
sprintf(
|
||||
'Coupon %s (ID %s) conditions updated',
|
||||
$couponEvent->getCouponModel()->getTitle(),
|
||||
@@ -468,6 +469,7 @@ class CouponController extends BaseAdminController
|
||||
);
|
||||
|
||||
$this->adminLogAppend(
|
||||
AdminResources::COUPON, AccessManager::UPDATE,
|
||||
sprintf(
|
||||
'Coupon %s (ID ) ' . $log,
|
||||
$couponEvent->getTitle(),
|
||||
|
||||
@@ -29,10 +29,12 @@ use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Customer\CustomerEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Form\CustomerCreateForm;
|
||||
use Thelia\Form\CustomerUpdateForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Tools\Password;
|
||||
|
||||
/**
|
||||
* Class CustomerController
|
||||
@@ -59,7 +61,7 @@ class CustomerController extends BaseAdminController
|
||||
* update customer action
|
||||
*
|
||||
* @param $customer_id
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
* @return mixed|\Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function updateAction($customer_id)
|
||||
{
|
||||
@@ -85,7 +87,7 @@ class CustomerController extends BaseAdminController
|
||||
|
||||
$customerUpdated = $event->getCustomer();
|
||||
|
||||
$this->adminLogAppend(sprintf("Customer with Ref %s (ID %d) modified", $customerUpdated->getRef() , $customerUpdated->getId()));
|
||||
$this->adminLogAppend(AdminResources::CUSTOMER, AccessManager::UPDATE, sprintf("Customer with Ref %s (ID %d) modified", $customerUpdated->getRef() , $customerUpdated->getId()));
|
||||
|
||||
if ($this->getRequest()->get("save_mode") == "close") {
|
||||
$this->redirectToRoute("admin.customers");
|
||||
@@ -102,7 +104,7 @@ class CustomerController extends BaseAdminController
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer login process : %s.", $message));
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer update process : %s.", $message));
|
||||
|
||||
$customerUpdateForm->setErrorMessage($message);
|
||||
|
||||
@@ -117,6 +119,56 @@ class CustomerController extends BaseAdminController
|
||||
));
|
||||
}
|
||||
|
||||
public function createAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::CUSTOMER, AccessManager::CREATE)) return $response;
|
||||
|
||||
$message = null;
|
||||
|
||||
$customerCreateForm = new CustomerCreateForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
$form = $this->validateForm($customerCreateForm);
|
||||
|
||||
$data = $form->getData();
|
||||
$data["password"] = Password::generateRandom();
|
||||
|
||||
$event = $this->createEventInstance($form->getData());
|
||||
|
||||
|
||||
|
||||
$this->dispatch(TheliaEvents::CUSTOMER_CREATEACCOUNT, $event);
|
||||
|
||||
$successUrl = $customerCreateForm->getSuccessUrl();
|
||||
|
||||
$successUrl = str_replace('_ID_', $event->getCustomer()->getId(), $successUrl);
|
||||
|
||||
$this->redirect($successUrl);
|
||||
|
||||
|
||||
}catch (FormValidationException $e) {
|
||||
$message = sprintf("Please check your input: %s", $e->getMessage());
|
||||
} catch (PropelException $e) {
|
||||
$message = $e->getMessage();
|
||||
} catch (\Exception $e) {
|
||||
$message = sprintf("Sorry, an error occured: %s", $e->getMessage()." ".$e->getFile());
|
||||
}
|
||||
|
||||
if ($message !== false) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer creation process : %s.", $message));
|
||||
|
||||
$customerCreateForm->setErrorMessage($message);
|
||||
|
||||
$this->getParserContext()
|
||||
->addForm($customerCreateForm)
|
||||
->setGeneralError($message)
|
||||
;
|
||||
}
|
||||
|
||||
return $this->render("customers", array("display_customer" => 20));
|
||||
}
|
||||
|
||||
public function deleteAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::CUSTOMER, AccessManager::DELETE)) return $response;
|
||||
|
||||
@@ -157,23 +157,6 @@ class FeatureController extends AbstractCrudController
|
||||
'postscriptum' => $object->getPostscriptum()
|
||||
);
|
||||
|
||||
// Setup features values
|
||||
/*
|
||||
* FIXME : doesn't work. "We get a This form should not contain extra fields." error
|
||||
$attr_av_list = FeatureAvQuery::create()
|
||||
->joinWithI18n($this->getCurrentEditionLocale())
|
||||
->filterByFeatureId($object->getId())
|
||||
->find();
|
||||
|
||||
$attr_array = array();
|
||||
|
||||
foreach ($attr_av_list as $attr_av) {
|
||||
$attr_array[$attr_av->getId()] = $attr_av->getTitle();
|
||||
}
|
||||
|
||||
$data['feature_values'] = $attr_array;
|
||||
*/
|
||||
|
||||
// Setup the object form
|
||||
return new FeatureModificationForm($this->getRequest(), "form", $data);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Thelia\Controller\Admin;
|
||||
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Event\Document\DocumentCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Document\DocumentDeleteEvent;
|
||||
@@ -130,6 +130,20 @@ class FileController extends BaseAdminController
|
||||
$imageCreateOrUpdateEvent
|
||||
);
|
||||
|
||||
$this->adminLogAppend(
|
||||
AdminResources::retrieve($parentType),
|
||||
AccessManager::UPDATE,
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Saving images for %parentName% parent id %parentId% (%parentType%)',
|
||||
array(
|
||||
'%parentName%' => $imageCreateOrUpdateEvent->getParentName(),
|
||||
'%parentId%' => $imageCreateOrUpdateEvent->getParentId(),
|
||||
'%parentType%' => $imageCreateOrUpdateEvent->getImageType()
|
||||
),
|
||||
'image'
|
||||
)
|
||||
);
|
||||
|
||||
return new ResponseRest(array('status' => true, 'message' => ''));
|
||||
}
|
||||
}
|
||||
@@ -194,6 +208,20 @@ class FileController extends BaseAdminController
|
||||
$documentCreateOrUpdateEvent
|
||||
);
|
||||
|
||||
$this->adminLogAppend(
|
||||
AdminResources::retrieve($parentType),
|
||||
AccessManager::UPDATE,
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Saving documents for %parentName% parent id %parentId% (%parentType%)',
|
||||
array(
|
||||
'%parentName%' => $documentCreateOrUpdateEvent->getParentName(),
|
||||
'%parentId%' => $documentCreateOrUpdateEvent->getParentId(),
|
||||
'%parentType%' => $documentCreateOrUpdateEvent->getDocumentType()
|
||||
),
|
||||
'document'
|
||||
)
|
||||
);
|
||||
|
||||
return new ResponseRest(array('status' => true, 'message' => ''));
|
||||
}
|
||||
}
|
||||
@@ -368,7 +396,7 @@ class FileController extends BaseAdminController
|
||||
|
||||
$imageUpdated = $event->getModelImage();
|
||||
|
||||
$this->adminLogAppend(sprintf('Image with Ref %s (ID %d) modified', $imageUpdated->getTitle(), $imageUpdated->getId()));
|
||||
$this->adminLogAppend(AdminResources::retrieve($parentType), AccessManager::UPDATE, sprintf('Image with Ref %s (ID %d) modified', $imageUpdated->getTitle(), $imageUpdated->getId()));
|
||||
|
||||
if ($this->getRequest()->get('save_mode') == 'close') {
|
||||
$this->redirectToRoute('admin.images');
|
||||
@@ -445,7 +473,7 @@ class FileController extends BaseAdminController
|
||||
|
||||
$documentUpdated = $event->getModelDocument();
|
||||
|
||||
$this->adminLogAppend(sprintf('Document with Ref %s (ID %d) modified', $documentUpdated->getTitle(), $documentUpdated->getId()));
|
||||
$this->adminLogAppend(AdminResources::retrieve($parentType), AccessManager::UPDATE, sprintf('Document with Ref %s (ID %d) modified', $documentUpdated->getTitle(), $documentUpdated->getId()));
|
||||
|
||||
if ($this->getRequest()->get('save_mode') == 'close') {
|
||||
$this->redirectToRoute('admin.documents');
|
||||
@@ -509,10 +537,39 @@ class FileController extends BaseAdminController
|
||||
);
|
||||
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
TheliaEvents::IMAGE_DELETE,
|
||||
$imageDeleteEvent
|
||||
);
|
||||
try {
|
||||
$this->dispatch(
|
||||
TheliaEvents::IMAGE_DELETE,
|
||||
$imageDeleteEvent
|
||||
);
|
||||
|
||||
$this->adminLogAppend(
|
||||
AdminResources::retrieve($parentType),
|
||||
AccessManager::UPDATE,
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Deleting image for %id% with parent id %parentId%',
|
||||
array(
|
||||
'%id%' => $imageDeleteEvent->getImageToDelete()->getId(),
|
||||
'%parentId%' => $imageDeleteEvent->getImageToDelete()->getParentId(),
|
||||
),
|
||||
'image'
|
||||
)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->adminLogAppend(
|
||||
AdminResources::retrieve($parentType),
|
||||
AccessManager::UPDATE,
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Fail to delete image for %id% with parent id %parentId% (Exception : %e%)',
|
||||
array(
|
||||
'%id%' => $imageDeleteEvent->getImageToDelete()->getId(),
|
||||
'%parentId%' => $imageDeleteEvent->getImageToDelete()->getParentId(),
|
||||
'%e%' => $e->getMessage()
|
||||
),
|
||||
'image'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$message = $this->getTranslator()
|
||||
->trans(
|
||||
@@ -552,10 +609,39 @@ class FileController extends BaseAdminController
|
||||
);
|
||||
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
TheliaEvents::DOCUMENT_DELETE,
|
||||
$documentDeleteEvent
|
||||
);
|
||||
try {
|
||||
$this->dispatch(
|
||||
TheliaEvents::DOCUMENT_DELETE,
|
||||
$documentDeleteEvent
|
||||
);
|
||||
|
||||
$this->adminLogAppend(
|
||||
AdminResources::retrieve($parentType),
|
||||
AccessManager::UPDATE,
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Deleting document for %id% with parent id %parentId%',
|
||||
array(
|
||||
'%id%' => $documentDeleteEvent->getDocumentToDelete()->getId(),
|
||||
'%parentId%' => $documentDeleteEvent->getDocumentToDelete()->getParentId(),
|
||||
),
|
||||
'document'
|
||||
)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->adminLogAppend(
|
||||
AdminResources::retrieve($parentType),
|
||||
AccessManager::UPDATE,
|
||||
$this->container->get('thelia.translator')->trans(
|
||||
'Fail to delete document for %id% with parent id %parentId% (Exception : %e%)',
|
||||
array(
|
||||
'%id%' => $documentDeleteEvent->getDocumentToDelete()->getId(),
|
||||
'%parentId%' => $documentDeleteEvent->getDocumentToDelete()->getParentId(),
|
||||
'%e%' => $e->getMessage()
|
||||
),
|
||||
'document'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$message = $this->getTranslator()
|
||||
->trans(
|
||||
|
||||
102
core/lib/Thelia/Controller/Admin/HomeController.php
Normal file
102
core/lib/Thelia/Controller/Admin/HomeController.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Model\OrderQuery;
|
||||
|
||||
class HomeController extends BaseAdminController
|
||||
{
|
||||
const RESOURCE_CODE = "admin.home";
|
||||
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(self::RESOURCE_CODE, AccessManager::VIEW)) return $response;
|
||||
|
||||
// Render the edition template.
|
||||
return $this->render('home');
|
||||
}
|
||||
|
||||
public function loadStatsAjaxAction()
|
||||
{
|
||||
$data = new \stdClass();
|
||||
|
||||
$data->title = "Stats on " . $this->getRequest()->query->get('month', date('m')) . "/" . $this->getRequest()->query->get('year', date('Y'));
|
||||
|
||||
/* sales */
|
||||
$saleSeries = new \stdClass();
|
||||
$saleSeries->color = $this->getRequest()->query->get('sales_color', '#adadad');
|
||||
$saleSeries->data = OrderQuery::getSaleStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y'))
|
||||
);
|
||||
|
||||
/* new customers */
|
||||
$newCustomerSeries = new \stdClass();
|
||||
$newCustomerSeries->color = $this->getRequest()->query->get('customers_color', '#f39922');
|
||||
$newCustomerSeries->data = CustomerQuery::getNewCustomersStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y'))
|
||||
);
|
||||
|
||||
/* orders */
|
||||
$orderSeries = new \stdClass();
|
||||
$orderSeries->color = $this->getRequest()->query->get('orders_color', '#5cb85c');
|
||||
$orderSeries->data = OrderQuery::getOrdersStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y'))
|
||||
);
|
||||
|
||||
/* first order */
|
||||
$firstOrderSeries = new \stdClass();
|
||||
$firstOrderSeries->color = $this->getRequest()->query->get('first_orders_color', '#5bc0de');
|
||||
$firstOrderSeries->data = OrderQuery::getFirstOrdersStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y'))
|
||||
);
|
||||
|
||||
/* cancelled orders */
|
||||
$cancelledOrderSeries = new \stdClass();
|
||||
$cancelledOrderSeries->color = $this->getRequest()->query->get('cancelled_orders_color', '#d9534f');
|
||||
$cancelledOrderSeries->data = OrderQuery::getOrdersStats(
|
||||
$this->getRequest()->query->get('month', date('m')),
|
||||
$this->getRequest()->query->get('year', date('Y')),
|
||||
array(5)
|
||||
);
|
||||
|
||||
|
||||
$data->series = array(
|
||||
$saleSeries,
|
||||
$newCustomerSeries,
|
||||
$orderSeries,
|
||||
$firstOrderSeries,
|
||||
$cancelledOrderSeries,
|
||||
);
|
||||
|
||||
$json = json_encode($data);
|
||||
|
||||
return $this->jsonResponse($json);
|
||||
}
|
||||
}
|
||||
@@ -116,8 +116,8 @@ class LangController extends BaseAdminController
|
||||
}
|
||||
|
||||
$changedObject = $event->getLang();
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", 'Lang', $changedObject->getTitle(), $changedObject->getId()));
|
||||
$this->redirectToRoute('/admin/configuration/languages');
|
||||
$this->adminLogAppend(AdminResources::LANGUAGE, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", 'Lang', $changedObject->getTitle(), $changedObject->getId()));
|
||||
$this->redirectToRoute('admin.configuration.languages');
|
||||
} catch (\Exception $e) {
|
||||
$error_msg = $e->getMessage();
|
||||
}
|
||||
@@ -153,7 +153,7 @@ class LangController extends BaseAdminController
|
||||
}
|
||||
|
||||
$changedObject = $event->getLang();
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", 'Lang', $changedObject->getTitle(), $changedObject->getId()));
|
||||
$this->adminLogAppend(AdminResources::LANGUAGE, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", 'Lang', $changedObject->getTitle(), $changedObject->getId()));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error on changing default languages with message : %s", $e->getMessage()));
|
||||
@@ -189,7 +189,7 @@ class LangController extends BaseAdminController
|
||||
}
|
||||
|
||||
$createdObject = $createEvent->getLang();
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) created", 'Lang', $createdObject->getTitle(), $createdObject->getId()));
|
||||
$this->adminLogAppend(AdminResources::LANGUAGE, AccessManager::CREATE, sprintf("%s %s (ID %s) created", 'Lang', $createdObject->getTitle(), $createdObject->getId()));
|
||||
|
||||
$this->redirectToRoute('admin.configuration.languages');
|
||||
|
||||
|
||||
@@ -23,20 +23,91 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Event\MailingSystem\MailingSystemEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Form\MailingSystemModificationForm;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
/**
|
||||
* Class MailingSystemController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class MailingSystemController extends BaseAdminController
|
||||
{
|
||||
const RESOURCE_CODE = "admin.mailing-system";
|
||||
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::MAILING_SYSTEM, AccessManager::VIEW)) return $response;
|
||||
return $this->render("mailing-system");
|
||||
if (null !== $response = $this->checkAuth(self::RESOURCE_CODE, AccessManager::VIEW)) return $response;
|
||||
|
||||
// Hydrate the form abd pass it to the parser
|
||||
$data = array(
|
||||
'enabled' => ConfigQuery::isSmtpEnable() ? 1 : 0,
|
||||
'host' => ConfigQuery::getSmtpHost(),
|
||||
'port' => ConfigQuery::getSmtpPort(),
|
||||
'encryption' => ConfigQuery::getSmtpEncryption(),
|
||||
'username' => ConfigQuery::getSmtpUsername(),
|
||||
'password' => ConfigQuery::getSmtpPassword(),
|
||||
'authmode' => ConfigQuery::getSmtpAuthMode(),
|
||||
'timeout' => ConfigQuery::getSmtpTimeout(),
|
||||
'sourceip' => ConfigQuery::getSmtpSourceIp(),
|
||||
);
|
||||
|
||||
// Setup the object form
|
||||
$form = new MailingSystemModificationForm($this->getRequest(), "form", $data);
|
||||
|
||||
// Pass it to the parser
|
||||
$this->getParserContext()->addForm($form);
|
||||
|
||||
// Render the edition template.
|
||||
return $this->render('mailing-system');
|
||||
}
|
||||
|
||||
public function updateAction()
|
||||
{
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth(self::RESOURCE_CODE, AccessManager::UPDATE)) return $response;
|
||||
|
||||
$error_msg = false;
|
||||
|
||||
// Create the form from the request
|
||||
$form = new MailingSystemModificationForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
// Check the form against constraints violations
|
||||
$formData = $this->validateForm($form, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$event = new MailingSystemEvent();
|
||||
$event->setEnabled($formData->get('enabled')->getData());
|
||||
$event->setHost($formData->get('host')->getData());
|
||||
$event->setPort($formData->get('port')->getData());
|
||||
$event->setEncryption($formData->get('encryption')->getData());
|
||||
$event->setUsername($formData->get('username')->getData());
|
||||
$event->setPassword($formData->get('password')->getData());
|
||||
$event->setAuthMode($formData->get('authmode')->getData());
|
||||
$event->setTimeout($formData->get('timeout')->getData());
|
||||
$event->setSourceIp($formData->get('sourceip')->getData());
|
||||
|
||||
$this->dispatch(TheliaEvents::MAILING_SYSTEM_UPDATE, $event);
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirectToRoute("admin.configuration.mailing-system.view");
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("mailing system modification", array()),
|
||||
$error_msg,
|
||||
$form,
|
||||
$ex
|
||||
);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->render('mailing-system');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Event\Order\OrderAddressEvent;
|
||||
use Thelia\Core\Event\Order\OrderEvent;
|
||||
|
||||
@@ -64,6 +64,8 @@ use Thelia\Model\Country;
|
||||
use Thelia\Tools\NumberFormat;
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Form\ProductCombinationGenerationForm;
|
||||
use Thelia\Core\Event\Product\ProductCombinationGenerationEvent;
|
||||
|
||||
/**
|
||||
* Manages products
|
||||
@@ -931,7 +933,7 @@ class ProductController extends AbstractCrudController
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $event->getProductSaleElement()) {
|
||||
$this->adminLogAppend(sprintf("Product Sale Element (ID %s) for product reference %s modified", $changedObject->getId(), $event->getProduct()->getRef()));
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("Product Sale Element (ID %s) for product reference %s modified", $changedObject->getId(), $event->getProduct()->getRef()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1025,6 +1027,108 @@ class ProductController extends AbstractCrudController
|
||||
);
|
||||
}
|
||||
|
||||
// Create combinations
|
||||
protected function combine($input, &$output, &$tmp) {
|
||||
$current = array_shift($input);
|
||||
|
||||
if (count($input) > 0) {
|
||||
foreach($current as $element) {
|
||||
$tmp[] = $element;
|
||||
$this->combine($input, $output, $tmp);
|
||||
array_pop($tmp);
|
||||
}
|
||||
} else {
|
||||
foreach($current as $element) {
|
||||
$tmp[] = $element;
|
||||
$output[] = $tmp;
|
||||
array_pop($tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build combinations from the combination output builder
|
||||
*/
|
||||
public function buildCombinationsAction() {
|
||||
|
||||
// Check current user authorization
|
||||
if (null !== $response = $this->checkAuth($this->resourceCode, AccessManager::UPDATE)) return $response;
|
||||
|
||||
$error_msg = false;
|
||||
|
||||
$changeForm = new ProductCombinationGenerationForm($this->getRequest());
|
||||
|
||||
try {
|
||||
|
||||
// Check the form against constraints violations
|
||||
$form = $this->validateForm($changeForm, "POST");
|
||||
|
||||
// Get the form field values
|
||||
$data = $form->getData();
|
||||
|
||||
// Rework attributes_av array, to build an array which contains all combinations,
|
||||
// in the form combination[] = array of combination attributes av IDs
|
||||
//
|
||||
// First, create an array of attributes_av ID in the form $attributes_av_list[$attribute_id] = array of attributes_av ID
|
||||
// from the list of attribute_id:attributes_av ID from the form.
|
||||
$combinations = $attributes_av_list = array();
|
||||
|
||||
foreach($data['attribute_av'] as $item) {
|
||||
list($attribute_id, $attribute_av_id) = explode(':', $item);
|
||||
|
||||
if (! isset($attributes_av_list[$attribute_id]))
|
||||
$attributes_av_list[$attribute_id] = array();
|
||||
|
||||
|
||||
$attributes_av_list[$attribute_id][] = $attribute_av_id;
|
||||
}
|
||||
|
||||
// Next, recursively combine array
|
||||
$combinations = $tmp = array();
|
||||
|
||||
$this->combine($attributes_av_list, $combinations, $tmp);
|
||||
|
||||
// Create event
|
||||
$event = new ProductCombinationGenerationEvent(
|
||||
$this->getExistingObject(),
|
||||
$data['currency'],
|
||||
$combinations
|
||||
);
|
||||
|
||||
$event
|
||||
->setReference($data['reference'] == null ? '' : $data['reference'])
|
||||
->setPrice($data['price'] == null ? 0 : $data['price'])
|
||||
->setWeight($data['weight'] == null ? 0 : $data['weight'])
|
||||
->setQuantity($data['quantity'] == null ? 0 : $data['quantity'])
|
||||
->setSalePrice($data['sale_price'] == null ? 0 : $data['sale_price'])
|
||||
->setOnsale($data['onsale'] == null ? false : $data['onsale'])
|
||||
->setIsnew($data['isnew'] == null ? false : $data['isnew'])
|
||||
->setEanCode($data['ean_code'] == null ? '' : $data['ean_code'])
|
||||
;
|
||||
|
||||
$this->dispatch(TheliaEvents::PRODUCT_COMBINATION_GENERATION, $event);
|
||||
|
||||
// Log object modification
|
||||
$this->adminLogAppend(sprintf("Combination generation for product reference %s", $event->getProduct()->getRef()));
|
||||
|
||||
// Redirect to the success URL
|
||||
$this->redirect($changeForm->getSuccessUrl());
|
||||
|
||||
} catch (FormValidationException $ex) {
|
||||
// Form cannot be validated
|
||||
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
|
||||
} catch (\Exception $ex) {
|
||||
// Any other error
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("Combination builder"), $error_msg, $changeForm, $ex);
|
||||
|
||||
// At this point, the form has errors, and should be redisplayed.
|
||||
return $this->renderEditionTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked through Ajax; this method calculates the taxed price from the unaxed price, and
|
||||
* vice versa.
|
||||
|
||||
@@ -330,7 +330,7 @@ class ProfileController extends AbstractCrudController
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) {
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
if ($response == null) {
|
||||
@@ -379,7 +379,7 @@ class ProfileController extends AbstractCrudController
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) {
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
if ($response == null) {
|
||||
|
||||
@@ -50,7 +50,7 @@ class SessionController extends BaseAdminController
|
||||
|
||||
$this->getSecurityContext()->setAdminUser($user);
|
||||
|
||||
$this->adminLogAppend("Successful token authentication");
|
||||
$this->adminLogAppend("admin", "LOGIN", "Successful token authentication");
|
||||
|
||||
// Update the cookie
|
||||
$cookie = $this->createAdminRememberMeCookie($user);
|
||||
@@ -58,7 +58,7 @@ class SessionController extends BaseAdminController
|
||||
// Render the home page
|
||||
return $this->render("home");
|
||||
} catch (TokenAuthenticationException $ex) {
|
||||
$this->adminLogAppend("Token based authentication failed.");
|
||||
$this->adminLogAppend("admin", "LOGIN", "Token based authentication failed.");
|
||||
|
||||
// Clear the cookie
|
||||
$this->clearRememberMeCookie();
|
||||
@@ -99,7 +99,7 @@ class SessionController extends BaseAdminController
|
||||
$this->getSecurityContext()->setAdminUser($user);
|
||||
|
||||
// Log authentication success
|
||||
AdminLog::append("Authentication successful", $request, $user);
|
||||
AdminLog::append("admin", "LOGIN", "Authentication successful", $request, $user);
|
||||
|
||||
/**
|
||||
* FIXME: we have tou find a way to send cookie
|
||||
@@ -122,13 +122,13 @@ class SessionController extends BaseAdminController
|
||||
} catch (AuthenticationException $ex) {
|
||||
|
||||
// Log authentication failure
|
||||
AdminLog::append(sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request);
|
||||
AdminLog::append("admin", "LOGIN", sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request);
|
||||
|
||||
$message = $this->getTranslator()->trans("Login failed. Please check your username and password.");
|
||||
} catch (\Exception $ex) {
|
||||
|
||||
// Log authentication failure
|
||||
AdminLog::append(sprintf("Undefined error: %s", $ex->getMessage()), $request);
|
||||
AdminLog::append("admin", "LOGIN", sprintf("Undefined error: %s", $ex->getMessage()), $request);
|
||||
|
||||
$message = $this->getTranslator()->trans(
|
||||
"Unable to process your request. Please try again (%err).",
|
||||
|
||||
@@ -55,7 +55,7 @@ class ShippingZoneController extends BaseAdminController
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|\Symfony\Component\HttpFoundation\Response
|
||||
* @return mixed|\Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
public function addArea()
|
||||
{
|
||||
|
||||
182
core/lib/Thelia/Controller/Admin/SystemLogController.php
Normal file
182
core/lib/Thelia/Controller/Admin/SystemLogController.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Admin;
|
||||
|
||||
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Form\SystemLogConfigurationForm;
|
||||
use Thelia\Log\Tlog;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
/**
|
||||
* Class LangController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class SystemLogController extends BaseAdminController
|
||||
{
|
||||
|
||||
protected function renderTemplate()
|
||||
{
|
||||
$destinations = array();
|
||||
|
||||
$destination_directories = Tlog::getInstance()->getDestinationsDirectories();
|
||||
|
||||
foreach($destination_directories as $dir) {
|
||||
$this->loadDefinedDestinations($dir, $destinations);
|
||||
}
|
||||
|
||||
$active_destinations = explode(";", ConfigQuery::read(Tlog::VAR_DESTINATIONS, Tlog::DEFAUT_DESTINATIONS));
|
||||
|
||||
return $this->render('system-logs',
|
||||
array(
|
||||
'ip_address' => $this->getRequest()->getClientIp(),
|
||||
'destinations' => $destinations,
|
||||
'active_destinations' => $active_destinations
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function loadDefinedDestinations($directory, &$destinations) {
|
||||
|
||||
try {
|
||||
foreach (new \DirectoryIterator($directory) as $fileInfo) {
|
||||
|
||||
if ($fileInfo->isDot()) continue;
|
||||
|
||||
$matches = array();
|
||||
|
||||
if (preg_match("/([^\.]+)\.php/", $fileInfo->getFilename(), $matches)) {
|
||||
|
||||
$classname = $matches[1];
|
||||
|
||||
if (! isset($destinations[$classname])) {
|
||||
|
||||
$full_class_name = "Thelia\\Log\\Destination\\".$classname;
|
||||
|
||||
$destinations[$classname] = new $full_class_name();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\UnexpectedValueException $ex) {
|
||||
// Directory does no exists -> Nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::SYSTEM_LOG, AccessManager::VIEW)) return $response;
|
||||
|
||||
/*
|
||||
const VAR_LEVEL = "tlog_level";
|
||||
const VAR_DESTINATIONS = "tlog_destinations";
|
||||
const VAR_PREFIXE = "tlog_prefix";
|
||||
const VAR_FILES = "tlog_files";
|
||||
const VAR_IP = "tlog_ip";
|
||||
const VAR_SHOW_REDIRECT = "tlog_show_redirect";
|
||||
|
||||
const DEFAULT_LEVEL = self::DEBUG;
|
||||
const DEFAUT_DESTINATIONS = "Thelia\Log\Destination\TlogDestinationFile";
|
||||
const DEFAUT_PREFIXE = "#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: ";
|
||||
const DEFAUT_FILES = "*";
|
||||
const DEFAUT_IP = "";
|
||||
const DEFAUT_SHOW_REDIRECT = 0;
|
||||
|
||||
*/
|
||||
|
||||
// Hydrate the general configuration form
|
||||
$systemLogForm = new SystemLogConfigurationForm($this->getRequest(), 'form', array(
|
||||
'level' => ConfigQuery::read(Tlog::VAR_LEVEL, Tlog::DEFAULT_LEVEL),
|
||||
'format' => ConfigQuery::read(Tlog::VAR_PREFIXE, Tlog::DEFAUT_PREFIXE),
|
||||
'show_redirections' => ConfigQuery::read(Tlog::VAR_SHOW_REDIRECT, Tlog::DEFAUT_SHOW_REDIRECT),
|
||||
'files' => ConfigQuery::read(Tlog::VAR_FILES, Tlog::DEFAUT_FILES),
|
||||
'ip_addresses' => ConfigQuery::read(Tlog::VAR_IP, Tlog::DEFAUT_IP),
|
||||
));
|
||||
|
||||
$this->getParserContext()->addForm($systemLogForm);
|
||||
|
||||
return $this->renderTemplate();
|
||||
}
|
||||
|
||||
public function saveAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(AdminResources::LANGUAGE, AccessManager::UPDATE)) return $response;
|
||||
|
||||
$error_msg = false;
|
||||
|
||||
$systemLogForm = new SystemLogConfigurationForm($this->getRequest());
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($systemLogForm);
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
ConfigQuery::write(Tlog::VAR_LEVEL , $data['level']);
|
||||
ConfigQuery::write(Tlog::VAR_PREFIXE , $data['format']);
|
||||
ConfigQuery::write(Tlog::VAR_SHOW_REDIRECT , $data['show_redirections']);
|
||||
ConfigQuery::write(Tlog::VAR_FILES , $data['files']);
|
||||
ConfigQuery::write(Tlog::VAR_IP , $data['ip_addresses']);
|
||||
|
||||
// Save destination configuration
|
||||
$destinations = $this->getRequest()->get('destinations');
|
||||
$configs = $this->getRequest()->get('config');
|
||||
|
||||
$active_destinations = array();
|
||||
|
||||
foreach($destinations as $classname => $destination) {
|
||||
|
||||
if (isset($destination['active'])) {
|
||||
$active_destinations[] = $destination['classname'];
|
||||
}
|
||||
|
||||
if (isset($configs[$classname])) {
|
||||
|
||||
// Update destinations configuration
|
||||
foreach($configs[$classname] as $var => $value) {
|
||||
ConfigQuery::write($var, $value, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update active destinations list
|
||||
ConfigQuery::write(Tlog::VAR_DESTINATIONS, implode(';', $active_destinations));
|
||||
|
||||
$this->adminLogAppend(AdminResources::SYSTEM_LOG, AccessManager::UPDATE, "System log configuration changed");
|
||||
|
||||
$this->redirectToRoute('admin.configuration.system-logs.default');
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
$error_msg = $ex->getMessage();
|
||||
}
|
||||
|
||||
$this->setupFormErrorContext(
|
||||
$this->getTranslator()->trans("System log configuration failed."),
|
||||
$error_msg,
|
||||
$systemLogForm,
|
||||
$ex
|
||||
);
|
||||
|
||||
return $this->renderTemplate();
|
||||
}
|
||||
}
|
||||
@@ -279,7 +279,7 @@ class TaxRuleController extends AbstractCrudController
|
||||
|
||||
// Log object modification
|
||||
if (null !== $changedObject = $this->getObjectFromEvent($changeEvent)) {
|
||||
$this->adminLogAppend(sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
$this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("%s %s (ID %s) modified", ucfirst($this->objectName), $this->getObjectLabel($changedObject), $this->getObjectId($changedObject)));
|
||||
}
|
||||
|
||||
if ($response == null) {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
/*************************************************************************************/
|
||||
namespace Thelia\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
@@ -58,7 +58,7 @@ class BaseController extends ContainerAware
|
||||
/**
|
||||
* Return an empty response (after an ajax request, for example)
|
||||
* @param int $status
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return \Thelia\Core\HttpFoundation\Response
|
||||
*/
|
||||
protected function nullResponse($status = 200)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user