Ajout du vidage des caches assets, images et documents

This commit is contained in:
Franck Allimant
2014-04-26 17:06:10 +02:00
parent d7b9479cb9
commit 657af6e8f1
8 changed files with 317 additions and 170 deletions

View File

@@ -124,6 +124,9 @@
<form name="thelia.admin.module.modification" class="Thelia\Form\ModuleModificationForm"/>
<form name="thelia.cache.flush" class="Thelia\Form\Cache\CacheFlushForm"/>
<form name="thelia.assets.flush" class="Thelia\Form\Cache\AssetsFlushForm"/>
<form name="thelia.images-and-documents-cache.flush" class="Thelia\Form\Cache\ImagesAndDocumentsCacheFlushForm"/>
</forms>
</config>

View File

@@ -1000,6 +1000,14 @@
<default key="_controller">Thelia\Controller\Admin\AdvancedConfigurationController::flushCacheAction</default>
</route>
<route id="admin.configuration.advanced.flush-assets" path="/admin/configuration/advanced/flush-assets">
<default key="_controller">Thelia\Controller\Admin\AdvancedConfigurationController::flushAssetsAction</default>
</route>
<route id="admin.configuration.advanced.flush-images-and-documents" path="/admin/configuration/advanced/flush-images-and-documents">
<default key="_controller">Thelia\Controller\Admin\AdvancedConfigurationController::flushImagesAndDocumentsAction</default>
</route>
<!-- and cache route management -->
<!-- Modules rule management -->

View File

@@ -16,8 +16,12 @@ 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\AssetsFlushForm;
use Thelia\Form\Cache\CacheFlushForm;
use Thelia\Form\Cache\ImagesAndDocumentsCacheFlushForm;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Log\Tlog;
use Thelia\Model\ConfigQuery;
/**
* Class CacheController
@@ -49,12 +53,53 @@ class AdvancedConfigurationController extends BaseAdminController
$event = new CacheEvent($this->container->getParameter("kernel.cache_dir"));
$this->dispatch(TheliaEvents::CACHE_CLEAR, $event);
} catch (\Exception $e) {
Tlog::getInstance()->addError(sprintf("Flush cache error: %s", $e->getMessage()));
}
$this->redirectToRoute('admin.configuration.advanced');
}
public function flushAssetsAction()
{
if (null !== $result = $this->checkAuth(AdminResources::ADVANCED_CONFIGURATION, [], AccessManager::UPDATE)) {
return $result;
}
$form = new AssetsFlushForm($this->getRequest());
try {
$this->validateForm($form);
$event = new CacheEvent(THELIA_WEB_DIR . "assets");
$this->dispatch(TheliaEvents::CACHE_CLEAR, $event);
$this->redirectToRoute('admin.configuration.advanced');
} catch (FormValidationException $e) {
} catch (\Exception $e) {
Tlog::getInstance()->addError(sprintf("Flush assets error: %s", $e->getMessage()));
}
$this->redirectToRoute('admin.configuration.advanced');
}
public function flushImagesAndDocumentsAction()
{
if (null !== $result = $this->checkAuth(AdminResources::ADVANCED_CONFIGURATION, [], AccessManager::UPDATE)) {
return $result;
}
$form = new ImagesAndDocumentsCacheFlushForm($this->getRequest());
try {
$this->validateForm($form);
$event = new CacheEvent(THELIA_WEB_DIR . ConfigQuery::read('image_cache_dir_from_web_root', 'cache'));
$this->dispatch(TheliaEvents::CACHE_CLEAR, $event);
$event = new CacheEvent(THELIA_WEB_DIR . ConfigQuery::read('document_cache_dir_from_web_root', 'cache'));
$this->dispatch(TheliaEvents::CACHE_CLEAR, $event);
} catch (\Exception $e) {
Tlog::getInstance()->addError(sprintf("Flush images and document error: %s", $e->getMessage()));
}
$this->redirectToRoute('admin.configuration.advanced');
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Cache;
use Thelia\Form\BaseForm;
/**
* Class CacheFlushForm
* @package Thelia\Form\Cache
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class AssetsFlushForm extends BaseForm
{
/**
* @inheritdoc
*/
protected function buildForm()
{
//Nothing, we just want CSRF protection
}
/**
* @inheritdoc
*/
public function getName()
{
return "assets_flush";
}
}

View File

@@ -23,24 +23,7 @@ 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
* @inheritdoc
*/
protected function buildForm()
{
@@ -48,7 +31,7 @@ class CacheFlushForm extends BaseForm
}
/**
* @return string the name of you form. This name must be unique
* @inheritdoc
*/
public function getName()
{

View File

@@ -0,0 +1,40 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Form\Cache;
use Thelia\Form\BaseForm;
/**
* Class CacheFlushForm
* @package Thelia\Form\Cache
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
class ImagesAndDocumentsCacheFlushForm extends BaseForm
{
/**
* @inheritdoc
*/
protected function buildForm()
{
//Nothing, we just want CSRF protection
}
/**
* @inheritdoc
*/
public function getName()
{
return "images_and_documents_cache_flush";
}
}

View File

