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.system-logs.configuration" class="Thelia\Form\SystemLogConfigurationForm"/>
<form name="thelia.admin.module.modification" class="Thelia\Form\ModuleModificationForm"/> <form name="thelia.admin.module.modification" class="Thelia\Form\ModuleModificationForm"/>
<form name="thelia.cache.flush" class="Thelia\Form\Cache\CacheFlushForm"/>
</forms> </forms>
</config> </config>

View File

@@ -981,6 +981,17 @@
<!-- end feature and feature routes management --> <!-- 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 --> <!-- Modules rule management -->
<route id="admin.module" path="/admin/modules"> <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 ATTRIBUTE = "admin.configuration.attribute";
const CACHE = "admin.cache";
const CATEGORY = "admin.category"; const CATEGORY = "admin.category";
const CONFIG = "admin.configuration"; 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";
}
}

View File

@@ -1269,7 +1269,8 @@ INSERT INTO resource (`id`, `code`, `created_at`, `updated_at`) VALUES
(21, 'admin.configuration.shipping-zone', NOW(), NOW()), (21, 'admin.configuration.shipping-zone', NOW(), NOW()),
(22, 'admin.configuration.tax', NOW(), NOW()), (22, 'admin.configuration.tax', NOW(), NOW()),
(23, 'admin.configuration.template', NOW(), NOW()), (23, 'admin.configuration.template', NOW(), NOW()),
(24, 'admin.configuration.system-log', NOW(), NOW()); (24, 'admin.configuration.system-log', NOW(), NOW()),
(25, 'admin.cache', NOW(), NOW());
/** /**
generated with command : php Thelia thelia:generate-resources --output sql-i18n generated with command : php Thelia thelia:generate-resources --output sql-i18n

View File

@@ -0,0 +1,31 @@
{extends file="admin-layout.tpl"}
{block name="page-title"}{intl l='Cache'}{/block}
{block name="check-resource"}admin.cache{/block}
{block name="check-access"}view{/block}
{block name="main-content"}
<div class="variables edit-variable">
<div id="wrapper" class="container">
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
<li>{intl l="Cache"}</li>
</ul>
<div class="row">
<div class="col-md-12">
{form name="thelia.cache.flush"}
<form method="post" action="{url path="/admin/cache/flush"}">
{form_hidden_fields form=$form}
<button type="submit" class="btn btn-danger btn-lg btn-block">{intl l="Flush the cache"}</button>
</form>
{/form}
</div>
</div>
</div>
</div>
{/block}

View File

@@ -178,6 +178,12 @@
<td><a class="btn btn-default btn-xs" href="{url path='/admin/configuration/system-logs'}"><i class="glyphicon glyphicon-edit"></i></a></td> <td><a class="btn btn-default btn-xs" href="{url path='/admin/configuration/system-logs'}"><i class="glyphicon glyphicon-edit"></i></a></td>
</tr> </tr>
{/loop} {/loop}
{loop type="auth" name="pcc9" role="ADMIN" resource="admin.configuration.cache" access="VIEW"}
<tr>
<td><a href="{url path='/admin/configuration/cache'}">{intl l='Cache'}</a></td>
<td><a class="btn btn-default btn-xs" href="{url path='/admin/configuration/cache'}"><i class="glyphicon glyphicon-edit"></i></a></td>
</tr>
{/loop}
{module_include location='system_configuration_bottom'} {module_include location='system_configuration_bottom'}
</table> </table>
</div> </div>