|
1
|
|
|
<?php |
|
2
|
|
|
namespace Aoe\Varnish\TYPO3\Hooks; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2018 AOE GmbH <[email protected]> |
|
8
|
|
|
* |
|
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 3 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
|
|
|
|
|
28
|
|
|
use Aoe\Varnish\Domain\Model\Tag\PageIdTag; |
|
29
|
|
|
use Aoe\Varnish\System\Varnish; |
|
30
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
|
31
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
|
32
|
|
|
|
|
33
|
|
|
class CrawlerHook extends AbstractHook |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* (Hook-function called from TypoScriptFrontend, see ext_localconf.php for configuration). |
|
37
|
|
|
* |
|
38
|
|
|
* @param array $parameters Parameters delivered by TypoScriptFrontend |
|
39
|
|
|
* @param TypoScriptFrontendController $parentObject The calling parent object (TypoScriptFrontend) |
|
40
|
|
|
*/ |
|
41
|
3 |
|
public function clearVarnishCache(array $parameters, TypoScriptFrontendController $parentObject) |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
3 |
|
if ($this->isCrawlerExtensionLoaded() && $this->isCrawlerRunning($parentObject)) { |
|
44
|
1 |
|
$this->clearPageCacheInVarnish($parentObject->id); |
|
45
|
1 |
|
} |
|
46
|
3 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return boolean |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function isCrawlerExtensionLoaded() |
|
52
|
|
|
{ |
|
53
|
|
|
return ExtensionManagementUtility::isLoaded('crawler'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param integer $pageId |
|
58
|
|
|
*/ |
|
59
|
1 |
|
private function clearPageCacheInVarnish($pageId) |
|
60
|
|
|
{ |
|
61
|
1 |
|
$pageIdTag = new PageIdTag($pageId); |
|
62
|
|
|
|
|
63
|
|
|
/** @var Varnish $varnish */ |
|
64
|
1 |
|
$varnish = $this->objectManager->get(Varnish::class); |
|
65
|
1 |
|
$varnish->banByTag($pageIdTag); |
|
66
|
1 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param TypoScriptFrontendController $tsfe |
|
70
|
|
|
* @return boolean |
|
71
|
|
|
*/ |
|
72
|
2 |
|
private function isCrawlerRunning(TypoScriptFrontendController $tsfe) { |
|
73
|
2 |
|
if ($tsfe->applicationData['tx_crawler']['running']) { |
|
74
|
1 |
|
return true; |
|
75
|
|
|
} |
|
76
|
1 |
|
return false; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.