From 211c3a7b529cc935bd264c33c1e2ed95ecc64012 Mon Sep 17 00:00:00 2001
From: Christian Kuhn <lolli@schwarzbu.ch>
Date: Thu, 21 Apr 2016 14:13:07 +0200
Subject: [PATCH] [BUGFIX] Clear cache inconsistency in toolbar

With the simplification of the clear cache items in
toolbar the clearCacheSystem TYPO3_CONF_VARS was
rendered obsolete.
The patch removes last occurences in toolbar and
simplifies the visibility restrictions again: The
clear all toolbar item is now shown if user is admin
and the TSconfig option is not explictly disabling
the option for an admin, or a non-admin has the
TSconfig options.clearCache.all set to 1.

Change-Id: I5608baf2d4fe0c21dcc38f09fc17e550fcbfe8ff
Resolves: #75844
Releases: master
Reviewed-on: https://review.typo3.org/47835
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../Backend/ToolbarItems/ClearCacheToolbarItem.php | 14 +++++---------
 .../core/Classes/DataHandling/DataHandler.php      | 11 ++++++-----
 .../core/Configuration/DefaultConfiguration.php    |  8 ++++----
 ...cation-75625-DeprecatedCacheClearingOptions.rst |  2 +-
 4 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php b/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php
index 24da0fab5a02..cc0afd75719e 100644
--- a/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php
+++ b/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php
@@ -67,16 +67,12 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
             $this->optionValues[] = 'pages';
         }
 
-        // 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 (only for admins)
-        // or if $GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] is set (only for admins)
-        if ($backendUser->getTSConfigVal('options.clearCache.all')
-            || (GeneralUtility::getApplicationContext()->isDevelopment() && $backendUser->isAdmin())
-            || ((bool)$GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] === true && $backendUser->isAdmin())
-        ) {
+        // Clearing of all caches is only shown if explicitly enabled via TSConfig
+        // or if BE-User is admin and the TSconfig explicitly disables the possibility for admins.
+        // This is useful for big production systems where admins accidentally could slow down the system.
+        if ($backendUser->getTSConfigVal('options.clearCache.all') || ($backendUser->isAdmin() && $backendUser->getTSConfigVal('options.clearCache.all') !== '0')) {
             $this->cacheActions[] = array(
-                'id' => 'system',
+                'id' => 'all',
                 'title' => htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushAllCachesTitle2')),
                 'description' => htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushAllCachesDescription2')),
                 'href' => BackendUtility::getModuleUrl('tce_db', ['vC' => $backendUser->veriCode(), 'cacheCmd' => 'all']),
diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
index ccba87fbe2cb..b811a968b0c7 100644
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -7812,7 +7812,10 @@ class DataHandler
                 }
                 break;
             case 'all':
-                if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) {
+                // allow to clear all caches if the TS config option is enabled or the option is not explicitly
+                // disabled for admins (which could clear all caches by default). The latter option is useful
+                // for big production sites where it should be possible to restrict the cache clearing for some admins.
+                if ($this->BE_USER->getTSConfigVal('options.clearCache.all') || ($this->admin && $this->BE_USER->getTSConfigVal('options.clearCache.all') !== '0')) {
                     $this->getCacheManager()->flushCaches();
                     GeneralUtility::makeInstance(ConnectionPool::class)
                         ->getConnectionForTable('cache_treelist')
@@ -7826,11 +7829,9 @@ class DataHandler
             case 'system':
                 GeneralUtility::deprecationLog(
                     'Calling clear_cacheCmd() with arguments \'temp_cached\' or \'system\', using'
-                    . ' the ts config option \'options.clearCache.system\' or using'
-                    . '\'$GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'clearCacheSystem\'] has been deprecated.'
+                    . ' the TS config option \'options.clearCache.system\' has been deprecated.'
                 );
-                if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.system')
-                    || ((bool)$GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] === true && $this->admin)) {
+                if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.system')) {
                     $this->getCacheManager()->flushCachesInGroup('system');
                 }
                 break;
diff --git a/typo3/sysext/core/Configuration/DefaultConfiguration.php b/typo3/sysext/core/Configuration/DefaultConfiguration.php
index e723eda17541..ea2057fce99f 100644
--- a/typo3/sysext/core/Configuration/DefaultConfiguration.php
+++ b/typo3/sysext/core/Configuration/DefaultConfiguration.php
@@ -104,7 +104,7 @@ return array(
                     'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
                     'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class,
                     'options' => array(),
-                    'groups' => array('pages', 'all')
+                    'groups' => array('pages')
                 ),
                 'cache_pages' => array(
                     'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
@@ -112,7 +112,7 @@ return array(
                     'options' => array(
                         'compression' => true
                     ),
-                    'groups' => array('pages', 'all')
+                    'groups' => array('pages')
                 ),
                 'cache_pagesection' => array(
                     'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
@@ -121,7 +121,7 @@ return array(
                         'compression' => true,
                         'defaultLifetime' => 2592000, // 30 days; set this to a lower value in case your cache gets too big
                     ),
-                    'groups' => array('pages', 'all')
+                    'groups' => array('pages')
                 ),
                 'cache_phpcode' => array(
                     'frontend' => \TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class,
@@ -143,7 +143,7 @@ return array(
                     'options' => array(
                         'defaultLifetime' => 2592000, // 30 days; set this to a lower value in case your cache gets too big
                     ),
-                    'groups' => array('pages', 'all')
+                    'groups' => array('pages')
                 ),
                 'cache_imagesizes' => array(
                     'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75625-DeprecatedCacheClearingOptions.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75625-DeprecatedCacheClearingOptions.rst
index 4738673f285b..60df0ffcefa4 100644
--- a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75625-DeprecatedCacheClearingOptions.rst
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75625-DeprecatedCacheClearingOptions.rst
@@ -9,7 +9,7 @@ The following commands have been deprecated and should not be used anymore:
 
 * Method :php:`DataHandler->clear_cacheCmd()` with arguments `system` and `temp_cached`
 * ``userTSconfig`` setting ``options.clearCache.system``
-* Option ``$TYPO3_CONF_VARS['SYS']['clearCacheSystem']``
+* Option ``$TYPO3_CONF_VARS['SYS']['clearCacheSystem']`` has been removed
 
 
 Impact
-- 
GitLab