allow to possibility to flush the cache from admin panel, Fix #249
This commit is contained in:
@@ -122,6 +122,8 @@
|
||||
<form name="thelia.system-logs.configuration" class="Thelia\Form\SystemLogConfigurationForm"/>
|
||||
|
||||
<form name="thelia.admin.module.modification" class="Thelia\Form\ModuleModificationForm"/>
|
||||
|
||||
<form name="thelia.cache.flush" class="Thelia\Form\Cache\CacheFlushForm"/>
|
||||
</forms>
|
||||
|
||||
</config>
|
||||
|
||||
@@ -981,6 +981,17 @@
|
||||
|
||||
<!-- end feature and feature routes management -->
|
||||
|
||||
<!-- cache route management -->
|
||||
<route id="admin.configuration.cache" path="/admin/configuration/cache">
|
||||
<default key="_controller">Thelia\Controller\Admin\CacheController::defaultAction</default>
|
||||
</route>
|
||||
|
||||
<route id="admin.configuration.cache.flush" path="/admin/cache/flush">
|
||||
<default key="_controller">Thelia\Controller\Admin\CacheController::flushAction</default>
|
||||
</route>
|
||||
|
||||
<!-- and cache route management -->
|
||||
|
||||
<!-- Modules rule management -->
|
||||
|
||||
<route id="admin.module" path="/admin/modules">
|
||||
|
||||
73
core/lib/Thelia/Controller/Admin/CacheController.php
Normal file
73
core/lib/Thelia/Controller/Admin/CacheController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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\Event\Cache\CacheEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Form\Cache\CacheFlushForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
|
||||
|
||||
/**
|
||||
* Class CacheController
|
||||
* @package Thelia\Controller\Admin
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class CacheController extends BaseAdminController
|
||||
{
|
||||
|
||||
public function defaultAction()
|
||||
{
|
||||
if (null !== $result = $this->checkAuth(AdminResources::CACHE, [], AccessManager::VIEW)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $this->render('cache');
|
||||
}
|
||||
|
||||
public function flushAction()
|
||||
{
|
||||
if (null !== $result = $this->checkAuth(AdminResources::CACHE, [], AccessManager::UPDATE)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$form = new CacheFlushForm($this->getRequest());
|
||||
try {
|
||||
$this->validateForm($form);
|
||||
|
||||
$event = new CacheEvent($this->container->getParameter("kernel.cache_dir"));
|
||||
$this->dispatch(TheliaEvents::CACHE_CLEAR, $event);
|
||||
|
||||
$event = new CacheEvent(THELIA_WEB_DIR . "assets");
|
||||
$this->dispatch(TheliaEvents::CACHE_CLEAR, $event);
|
||||
|
||||
$this->redirectToRoute('admin.configuration.cache');
|
||||
} catch (FormValidationException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -60,6 +60,8 @@ final class AdminResources
|
||||
|
||||
const ATTRIBUTE = "admin.configuration.attribute";
|
||||
|
||||
const CACHE = "admin.cache";
|
||||
|
||||
const CATEGORY = "admin.category";
|
||||
|
||||
const CONFIG = "admin.configuration";
|
||||
|
||||
69
core/lib/Thelia/Form/Cache/CacheFlushForm.php
Normal file
69
core/lib/Thelia/Form/Cache/CacheFlushForm.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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\Form\Cache;
|
||||
|
||||
use Thelia\Form\BaseForm;
|
||||
|
||||
|
||||
/**
|
||||
* Class CacheFlushForm
|
||||
* @package Thelia\Form\Cache
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class CacheFlushForm extends BaseForm
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* in this function you add all the fields you need for your Form.
|
||||
* Form this you have to call add method on $this->formBuilder attribute :
|
||||
*
|
||||
* $this->formBuilder->add("name", "text")
|
||||
* ->add("email", "email", array(
|
||||
* "attr" => array(
|
||||
* "class" => "field"
|
||||
* ),
|
||||
* "label" => "email",
|
||||
* "constraints" => array(
|
||||
* new \Symfony\Component\Validator\Constraints\NotBlank()
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* ->add('age', 'integer');
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
//Nothing, we just want CSRF protection
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of you form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return "cache_flush";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user