diff --git a/core/lib/Thelia/Config/Resources/form.xml b/core/lib/Thelia/Config/Resources/form.xml index ec281266e..7cfd5ce34 100644 --- a/core/lib/Thelia/Config/Resources/form.xml +++ b/core/lib/Thelia/Config/Resources/form.xml @@ -122,6 +122,8 @@
+ + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 3e6ea5646..7173fa8ce 100644 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -981,6 +981,17 @@ + + + Thelia\Controller\Admin\CacheController::defaultAction + + + + Thelia\Controller\Admin\CacheController::flushAction + + + + diff --git a/core/lib/Thelia/Controller/Admin/CacheController.php b/core/lib/Thelia/Controller/Admin/CacheController.php new file mode 100644 index 000000000..4f183cfd4 --- /dev/null +++ b/core/lib/Thelia/Controller/Admin/CacheController.php @@ -0,0 +1,73 @@ +. */ +/* */ +/*************************************************************************************/ + +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 + */ +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) { + + } + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Security/Resource/AdminResources.php b/core/lib/Thelia/Core/Security/Resource/AdminResources.php index 314038e67..4d8d8ad90 100644 --- a/core/lib/Thelia/Core/Security/Resource/AdminResources.php +++ b/core/lib/Thelia/Core/Security/Resource/AdminResources.php @@ -60,6 +60,8 @@ final class AdminResources const ATTRIBUTE = "admin.configuration.attribute"; + const CACHE = "admin.cache"; + const CATEGORY = "admin.category"; const CONFIG = "admin.configuration"; diff --git a/core/lib/Thelia/Form/Cache/CacheFlushForm.php b/core/lib/Thelia/Form/Cache/CacheFlushForm.php new file mode 100644 index 000000000..8410bd7c7 --- /dev/null +++ b/core/lib/Thelia/Form/Cache/CacheFlushForm.php @@ -0,0 +1,69 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form\Cache; + +use Thelia\Form\BaseForm; + + +/** + * Class CacheFlushForm + * @package Thelia\Form\Cache + * @author Manuel Raynaud + */ +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"; + } +} \ No newline at end of file diff --git a/install/insert.sql b/install/insert.sql index 9ad551a47..a1a629f67 100644 --- a/install/insert.sql +++ b/install/insert.sql @@ -1269,7 +1269,8 @@ INSERT INTO resource (`id`, `code`, `created_at`, `updated_at`) VALUES (21, 'admin.configuration.shipping-zone', NOW(), NOW()), (22, 'admin.configuration.tax', 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 diff --git a/templates/backOffice/default/cache.html b/templates/backOffice/default/cache.html new file mode 100644 index 000000000..95c9b5178 --- /dev/null +++ b/templates/backOffice/default/cache.html @@ -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"} +
+ +
+ + + +
+
+ {form name="thelia.cache.flush"} + + {form_hidden_fields form=$form} + + + {/form} +
+
+
+
+{/block} diff --git a/templates/backOffice/default/configuration.html b/templates/backOffice/default/configuration.html index 1560cd332..4e57584ca 100644 --- a/templates/backOffice/default/configuration.html +++ b/templates/backOffice/default/configuration.html @@ -178,6 +178,12 @@ {/loop} + {loop type="auth" name="pcc9" role="ADMIN" resource="admin.configuration.cache" access="VIEW"} + + {intl l='Cache'} + + + {/loop} {module_include location='system_configuration_bottom'}