|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Controller of the CacheCheck Module |
|
4
|
|
|
* |
|
5
|
|
|
* @package CacheCheck\Controller |
|
6
|
|
|
* @author Julian Seitz |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace HDNET\CacheCheck\Controller; |
|
10
|
|
|
|
|
11
|
|
|
use HDNET\CacheCheck\Domain\Model\Cache; |
|
12
|
|
|
use TYPO3\CMS\Core\Cache\CacheManager; |
|
13
|
|
|
use TYPO3\CMS\Core\Database\DatabaseConnection; |
|
14
|
|
|
use TYPO3\CMS\Core\Messaging\AbstractMessage; |
|
15
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
16
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class CacheCheckController |
|
20
|
|
|
*/ |
|
21
|
|
|
class CacheCheckController extends ActionController |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Cache registry |
|
26
|
|
|
* |
|
27
|
|
|
* @var \HDNET\CacheCheck\Service\CacheRegistry |
|
28
|
|
|
* @inject |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $cacheRegistry; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Cache repository |
|
34
|
|
|
* |
|
35
|
|
|
* @var \HDNET\CacheCheck\Domain\Repository\CacheRepository |
|
36
|
|
|
* @inject |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $cacheRepository; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Assigns the given array to the view |
|
42
|
|
|
*/ |
|
43
|
|
|
public function listAction() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->view->assign('caches', $this->cacheRepository->findAll()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* action to start a cache analysis |
|
50
|
|
|
* |
|
51
|
|
|
* @param \HDNET\CacheCheck\Domain\Model\Cache $cache |
|
52
|
|
|
*/ |
|
53
|
|
|
public function startAction(Cache $cache) |
|
54
|
|
|
{ |
|
55
|
|
|
if (!$cache->getIsInAnalyseMode()) { |
|
56
|
|
|
$this->cacheRegistry->add($cache->getName()); |
|
57
|
|
|
$this->addFlashMessage('This cache "' . $cache->getName() . '" is now being analyzed'); |
|
58
|
|
|
} else { |
|
59
|
|
|
$this->addFlashMessage( |
|
60
|
|
|
'This cache "' . $cache->getName() . '" is already being analyzed', |
|
61
|
|
|
'', |
|
62
|
|
|
AbstractMessage::WARNING |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
$this->redirect('list'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Action to stop a cache analysis |
|
70
|
|
|
* |
|
71
|
|
|
* @param \HDNET\CacheCheck\Domain\Model\Cache $cache |
|
72
|
|
|
*/ |
|
73
|
|
|
public function stopAction(Cache $cache) |
|
74
|
|
|
{ |
|
75
|
|
|
if ($cache->getIsInAnalyseMode()) { |
|
76
|
|
|
$this->cacheRegistry->remove($cache->getName()); |
|
77
|
|
|
$this->addFlashMessage('This cache "' . $cache->getName() . '" is not being analyzed anymore.'); |
|
78
|
|
|
} else { |
|
79
|
|
|
$this->addFlashMessage( |
|
80
|
|
|
'This cache "' . $cache->getName() . '" is not being analyzed', |
|
81
|
|
|
'', |
|
82
|
|
|
AbstractMessage::WARNING |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
$this->redirect('list'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Action to stop a cache analysis |
|
90
|
|
|
* |
|
91
|
|
|
* @param \HDNET\CacheCheck\Domain\Model\Cache $cache |
|
92
|
|
|
*/ |
|
93
|
|
|
public function deleteAction(Cache $cache) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->getDatabaseConnection() |
|
96
|
|
|
->exec_DELETEquery('tx_cachecheck_domain_model_log', 'cache_name = "' . $cache->getName() . '"'); |
|
97
|
|
|
$this->addFlashMessage('This cache "' . $cache->getName() . '" information is removed from log'); |
|
98
|
|
|
$this->redirect('list'); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Flush the given cache |
|
103
|
|
|
* |
|
104
|
|
|
* @param \HDNET\CacheCheck\Domain\Model\Cache $cache |
|
105
|
|
|
*/ |
|
106
|
|
|
public function flushAction(Cache $cache) |
|
107
|
|
|
{ |
|
108
|
|
|
$cacheManager = GeneralUtility::makeInstance(CacheManager::class); |
|
109
|
|
|
$cacheObject = $cacheManager->getCache($cache->getName()); |
|
110
|
|
|
$cacheObject->flush(); |
|
111
|
|
|
$this->addFlashMessage('The cache "' . $cache->getName() . '" was flushed'); |
|
112
|
|
|
$this->redirect('list'); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Get database connection |
|
117
|
|
|
* |
|
118
|
|
|
* @return DatabaseConnection |
|
119
|
|
|
*/ |
|
120
|
|
|
protected function getDatabaseConnection() |
|
121
|
|
|
{ |
|
122
|
|
|
return $GLOBALS['TYPO3_DB']; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|