[FEATURE] Simplify cache clearing 80/47580/5
authorFrank Naegler <frank.naegler@typo3.org>
Mon, 11 Apr 2016 18:48:36 +0000 (20:48 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Wed, 13 Apr 2016 21:01:31 +0000 (23:01 +0200)
The cache clearing system has been simplified by removing options in
cache clear menu and install tool.

Resolves: #75581
Releases: master
Change-Id: Ia784efb13e443705b1be3326ba12107b885e8268
Reviewed-on: https://review.typo3.org/47580
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
Build/Resources/Public/Less/TYPO3/_topbar.less
typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php
typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ClearCacheMenu.js
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Documentation/Changelog/master/Feature-75581-SimplifyCacheClearing.rst [new file with mode: 0644]
typo3/sysext/install/Classes/Controller/Action/Tool/ImportantActions.php
typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/ClearAllCache.html
typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/ClearOpcodeCache.html [deleted file]
typo3/sysext/install/Resources/Private/Templates/Action/Tool/ImportantActions.html
typo3/sysext/lang/locallang_core.xlf
typo3/sysext/t3skin/Resources/Public/Css/backend.css

index 721a063..988f38d 100644 (file)
                        background-color: @brand-danger;
                        color: @btn-danger-color;
                }
+               small {
+                       white-space: normal;
+                       width: 270px;
+                       display: block;
+                       padding-left: 21px;
+               }
        }
        .dropdown-list-link-edit,
        .dropdown-list-link-delete,
index 43f089e..4faa057 100644 (file)
@@ -67,24 +67,11 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
             $this->optionValues[] = 'pages';
         }
 
-        // Clear cache for ALL tables!
-        if ($backendUser->isAdmin() || $backendUser->getTSConfigVal('options.clearCache.all')) {
-            $this->cacheActions[] = array(
-                'id' => 'all',
-                'title' => htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushGeneralCachesTitle')),
-                'description' => htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushGeneralCachesDescription')),
-                'href' => BackendUtility::getModuleUrl('tce_db', ['vC' => $backendUser->veriCode(), 'cacheCmd' => 'all']),
-                'icon' => $this->iconFactory->getIcon('actions-system-cache-clear-impact-medium', Icon::SIZE_SMALL)->render()
-            );
-            $this->optionValues[] = 'all';
-        }
-
         // 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.system')
+        if ($backendUser->getTSConfigVal('options.clearCache.all')
             || (GeneralUtility::getApplicationContext()->isDevelopment() && $backendUser->isAdmin())
             || ((bool)$GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] === true && $backendUser->isAdmin())
         ) {
@@ -92,10 +79,10 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
                 'id' => 'system',
                 'title' => htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushSystemCachesTitle')),
                 'description' => htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_core.xlf:flushSystemCachesDescription')),
-                'href' => BackendUtility::getModuleUrl('tce_db', ['vC' => $backendUser->veriCode(), 'cacheCmd' => 'system']),
+                'href' => BackendUtility::getModuleUrl('tce_db', ['vC' => $backendUser->veriCode(), 'cacheCmd' => 'all']),
                 'icon' => $this->iconFactory->getIcon('actions-system-cache-clear-impact-high', Icon::SIZE_SMALL)->render()
             );
-            $this->optionValues[] = 'system';
+            $this->optionValues[] = 'all';
         }
 
         // Hook for manipulating cacheActions
@@ -156,8 +143,9 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
         foreach ($this->cacheActions as $cacheAction) {
             $title = $cacheAction['description'] ?: $cacheAction['title'];
             $result[] = '<li>';
-            $result[] = '<a class="dropdown-list-link" href="' . htmlspecialchars($cacheAction['href']) . '" title="' . htmlspecialchars($title) . '">';
+            $result[] = '<a class="dropdown-list-link" href="' . htmlspecialchars($cacheAction['href']) . '">';
             $result[] = $cacheAction['icon'] . ' ' . htmlspecialchars($cacheAction['title']);
+            $result[] = '<br/><small>' . htmlspecialchars($title) . '</small>';
             $result[] = '</a>';
             $result[] = '</li>';
         }
