[FEATURE] Enabled removing all rendered caches via clear caches menu 76/15176/1
authorBastian Bringenberg <mail@bastian-bringenberg.de>
Sun, 30 Sep 2012 17:39:27 +0000 (19:39 +0200)
committerBastian Bringenberg <mail@bastian-bringenberg.de>
Sun, 30 Sep 2012 17:39:27 +0000 (19:39 +0200)
Implemented the ClearCaches Button and added the functionality behind it.

If User is no Admin he has to set in User TS:
options.clearCache.typo3wiki = 1

Change-Id: I00d32116f580fcaca90b76a5b0cfd7fdec72c386
Resolves: #41465 @2h30

Classes/Controller/PageController.php
Resources/Private/Language/locallang_db.xlf
Resources/Public/Icons/cache.gif [new file with mode: 0644]
class.tx_typo3wiki_cache.php [new file with mode: 0644]
class.tx_typo3wiki_cachemenu.php [new file with mode: 0644]
ext_localconf.php

index 8fdcf18..bf1f443 100755 (executable)
@@ -82,6 +82,10 @@ class Tx_Typo3wiki_Controller_PageController extends Tx_Extbase_MVC_Controller_A
                        $redirection = $this->request->getArgument('redirection');
                }catch(Exception $e){}
                if($page->getRedirection() != NULL) $this->redirect('show', NULL, NULL, array('page' => $page->getRedirection(), 'redirection' => $page->getPageTitle()));
+               if($page->getMainRevision()->getRenderedText() === ''){
+                       $renderHelper = $this->createRenderHelper();
+                       $page->getMainRevision()->setRenderedText($renderHelper->renderText($page->getMainRevision()->getUnrenderedText()));
+               }
                $this->view->assign('redirection', $redirection);
                $this->view->assign('page', $page);
        }
@@ -124,12 +128,7 @@ class Tx_Typo3wiki_Controller_PageController extends Tx_Extbase_MVC_Controller_A
        public function updateAction(Tx_Typo3wiki_Domain_Model_Page $page) {
                if($page === NULL) $page = $this->pageRepository->findOneByPageTitle($this->request->getArgument('page'));
                $text = $this->request->getArgument('text') ;
-
-               $renderHelper = $this->objectManager->get('Tx_Typo3wiki_Helper_RenderHelper');
-               $renderHelper->setPageRepository($this->pageRepository);
-               $renderHelper->setUriBuilder($this->uriBuilder);
-               $renderHelper->setSettings($this->settings);
-               $renderHelper->setObjectManager($this->objectManager);
+               $renderHelper = $this->createRenderHelper();
 
                $revision = $this->objectManager->get('Tx_Typo3wiki_Domain_Model_TextRevision');
                $revision->setUnrenderedText($text);
@@ -155,4 +154,19 @@ class Tx_Typo3wiki_Controller_PageController extends Tx_Extbase_MVC_Controller_A
                $this->redirect('show', NULL, NULL, array('page' => $page));
        }
 
+       /**
+        * Creates a RenderHelper
+        *
+        * @return Tx_Typo3wiki_Helper_RenderHelper
+        */
+       private function createRenderHelper(){
+               $renderHelper = $this->objectManager->get('Tx_Typo3wiki_Helper_RenderHelper');
+               $renderHelper->setPageRepository($this->pageRepository);
+               $renderHelper->setUriBuilder($this->uriBuilder);
+               $renderHelper->setSettings($this->settings);
+               $renderHelper->setObjectManager($this->objectManager);
+
+               return $renderHelper;
+       }
+
 }
\ No newline at end of file
index 049b6c5..d6264d5 100755 (executable)
                                <source>Pages</source>
                        </trans-unit>
 