@@ -51,6 +51,7 @@ return array(
'Administration profiles' => 'Profils d\'administration',
'Administrators' => 'Administrateurs',
'Advanced configuration' => 'Configuration avancée',
'Advanced configuration and tools' => 'Outils et configuration avancés',
'Afficher ce profil' => 'Afficher ce profil',
'All countries are assigned to a shipping zone.' => 'Tous les pays sont assignés à une zone de livraison.',
'All orders' => 'Toutes les commandes',
@@ -82,7 +83,6 @@ return array(
'Browse files' => 'Parcourir les fichiers',
'Browse this category' => 'Parcourir cette catégorie',
'Browse this folder' => 'Parcourir ce dossier',
'Cache' => 'Cache',
'Can\'t be cumulative' => 'Ne peut pas se cumuler',
'Can\'t load documents, please refresh this page.' => 'Impossible de charger les documents. Rechargez la page',
'Can\'t load images, please refresh this page.' => 'Impossible de charger l\'image. Rechargez la page',
@@ -474,7 +474,8 @@ return array(
'FirstName' => 'Prénom',
'Firstname' => 'Prénom',
'Flush the Thelia internal cache' => 'Vider le cache interne de Thelia',
'Flush the cache now' => 'Vider le cache maintenant',
'Flush the assets cache directory' => 'Vider le cache des assets web',
'Flush the images and documents cache' => 'Vider le caches des images et documents',
'Folder created on %date_create. Last modification: %date_change' => 'Dossier créé le %date_create. Dernière modification le %date_change',
'Folder title' => 'Titre du dossier',
'Folders' => 'Dossiers',
@@ -829,6 +830,7 @@ return array(
'Thelia Shipping configuration' => 'Configuration des livraisons Thelia',
'Thelia Shipping zones' => 'Zone de livraison de Thelia',
'Thelia System Variables' => 'Variables Thelia',
'Thelia caches flushing' => 'Vidage des caches Thelia',
'Thelia configuration' => 'Configuration thelia',
'Thelia contributions' => 'Contributions de Thelia',
'Thelia core' => 'Coeur de Thelia',
@@ -861,6 +863,7 @@ return array(
'This is the message purpose, such as \'Order confirmation\'.' => 'Titre du message (ex : confirmation de commande)',
'This is the subject of the e-mail, such as \'Your order is confirmed\'.' => 'Sujet du message (ex : votre commande est validée)',
'This mailing template could not be changed.' => 'Le template de mailing ne peut pas être changé',
'This module cannot be started, some files are probably missing.' => 'Ce module ne peut pas être démarré, il manque sans doute des fichiers.',
'This month' => 'Ce mois',
'This product contains no accessories' => 'Ce produit n\'a aucun accessoire',
'This product contains no contents' => 'Ce produit n\'a aucun contenu associé',

View File

@@ -1,6 +1,6 @@
{extends file="admin-layout.tpl"}
{block name="page-title"}{intl l='Cache'}{/block}
{block name="page-title"}{intl l='Advanced configuration'}{/block}
{block name="check-resource"}admin.cache{/block}
{block name="check-access"}view{/block}
@@ -13,31 +13,56 @@
<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="Advanced configuration"}</li>
<li>{intl l="Advanced configuration and tools"}</li>
</ul>
<div class="row">
<div class="col-md-12 general-block-decorator">
<div class="row">
<div class="col-md-12 general-block-decorator">
<div class="row vertical-row-space">
<div class="col-md-12 title title-without-tabs">
{intl l='Advanced configuration'}
{intl l='Thelia caches flushing'}
</div>
</div>
<div class="row">
<div class="col-md-4">
{form name="thelia.cache.flush"}
<form method="post" action="{url path="/admin/configuration/advanced/flush-cache"}">
{form_hidden_fields form=$form}
<div class="form-group">
<button type="submit" class="btn btn-warning btn-sm btn-block">{intl l="Flush the Thelia internal cache"}</button>
</div>
</form>
{/form}
</div>
<div class="form-container">
<div class="col-md-6">
<div class="col-md-4">
{form name="thelia.cache.flush"}
<form method="post" action="{url path="/admin/configuration/advanced/flush-cache"}">
{form_hidden_fields form=$form}
{form name="thelia.assets.flush"}
<form method="post" action="{url path="/admin/configuration/advanced/flush-assets"}">
{form_hidden_fields form=$form}
<div class="form-group">
<label class="control-label">{intl l="Flush the Thelia internal cache"} : </label>
<button type="submit" class="btn btn-warning btn-sm">{intl l="Flush the cache now"}</button>
</div>
</form>
{/form}
</div>
<div class="form-group">
<button type="submit" class="btn btn-warning btn-sm btn-block">{intl l="Flush the assets cache directory"}</button>
</div>
</form>
{/form}
</div>
<div class="col-md-4">
{form name="thelia.images-and-documents-cache.flush"}
<form method="post" action="{url path="/admin/configuration/advanced/flush-images-and-documents"}">
{form_hidden_fields form=$form}
<div class="form-group">
<button type="submit" class="btn btn-warning btn-sm btn-block">{intl l="Flush the images and documents cache"}</button>
</div>
</form>
{/form}
</div>
</div>
</div>