TYPO3 CMS  TYPO3_8-7
ClearAllCache.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
29 {
30 
34  protected $view;
35 
39  public function __construct(JsonView $view = null)
40  {
41  $this->view = $view ?: GeneralUtility::makeInstance(JsonView::class);
42  }
43 
48  protected function initializeHandle()
49  {
50  // empty on purpose because AbstractAjaxAction still overwrites $this->view with StandaloneView
51  }
52 
58  protected function executeAction()
59  {
60  $statusMessages[] = $this->clearAllCache();
61  $statusMessages[] = $this->clearOpcodeCache();
62 
63  $this->view->assignMultiple([
64  'success' => true,
65  'status' => $statusMessages,
66  ]);
67  return $this->view->render();
68  }
69 
75  protected function clearAllCache()
76  {
78  $clearCacheService = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\ClearCacheService::class);
79  $clearCacheService->clearAll();
80  $message = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\OkStatus::class);
81  $message->setTitle('Successfully cleared all caches');
82  return $message;
83  }
84 
90  protected function clearOpcodeCache()
91  {
92  GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive();
93  $message = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\OkStatus::class);
94  $message->setTitle('Successfully cleared all available opcode caches');
95  return $message;
96  }
97 }
static makeInstance($className,... $constructorArguments)