[FEATURE] Add complete opcode cache reset 20/28520/6
authorAlexander Opitz <opitz.alexander@googlemail.com>
Wed, 19 Mar 2014 10:22:38 +0000 (11:22 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Mon, 24 Mar 2014 15:33:06 +0000 (16:33 +0100)
This adds the possibility to reset the complete opcode cache in the
install tool. This functionality may be needed if you update extensions
not via EM and the cache does not stat the files.

Resolves: #56987
Releases: 6.2
Change-Id: I540a31a939fdc6305ad0aff9d39f7e424404925d
Reviewed-on: https://review.typo3.org/28520
Reviewed-by: Stefan Neufeind
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/Utility/OpcodeCacheUtility.php
typo3/sysext/install/Classes/Controller/Action/Tool/ImportantActions.php
typo3/sysext/install/Resources/Private/Partials/Action/Tool/ImportantActions/ClearOpcodeCache.html [new file with mode: 0644]
typo3/sysext/install/Resources/Private/Templates/Action/Tool/ImportantActions.html

index af78c5d..9d4860e 100644 (file)
@@ -68,7 +68,7 @@ class OpcodeCacheUtility {
                                'canInvalidate' => function_exists('opcache_invalidate'),
                                'error' => FALSE,
                                'clearCallback' => function ($fileAbsPath) {
-                                       if (function_exists('opcache_invalidate')) {
+                                       if ($fileAbsPath !== NULL && function_exists('opcache_invalidate')) {
                                                opcache_invalidate($fileAbsPath);
                                        } else {
                                                opcache_reset();
@@ -89,7 +89,7 @@ class OpcodeCacheUtility {
                                // Versions lower then 3.1.7 are known as malfunction
                                'error' => $apcVersion && VersionNumberUtility::convertVersionNumberToInteger($apcVersion) < 3001007,
                                'clearCallback' => function ($fileAbsPath) {
-                                       if (OpcodeCacheUtility::getCanInvalidate('APC')) {
+                                       if ($fileAbsPath !== NULL && OpcodeCacheUtility::getCanInvalidate('APC')) {
                                                // This may output a warning like: PHP Warning: apc_delete_file(): Could not stat file
                                                // This warning isn't true, this means that apc was unable to generate the cache key
                                                // which depends on the configuration of APC.
@@ -108,7 +108,12 @@ class OpcodeCacheUtility {
                                'canInvalidate' => TRUE, // wincache_refresh_if_changed()
                                'error' => FALSE,
                                'clearCallback' => function ($fileAbsPath) {
-                                       wincache_refresh_if_changed(array($fileAbsPath));
+                                       if ($fileAbsPath !== NULL) {
+                                               wincache_refresh_if_changed(array($fileAbsPath));
+                                       } else {
+                                               // No argument means refreshing all.
+                                               wincache_refresh_if_changed();
+                                       }
                                }
                        ),
 
@@ -182,11 +187,11 @@ class OpcodeCacheUtility {
        /**
         * Clears a file from an opcache, if one exists.
         *
-        * @param string $fileAbsPath The file as absolute path to be cleared.
+        * @param string|NULL $fileAbsPath The file as absolute path to be cleared or NULL to clear completely.
         *
         * @return void
         */
-       static public function clearAllActive($fileAbsPath) {
+       static public function clearAllActive($fileAbsPath = NULL) {
                foreach (static::getAllActive() as $properties) {
                        $callback = $properties['clearCallback'];
                        $callback($fileAbsPath);
index 55aa710..2cafae6 100644 (file)
@@ -26,6 +26,7 @@ namespace TYPO3\CMS\Install\Controller\Action\Tool;
 
 use TYPO3\CMS\Install\Controller\Action;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\OpcodeCacheUtility;
 
 /**
  * Handle important actions
@@ -55,6 +56,9 @@ class ImportantActions extends Action\AbstractAction {
                if (isset($this->postValues['set']['clearAllCache'])) {
                        $actionMessages[] = $this->clearAllCache();
                }
+               if (isset($this->postValues['set']['clearOpcodeCache'])) {
+                       $actionMessages[] = $this->clearOpcodeCache();
+               }
 
                // Database analyzer handling
                if (isset($this->postValues['set']['databaseAnalyzerExecute'])
@@ -89,7 +93,8 @@ class ImportantActions extends Action\AbstractAction {
                        ->assign('databaseSocket', $GLOBALS['TYPO3_CONF_VARS']['DB']['socket'])
                        ->assign('databaseNumberOfTables', count($this->getDatabaseConnection()->admin_get_tables()))
                        ->assign('extensionCompatibilityTesterProtocolFile', GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'typo3temp/ExtensionCompatibilityTester.txt')
-                       ->assign('extensionCompatibilityTesterErrorProtocolFile', GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'typo3temp/ExtensionCompatibilityTesterErrors.json');
+                       ->assign('extensionCompatibilityTesterErrorProtocolFile', GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'typo3temp/ExtensionCompatibilityTesterErrors.json')
+                       ->assign('listOfOpcodeCaches', OpcodeCacheUtility::getAllActive());
 
                return $this->view->render();
        }
@@ -164,6 +169,19 @@ class ImportantActions extends Action\AbstractAction {
        }
 
        /**
+        * Clear PHP opcode cache
+        *
+        * @return \TYPO3\CMS\Install\Status\StatusInterface
+        */
+       protected function clearOpcodeCache() {
+               /** @var \TYPO3\CMS\Install\Service\ClearCacheService $clearCacheService */
+               OpcodeCacheUtility::clearAllActive();
+               $message = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\OkStatus');
+               $message->setTitle('Successfully cleared all available opcode caches');
+               return $message;
+       }
+
+       /**
         * Set new encryption key
         *
         * @return void
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
new file mode 100644 (file)
index 0000000..e5f098d
--- /dev/null
@@ -0,0 +1,22 @@
+<f:if condition="{listOfOpcodeCaches}">
+       <h4>Clear PHP opcode cache</h4>
+       <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 8f13e2a..3520b42 100644 (file)
@@ -25,6 +25,8 @@
        <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 />
 
@@ -42,4 +44,4 @@
 
        <f:render partial="Action/Tool/ImportantActions/CreateAdministrator" arguments="{_all}"/>
 
-</f:section>
\ No newline at end of file
+</f:section>