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\PageTag; |
29
|
|
|
use Aoe\Varnish\Domain\Model\Tag\PageIdTag; |
30
|
|
|
use Aoe\Varnish\System\Varnish; |
31
|
|
|
use TYPO3\CMS\Core\DataHandling\DataHandler; |
32
|
|
|
|
33
|
|
|
class TceMainHook extends AbstractHook |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @param array $parameters |
37
|
|
|
* @param DataHandler $parent |
38
|
|
|
* |
39
|
|
|
* @todo implement cache clearing for "clearCache_pageGrandParent", "clearCache_pageSiblingChildren" and |
40
|
|
|
* and "clearCache_disable" http://docs.typo3.org/typo3cms/TSconfigReference/PageTsconfig/TCEmain/Index.html |
41
|
|
|
* @todo find a way how to clear all affected pages after changeing a page title in the main menu or footer |
42
|
|
|
* because it is not possible through the existings hooks to access the correct page tags which needs be cleared from cache |
43
|
|
|
*/ |
44
|
12 |
|
public function clearCachePostProc(array $parameters, DataHandler $parent) |
45
|
|
|
{ |
46
|
12 |
|
if ($this->isBackendUserInWorkspace($parent)) { |
47
|
1 |
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** @var Varnish $varnish */ |
51
|
11 |
|
$varnish = $this->objectManager->get(Varnish::class); |
52
|
|
|
|
53
|
|
|
// delete all Typo3 pages |
54
|
11 |
|
if (isset($parameters['cacheCmd']) && $parameters['cacheCmd'] === 'pages') { |
55
|
1 |
|
$pageTag = new PageTag('typo3_page'); |
|
|
|
|
56
|
1 |
|
$varnish->banByTag($pageTag); |
57
|
|
|
} else { |
58
|
10 |
|
$pageId = $this->extractPageIdFromParameters($parameters); |
59
|
10 |
|
if ($pageId > 0) { |
60
|
3 |
|
$pageIdTag = new PageIdTag($pageId); |
61
|
3 |
|
$varnish->banByTag($pageIdTag); |
62
|
|
|
} |
63
|
|
|
} |
64
|
11 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* extract page id from all variants of parameters that can be given |
68
|
|
|
* |
69
|
|
|
* @param array $parameters |
70
|
|
|
* @return integer |
71
|
|
|
*/ |
72
|
10 |
|
private function extractPageIdFromParameters(array $parameters) |
73
|
|
|
{ |
74
|
10 |
|
if (isset($parameters['table']) && $parameters['table'] === 'pages' |
75
|
10 |
|
&& isset($parameters['uid']) && is_numeric($parameters['uid']) |
76
|
|
|
) { |
77
|
3 |
|
return (integer)$parameters['uid']; |
78
|
|
|
} |
79
|
7 |
|
if (isset($parameters['cacheCmd']) && is_numeric($parameters['cacheCmd'])) { |
80
|
3 |
|
return (integer)$parameters['cacheCmd']; |
81
|
|
|
} |
82
|
4 |
|
if (isset($parameters['uid_page']) && is_numeric($parameters['uid_page'])) { |
83
|
3 |
|
return (integer)$parameters['uid_page']; |
84
|
|
|
} |
85
|
1 |
|
return 0; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param DataHandler $parent |
90
|
|
|
* @return boolean |
91
|
|
|
*/ |
92
|
12 |
|
private function isBackendUserInWorkspace(DataHandler $parent) |
93
|
|
|
{ |
94
|
12 |
|
if ($parent->BE_USER->workspace > 0) { |
95
|
1 |
|
return true; |
96
|
|
|
} |
97
|
11 |
|
return false; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.