+
+                       <trans-unit id="tx_typo3wiki_backend.cacheMenu">
+                               <source>Empty Wiki Cache</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>
\ No newline at end of file
diff --git a/Resources/Public/Icons/cache.gif b/Resources/Public/Icons/cache.gif
new file mode 100644 (file)
index 0000000..1a832d4
Binary files /dev/null and b/Resources/Public/Icons/cache.gif differ
diff --git a/class.tx_typo3wiki_cache.php b/class.tx_typo3wiki_cache.php
new file mode 100644 (file)
index 0000000..ba97cd3
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+       /***************************************************************
+        *  Copyright notice
+        *
+        *  (c) 2012 Bastian Bringenberg <typo3@bastian-bringenberg.de>, Bastian Bringenberg
+        *
+        *  All rights reserved
+        *
+        *  This script is part of the TYPO3 project. The TYPO3 project 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, or
+        *  (at your option) any later version.
+        *
+        *  The GNU General Public License can be found at
+        *  http://www.gnu.org/copyleft/gpl.html.
+        *
+        *  This script 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.
+        *
+        *  This copyright notice MUST APPEAR in all copies of the script!
+        ***************************************************************/
+
+       class tx_typo3wiki_cache {
+
+               /**
+                * Clears all rendered Text
+                *
+                * @return        void
+                */
+               public static function clear() {
+                       $GLOBALS['TYPO3_DB']->sql_query('UPDATE tx_typo3wiki_domain_model_textrevision SET rendered_text = "";');
+               }
+       }
diff --git a/class.tx_typo3wiki_cachemenu.php b/class.tx_typo3wiki_cachemenu.php
new file mode 100644 (file)
index 0000000..bada712
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+       /***************************************************************
+        *  Copyright notice
+        *
+        *  (c) 2012 Bastian Bringenberg <typo3@bastian-bringenberg.de>, Bastian Bringenberg
+        *
+        *  All rights reserved
+        *
+        *  This script is part of the TYPO3 project. The TYPO3 project 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, or
+        *  (at your option) any later version.
+        *
+        *  The GNU General Public License can be found at
+        *  http://www.gnu.org/copyleft/gpl.html.
+        *
+        *  This script 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.
+        *
+        *  This copyright notice MUST APPEAR in all copies of the script!
+        ***************************************************************/
+
+
+       require_once(PATH_typo3 . 'interfaces/interface.backend_cacheActionsHook.php');
+       //require_once(t3lib_extMgm::extPath('realurl_clearcache') . 'class.tx_realurlclearcache.php');
+
+       class tx_typo3wiki_cachemenu implements backend_cacheActionsHook {
+               /**
+                * Adds the option to clear the TYPO3Wiki cache in the back-end clear cache menu.
+                *
+                * @param array $a_cacheActions
+                * @param array $a_optionValues
+                * @return void
+                * @see typo3/interfaces/backend_cacheActionsHook#manipulateCacheActions($cacheActions, $optionValues)
+                */
+               public function manipulateCacheActions(&$a_cacheActions, &$a_optionValues) {
+                       if (($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.typo3wiki')) && $GLOBALS['TYPO3_CONF_VARS']['EXT']['extCache']) {
+                               $s_title = $GLOBALS['LANG']->sL('LLL:EXT:typo3wiki/Resources/Private/Language/locallang_db.xlf:tx_typo3wiki_backend.cacheMenu', TRUE);
+                               $s_imagePath = t3lib_extMgm::extRelPath('typo3wiki') . 'Resources/Public/Icons/cache.gif';
+                               $a_cacheActions[] = array(
+                                       'id' => 'typo3wiki',
+                                       'title' => $s_title,
+                                       'href' => 'ajax.php?ajaxID=tx_typo3wiki::clear',
+                                       'icon' => '<img src="'.$s_imagePath.'" title="'.$s_title.'" alt="'.$s_title.'" />',
+                               );
+                               $a_optionValues[] = 'clearCacheTYPO3Wiki';
+                       }
+               }
+       }
\ No newline at end of file
index bdc07b4..0cd7c73 100755 (executable)
@@ -17,4 +17,14 @@ Tx_Extbase_Utility_Extension::configurePlugin(
        )
 );
 
-?>
\ No newline at end of file
+/**
+ * Enabling Caching Button in Backend
+ *
+ */
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'][] = 'EXT:'.$_EXTKEY.'/class.tx_typo3wiki_cachemenu.php:&tx_typo3wiki_cachemenu';
+$TYPO3_CONF_VARS['BE']['AJAX']['tx_typo3wiki::clear'] = 'EXT:'.$_EXTKEY.'/class.tx_typo3wiki_cache.php:tx_typo3wiki_cache->clear';
+
+       /** NOT NEEDED */
+//$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['additionalBackendItems']['cacheActions'][] = 'EXT:'.$_EXTKEY.'/class.tx_typo3wiki_cachemenu.php:&tx_typo3wiki_cachemenu';
+//$TYPO3_CONF_VARS['BE']['AJAX']['tx_realurlclearcache::clear'] = 'EXT:'.$_EXTKEY.'/class.tx_typo3wiki.php:tx_typo3wiki->clear';
+//$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'][] = 'EXT:'.$_EXTKEY.'/class.tx_typo3wiki.php:tx_tx_typo3wiki->pageIcon';
\ No newline at end of file