index 5727541..8a4790e 100644 (file)
@@ -16,7 +16,7 @@
  * main functionality for clearing caches via the top bar
  * reloading the clear cache icon
  */
-define(['jquery', 'TYPO3/CMS/Backend/Icons'], function($, Icons) {
+define(['jquery', 'TYPO3/CMS/Backend/Icons', 'TYPO3/CMS/Backend/Notification'], function($, Icons, Notification) {
        'use strict';
 
        /**
@@ -67,8 +67,11 @@ define(['jquery', 'TYPO3/CMS/Backend/Icons'], function($, Icons) {
                        url: ajaxUrl,
                        type: 'post',
                        cache: false,
-                       complete: function() {
+                       complete: function(jqXHRObject, status) {
                                $(ClearCacheMenu.options.toolbarIconSelector, ClearCacheMenu.options.containerSelector).replaceWith($existingIcon);
+                               if (status !== 'success' || jqXHRObject.responseText !== '') {
+                                       Notification.error('An error occurs', 'An error occured while clearing the cache. It is likely not all caches were cleared as expected.', 0);
+                               }
                        }
                });
        };
index 3615219..d315f37 100644 (file)
@@ -27,14 +27,17 @@ use TYPO3\CMS\Core\Html\RteHtmlParser;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Messaging\FlashMessageService;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Service\OpcodeCacheService;
 use TYPO3\CMS\Core\Type\Bitmask\Permission;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\File\BasicFileUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
 use TYPO3\CMS\Core\Versioning\VersionState;
+use TYPO3\CMS\Install\Service\ClearCacheService;
 
 /**
  * The main data handler class which takes care of correctly updating and inserting records.
@@ -7803,7 +7806,6 @@ class DataHandler
         if (is_object($this->BE_USER)) {
             $this->BE_USER->writelog(3, 1, 0, 0, 'User %s has cleared the cache (cacheCmd=%s)', array($this->BE_USER->user['username'], $cacheCmd));
         }
-        // Clear cache for either ALL pages or ALL tables!
         switch (strtolower($cacheCmd)) {
             case 'pages':
                 if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.pages')) {
@@ -7812,11 +7814,13 @@ class DataHandler
                 break;
             case 'all':
                 if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) {
-                    // Clear cache group "all" of caching framework caches
-                    $this->getCacheManager()->flushCachesInGroup('all');
+                    // Delete typo3temp/var/Cache manually as quick, straight and brutal approach here
+                    GeneralUtility::flushDirectory(PATH_site . 'typo3temp/var/Cache', true, true);
+                    $this->getCacheManager()->flushCaches();
                     $this->databaseConnection->exec_TRUNCATEquery('cache_treelist');
+                    // Delete Opcode Cache
+                    GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive();
                 }
-
                 break;
             case 'temp_cached':
             case 'system':
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-75581-SimplifyCacheClearing.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-75581-SimplifyCacheClearing.rst
new file mode 100644 (file)
index 0000000..85f9167
--- /dev/null
@@ -0,0 +1,18 @@
+=========================================
+Feature: #75581 - Simplify cache clearing
+=========================================
+
+Description
+===========
+
+The cache clearing system has been simplified by removing options in cache clear menu and install tool.
+
+The cache clear menu in the backend contains now only two options:
+
+* Flush frontend caches
+  Clear frontend and page-related caches, like before.
+
+* Flush all caches
+  Clear all system-related caches, including the class loader, localization, extension configuration file caches and opcode caches. Rebuilding this cache may take some time.
+
+Within the install tool the "Clear all cache" button will clear now also the opcode caches if possible.
index 08e3645..38150e9 100644 (file)
@@ -48,8 +48,6 @@ class ImportantActions extends Action\AbstractAction
         }
         if (isset($this->postValues['set']['clearAllCache'])) {
             $actionMessages[] = $this->clearAllCache();
-        }
-        if (isset($this->postValues['set']['clearOpcodeCache'])) {
             $actionMessages[] = $this->clearOpcodeCache();
         }
 
index ad95b71..befbd29 100644 (file)
@@ -7,7 +7,22 @@
        This method can throw a fatal error if a broken extension is loaded. If you get a white page
        or a PHP error message, check your system with the broken extension test below.
 </p>
+<p>
+       This clears the complete opcode caches of the active opcode cache systems, if the system supports reset.
+</p>
+<p>Available PHP opcode cache systems</p>
+<ul>
+       <f:for each="{listOfOpcodeCaches}" as="opcodeCache" key="opcodeCacheName">
+               <li>{opcodeCacheName} ({opcodeCache.version}) -
+                       <f:if condition="{opcodeCache.canReset}">
+                               <f:then>reset is supported</f:then>
+                               <f:else>reset is not supported</f:else>
+                       </f:if>
+               </li>
+       </f:for>
+</ul>
+
 <form method="post">
        <f:render partial="Action/Common/HiddenFormFields" arguments="{_all}" />
-       <f:render partial="Action/Common/SubmitButton" arguments="{name:'clearAllCache', text:'Clear all cache'}"/>
+       <f:render partial="Action/Common/SubmitButton" arguments="{name:'clearAllCache', text:'Clear all caches including PHP opcode cache'}"/>
 </form>
diff --git a/typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/ClearOpcodeCache.html b/typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/ClearOpcodeCache.html
deleted file mode 100644 (file)
index d0ba283..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<f:if condition="{listOfOpcodeCaches}">
-       <h3>Clear PHP opcode cache</h3>
-       <p>
-               This clears the complete opcode caches of the active opcode cache systems, if the system supports reset.
-       </p>
-       <p>Available PHP opcode cache systems</p>
-       <ul>
-               <f:for each="{listOfOpcodeCaches}" as="opcodeCache" key="opcodeCacheName">
-                       <li>{opcodeCacheName} ({opcodeCache.version}) -
-                               <f:if condition="{opcodeCache.canReset}">
-                                       <f:then>reset is supported</f:then>
-                                       <f:else>reset is not supported</f:else>
-                               </f:if>
-                       </li>
-               </f:for>
-       </ul>
-       <form method="post">
-               <f:render partial="Action/Common/HiddenFormFields" arguments="{_all}" />
-               <f:render partial="Action/Common/SubmitButton" arguments="{name:'clearOpcodeCache', text:'Clear PHP opcode cache'}"/>
-       </form>
-       <hr />
-</f:if>
index 0304331..1be9d69 100644 (file)
@@ -25,8 +25,6 @@
        <f:render partial="Action/Tool/ImportantActions/ClearAllCache" arguments="{_all}"/>
        <hr />
 
-       <f:render partial="Action/Tool/ImportantActions/ClearOpcodeCache" arguments="{_all}"/>
-
        <f:render partial="Action/Tool/ImportantActions/ExtensionCompatibilityTester" arguments="{_all}"/>
        <hr />
 
index 9b49d5e..1a1650c 100644 (file)
@@ -876,10 +876,10 @@ Do you want to refresh it now?</source>
                                <source>Clear frontend and page-related caches, plus some backend-related caches.</source>
                        </trans-unit>
                        <trans-unit id="flushSystemCachesTitle">
-                               <source>Flush system caches</source>
+                               <source>Flush all caches</source>
                        </trans-unit>
                        <trans-unit id="flushSystemCachesDescription">
-                               <source>Clear all system-related caches, including the class loader, localization and extension configuration file caches. Rebuilding this cache may take some time. </source>
+                               <source>Clear all system-related caches, including the class loader, localization, extension configuration file caches and opcode caches. Rebuilding this cache may take some time.</source>
                        </trans-unit>
                        <trans-unit id="rm.adminFunctions">
                                <source>Admin functions</source>
index d22624d..96b90b2 100644 (file)
@@ -12578,6 +12578,12 @@ iframe {
   background-color: #c83c3c;
   color: #ffffff;
 }
+.typo3-topbar-navigation-items .dropdown-list-link small {
+  white-space: normal;
+  width: 270px;
+  display: block;
+  padding-left: 21px;
+}
 .typo3-topbar-navigation-items .dropdown-list-link-edit,
 .typo3-topbar-navigation-items .dropdown-list-link-delete,
 .typo3-topbar-navigation-items .dropdown-list-link-close {