1
|
|
|
<?php |
2
|
|
|
namespace Etobi\CoreAPI\Command; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2012 Georg Ringer <[email protected]> |
8
|
|
|
* (c) 2014 Stefano Kowalke <[email protected]> |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* API Command Controller |
31
|
|
|
* |
32
|
|
|
* @author Georg Ringer <[email protected]> |
33
|
|
|
* @author Stefano Kowalke <[email protected]> |
34
|
|
|
* @package Etobi\CoreAPI\Service\SiteApiService |
35
|
|
|
*/ |
36
|
|
|
class CacheApiCommandController extends CommandController { |
37
|
|
|
/** |
38
|
|
|
* @var \TYPO3\CMS\Core\Log\LogManager $logManager |
39
|
|
|
*/ |
40
|
|
|
protected $logManager; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var \TYPO3\CMS\Core\Log\Logger $logger |
44
|
|
|
*/ |
45
|
|
|
protected $logger; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param \TYPO3\CMS\Core\Log\LogManager $logManager |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function injectLogManager(\TYPO3\CMS\Core\Log\LogManager $logManager) { |
53
|
|
|
$this->logManager = $logManager; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Initialize the object |
58
|
|
|
*/ |
59
|
|
|
public function initializeObject() { |
60
|
|
|
$this->logger = $this->objectManager->get('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var \Etobi\CoreAPI\Service\CacheApiService |
65
|
|
|
*/ |
66
|
|
|
protected $cacheApiService; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Inject the CacheApiService |
70
|
|
|
* |
71
|
|
|
* @param \Etobi\CoreAPI\Service\CacheApiService $cacheApiService |
72
|
|
|
*/ |
73
|
|
|
public function injectCacheApiService(\Etobi\CoreAPI\Service\CacheApiService $cacheApiService) { |
74
|
|
|
$this->cacheApiService = $cacheApiService; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Clear all caches. |
79
|
|
|
* If hard, cache will be cleared in a more straightforward approach and the according backend hooks are not executed. |
80
|
|
|
* |
81
|
|
|
* @param boolean $hard |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
public function clearAllCachesCommand($hard = false) { |
85
|
|
|
$this->cacheApiService->clearAllCaches($hard); |
86
|
|
|
$message = 'All caches have been cleared%s.'; |
87
|
|
|
$this->logger->info($message); |
88
|
|
|
$this->outputLine($message, $hard ? array(' hard') : array('')); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Clear system cache. |
93
|
|
|
* |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
public function clearSystemCacheCommand() { |
97
|
|
|
$this->cacheApiService->clearSystemCache(); |
98
|
|
|
$message = 'System cache has been cleared'; |
99
|
|
|
$this->logger->info($message); |
100
|
|
|
$this->outputLine($message); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Clears the opcode cache. |
105
|
|
|
* |
106
|
|
|
* @param string|NULL $fileAbsPath The file as absolute path to be cleared |
107
|
|
|
* or NULL to clear completely. |
108
|
|
|
* |
109
|
|
|
* @return void |
110
|
|
|
*/ |
111
|
|
|
public function clearAllActiveOpcodeCacheCommand($fileAbsPath = NULL) { |
112
|
|
|
$this->cacheApiService->clearAllActiveOpcodeCache($fileAbsPath); |
113
|
|
|
|
114
|
|
View Code Duplication |
if ($fileAbsPath !== NULL) { |
|
|
|
|
115
|
|
|
$message = sprintf('The opcode cache for the file %s has been cleared', $fileAbsPath); |
116
|
|
|
$this->outputLine($message); |
117
|
|
|
$this->logger->info($message); |
118
|
|
|
} else { |
119
|
|
|
$message = 'The complete opcode cache has been cleared'; |
120
|
|
|
$this->outputLine($message); |
121
|
|
|
$this->logger->info($message); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Clear configuration cache (temp_CACHED_..). |
127
|
|
|
* |
128
|
|
|
* @return void |
129
|
|
|
*/ |
130
|
|
|
public function clearConfigurationCacheCommand() { |
131
|
|
|
$this->cacheApiService->clearConfigurationCache(); |
132
|
|
|
$message = 'Configuration cache has been cleared.'; |
133
|
|
|
$this->logger->info($message); |
134
|
|
|
$this->outputLine($message); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Clear page cache. |
139
|
|
|
* |
140
|
|
|
* @return void |
141
|
|
|
*/ |
142
|
|
|
public function clearPageCacheCommand() { |
143
|
|
|
$this->cacheApiService->clearPageCache(); |
144
|
|
|
$message = 'Page cache has been cleared.'; |
145
|
|
|
$this->logger->info($message); |
146
|
|
|
$this->outputLine($message); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Clear all caches except the page cache. |
151
|
|
|
* This is especially useful on big sites when you can't just drop the page cache. |
152
|
|
|
* |
153
|
|
|
* @return void |
154
|
|
|
*/ |
155
|
|
|
public function clearAllExceptPageCacheCommand() { |
156
|
|
|
$clearedCaches = $this->cacheApiService->clearAllExceptPageCache(); |
157
|
|
|
$message = 'Cleared caches: ' . implode(', ', $clearedCaches); |
158
|
|
|
$this->logger->info($message); |
159
|
|
|
$this->outputLine($message); |
160
|
|
|
} |
161
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.