allow to possibility to flush the cache from admin panel, Fix #249

This commit is contained in:
Manuel Raynaud
2014-04-10 15:56:18 +02:00
parent 5562dac887
commit 5e9070097d
8 changed files with 196 additions and 1 deletions

View File

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

View File

@@ -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">

View 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) {
}
}
}

View File

@@ -60,6 +60,8 @@ final class AdminResources
const ATTRIBUTE = "admin.configuration.attribute";
const CACHE = "admin.cache";
const CATEGORY = "admin.category";
const CONFIG = "admin.configuration";

View 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";
}
}