From 1b83cad80a4cffe054faea3ec1f30d7b18389942 Mon Sep 17 00:00:00 2001
From: Benjamin Mack <benni@typo3.org>
Date: Sat, 18 Jan 2014 11:20:08 +0100
Subject: [PATCH] [TASK] Cache menu needs clear namings and permissions

With the introduction of the grouping mechanisms of the
caching framework and the sensitivity of the system
caches group, the re-ordering and re-naming of cache
menu entries is necessary to ensure that admins and
editors use the caching mechanisms right.

Therefore there are new labels as well as "Clear all caches"
below "Clear page content" as it has a higher impact on
the system. The option to clear the Configuration Cache
/ System Caches is now disabled by default, even for
admins. It is active when the TSconfig option
options.clearCache.system = 1 is set or if the system is in
development context. This avoids slow page rendering
after clearing the system caches.

A new title attribute is added to explain the menu items
when hovering.

Resolves: #55119
Releases: 6.2
Change-Id: Ifd6026279a890b743c6c3cda09def19f9b7d59b7
Reviewed-on: https://review.typo3.org/26912
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Marcin S?gol
Tested-by: Marcin S?gol
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
---
 NEWS.md                                       | 31 +++++++++++++
 .../Classes/Toolbar/ClearCacheToolbarItem.php | 45 ++++++++++---------
 typo3/sysext/lang/locallang_core.xlf          | 21 +++++++++
 3 files changed, 77 insertions(+), 20 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index e0a818bade74..f7e4ed70cd8a 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -69,6 +69,37 @@ does not include the system-related caches anymore** - these can be cleared by
 user has the according permissions. Each cache can be configured to be in one or
 multiple groups in its configuration parameters. Custom groups can be defined
 and cleared manually.
+All extension maintainers are encouraged to switch their own caching mechanisms
+to the caching framework and use the API instead of using hooks within TCEmain,
+as the clearing via TCEmain would only be triggered if going through
+the TCEmain calls (not via Extbase e.g.).
+
+* Re-ordered backend menu items
+With grouped caching (see above) items in the menu bar of the TYPO3 Backend
+have been re-arranged and renamed to reflect the impact of the icons.
+
+ - "Flush frontend caches" clears all caches marked with the group "pages".
+ This includes clearing the previous "cache_hash", "cache_pages" and
+ "cache_pagesection", which affects links, TypoScript, fully-cached pages and
+ cached page elements.
+
+ - "Flush all caches" clears all caches inside the groups "all" and "pages"
+ as well as additional database tables registered via hooks in TCEmain. However
+ the system-related caches are NOT flushed.
+
+ - "Flush system caches" clears all system-related caches, which is the class
+ loading cache, configuration cache (previously known as temp_CACHED_* files)
+ and some other extbase-related class caches. The symbol is now disabled
+ by default, even for admins, and can be enabled by setting the userTSconfig
+ option "options.clearCache.system=1", and is also always enabled using
+ the Application Context / TYPO3_CONTEXT Environment Option "Development".
+ Additionally, clearing system caches can be done via the Install Tool, they
+ are automatically flushed when an extension is being activated/uninstalled.
+
+All hooks within TCEmain still work as expected. However, the use of
+clear_cacheCmd with the parameter "temp_cached" is discouraged with
+the introduction of the group "system".
+
 
 ### Frontend
 
diff --git a/typo3/sysext/backend/Classes/Toolbar/ClearCacheToolbarItem.php b/typo3/sysext/backend/Classes/Toolbar/ClearCacheToolbarItem.php
index 316bf5fcfaeb..dd4c3360533e 100644
--- a/typo3/sysext/backend/Classes/Toolbar/ClearCacheToolbarItem.php
+++ b/typo3/sysext/backend/Classes/Toolbar/ClearCacheToolbarItem.php
@@ -64,34 +64,39 @@ class ClearCacheToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHoo
 		$this->backendReference = $backendReference;
 		$this->cacheActions = array();
 		$this->optionValues = array('all', 'pages');
+
+		// Clear all page-related caches
+		if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')) {
+			$this->cacheActions[] = array(
+				'id' => 'pages',
+				'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushPageCachesTitle', TRUE),
+				'description' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushPageCachesDescription', TRUE),
+				'href' => $this->backPath . 'tce_db.php?vC=' . $GLOBALS['BE_USER']->veriCode() . '&cacheCmd=pages&ajaxCall=1' . BackendUtility::getUrlToken('tceAction'),
+				'icon' => IconUtility::getSpriteIcon('actions-system-cache-clear-impact-low')
+			);
+		}
+
 		// Clear cache for ALL tables!
 		if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.all')) {
-			$title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.clearCacheMenu_all', TRUE);
 			$this->cacheActions[] = array(
 				'id' => 'all',
-				'title' => $title,
+				'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushAllCachesTitle', TRUE),
+				'description' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushAllCachesDescription', TRUE),
 				'href' => $this->backPath . 'tce_db.php?vC=' . $GLOBALS['BE_USER']->veriCode() . '&cacheCmd=all&ajaxCall=1' . BackendUtility::getUrlToken('tceAction'),
-				'icon' => IconUtility::getSpriteIcon('actions-system-cache-clear-impact-high')
-			);
-		}
-		// Clear cache for either ALL pages
-		if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.pages')) {
-			$title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.clearCacheMenu_pages', TRUE);
-			$this->cacheActions[] = array(
-				'id' => 'pages',
-				'title' => $title,
-				'href' => $this->backPath . 'tce_db.php?vC=' . $GLOBALS['BE_USER']->veriCode() . '&cacheCmd=pages&ajaxCall=1' . BackendUtility::getUrlToken('tceAction'),
 				'icon' => IconUtility::getSpriteIcon('actions-system-cache-clear-impact-medium')
 			);
 		}
-		// Clearing of cache-files in typo3conf/ + menu
-		if ($GLOBALS['BE_USER']->isAdmin()) {
-			$title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.clearCacheMenu_allTypo3Conf', TRUE);
+
+		// Clearing of system cache (core cache, class cache etc)
+		// is only shown explicitly if activated for a BE-user (not activated for admins by default)
+		// or if the system runs in development mode
+		if ($GLOBALS['BE_USER']->getTSConfigVal('options.clearCache.system') || GeneralUtility::getApplicationContext()->isDevelopment()) {
 			$this->cacheActions[] = array(
-				'id' => 'temp_CACHED',
-				'title' => $title,
-				'href' => $this->backPath . 'tce_db.php?vC=' . $GLOBALS['BE_USER']->veriCode() . '&cacheCmd=temp_CACHED&ajaxCall=1' . BackendUtility::getUrlToken('tceAction'),
-				'icon' => IconUtility::getSpriteIcon('actions-system-cache-clear-impact-low')
+				'id' => 'system',
+				'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushSystemCachesTitle', TRUE),
+				'description' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:flushSystemCachesDescription', TRUE),
+				'href' => $this->backPath . 'tce_db.php?vC=' . $GLOBALS['BE_USER']->veriCode() . '&cacheCmd=system&ajaxCall=1' . BackendUtility::getUrlToken('tceAction'),
+				'icon' => IconUtility::getSpriteIcon('actions-system-cache-clear-impact-high')
 			);
 		}
 		// Hook for manipulate cacheActions
@@ -137,7 +142,7 @@ class ClearCacheToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHoo
 		$cacheMenu[] = '<a href="#" class="toolbar-item">' . IconUtility::getSpriteIcon('apps-toolbar-menu-cache', array('title' => $title)) . '</a>';
 		$cacheMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
 		foreach ($this->cacheActions as $actionKey => $cacheAction) {
-			$cacheMenu[] = '<li><a href="' . htmlspecialchars($cacheAction['href']) . '">' . $cacheAction['icon'] . ' ' . $cacheAction['title'] . '</a></li>';
+			$cacheMenu[] = '<li><a href="' . htmlspecialchars($cacheAction['href']) . '" title="' . htmlspecialchars($cacheAction['description'] ?: $cacheAction['title']) . '">' . $cacheAction['icon'] . ' ' . htmlspecialchars($cacheAction['title']) . '</a></li>';
 		}
 		$cacheMenu[] = '</ul>';
 		return implode(LF, $cacheMenu);
diff --git a/typo3/sysext/lang/locallang_core.xlf b/typo3/sysext/lang/locallang_core.xlf
index 2e4d145cad62..23d886902a0b 100644
--- a/typo3/sysext/lang/locallang_core.xlf
+++ b/typo3/sysext/lang/locallang_core.xlf
@@ -672,6 +672,27 @@ Would you like to save now in order to refresh the display?</source>
 			<trans-unit id="rm.clearCacheMenu_allTypo3Conf" xml:space="preserve">
 				<source>Clear configuration cache</source>
 			</trans-unit>
+			<trans-unit id="rm.clearCacheMenu_pages" xml:space="preserve">
+				<source>Clear page content cache</source>
+			</trans-unit>
+			<trans-unit id="flushPageCachesTitle" xml:space="preserve">
+				<source>Flush frontend caches</source>
+			</trans-unit>
+			<trans-unit id="flushPageCachesDescription" xml:space="preserve">
+				<source>Clear frontend and page-related caches.</source>
+			</trans-unit>
+			<trans-unit id="flushAllCachesTitle" xml:space="preserve">
+				<source>Flush all caches</source>
+			</trans-unit>
+			<trans-unit id="flushAllCachesDescription" xml:space="preserve">
+				<source>Clear all caches, including frontend caches, and extension-specific caches. Compile-time caches / system caches that are needed for TYPO3 to run are not touched.</source>
+			</trans-unit>
+			<trans-unit id="flushSystemCachesTitle" xml:space="preserve">
+				<source>Flush system caches</source>
+			</trans-unit>
+			<trans-unit id="flushSystemCachesDescription" xml:space="preserve">
+				<source>Clears all system-related caches. This includes the class loader cache, the cache of all extension configuration files. Rebuilding this cache may take some time.</source>
+			</trans-unit>
 			<trans-unit id="rm.adminFunctions" xml:space="preserve">
 				<source>Admin functions</source>
 			</trans-unit>
-- 
GitLab