|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* Copyright (C) |
|
6
|
|
|
* Nathan Boiron <[email protected]> |
|
7
|
|
|
* Romain Canon <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of the TYPO3 NotiZ project. |
|
10
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
11
|
|
|
* under the terms of the GNU General Public License, either |
|
12
|
|
|
* version 3 of the License, or any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, see: |
|
15
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace CuyZ\Notiz\Domain\Event\TYPO3; |
|
19
|
|
|
|
|
20
|
|
|
use CuyZ\Notiz\Core\Event\AbstractEvent; |
|
21
|
|
|
use CuyZ\Notiz\Core\Event\Exception\CancelEventDispatch; |
|
22
|
|
|
use CuyZ\Notiz\Core\Event\Support\ProvidesExampleProperties; |
|
23
|
|
|
use TYPO3\CMS\Core\DataHandling\DataHandler; |
|
24
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
25
|
|
|
use TYPO3\CMS\Core\Utility\RootlineUtility; |
|
26
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
final class RecordCreatedEvent extends AbstractEvent implements ProvidesExampleProperties |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @label Event/TYPO3:record_created.marker.status |
|
32
|
|
|
* @marker |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $status; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @label Event/TYPO3:record_created.marker.table |
|
40
|
|
|
* @marker |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $table; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @label Event/TYPO3:record_created.marker.uid |
|
48
|
|
|
* @marker |
|
49
|
|
|
* |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $uid; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @label Event/TYPO3:record_created.marker.record |
|
56
|
|
|
* @marker |
|
57
|
|
|
* |
|
58
|
|
|
* @var array |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $record; |
|
61
|
|
|
|
|
62
|
|
|
public function run($status, $table, $recordId, array $updatedFields, DataHandler $dataHandler) |
|
63
|
|
|
{ |
|
64
|
|
|
if ($table !== $this->configuration['table']) { |
|
65
|
|
|
$this->cancelDispatch(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$this->checkStatus($status); |
|
69
|
|
|
|
|
70
|
|
|
$this->uid = $this->findUid($recordId, $table, $status, $dataHandler); |
|
71
|
|
|
$this->record = $dataHandler->recordInfo($table, $this->uid, '*'); |
|
72
|
|
|
|
|
73
|
|
|
$actualCType = ''; |
|
74
|
|
|
|
|
75
|
|
|
if (isset($updatedFields['CType']) && is_string($updatedFields['CType'])) { |
|
76
|
|
|
$actualCType = $updatedFields['CType']; |
|
77
|
|
|
} elseif (isset($this->record['CType']) && is_string($this->record['CType'])) { |
|
78
|
|
|
$actualCType = $this->record['CType']; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if ($table === 'tt_content' |
|
82
|
|
|
&& !empty($this->configuration['ctype']) |
|
83
|
|
|
&& !preg_match($this->configuration['ctype'], $actualCType) |
|
84
|
|
|
) { |
|
85
|
|
|
$this->cancelDispatch(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$this->checkPid(); |
|
89
|
|
|
|
|
90
|
|
|
$this->status = $status; |
|
91
|
|
|
$this->table = $table; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getExampleProperties(): array |
|
95
|
|
|
{ |
|
96
|
|
|
return [ |
|
97
|
|
|
'status' => 'new', |
|
98
|
|
|
'table' => $this->configuration['table'], |
|
99
|
|
|
'uid' => 1337, |
|
100
|
|
|
'record' => [ |
|
101
|
|
|
'uid' => 1337, |
|
102
|
|
|
'pid' => 42, |
|
103
|
|
|
'starttime' => 1612014706, |
|
104
|
|
|
], |
|
105
|
|
|
]; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
private function findUid($id, $table, $status, DataHandler $dataHandler) |
|
109
|
|
|
{ |
|
110
|
|
|
$uid = $id; |
|
111
|
|
|
|
|
112
|
|
|
if ($status === 'new') { |
|
113
|
|
|
if (!$dataHandler->substNEWwithIDs[$id]) { |
|
114
|
|
|
//postProcessFieldArray |
|
115
|
|
|
$uid = 0; |
|
116
|
|
|
} else { |
|
117
|
|
|
//afterDatabaseOperations |
|
118
|
|
|
$uid = $dataHandler->substNEWwithIDs[$id]; |
|
119
|
|
|
if (isset($dataHandler->autoVersionIdMap[$table][$uid])) { |
|
120
|
|
|
$uid = $dataHandler->autoVersionIdMap[$table][$uid]; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return (int)$uid; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param string $status Either "new" or "update" |
|
130
|
|
|
* @throws CancelEventDispatch |
|
131
|
|
|
*/ |
|
132
|
|
|
private function checkStatus($status) |
|
133
|
|
|
{ |
|
134
|
|
|
if (!isset($this->configuration['statuses']) |
|
135
|
|
|
|| !is_string($this->configuration['statuses']) |
|
136
|
|
|
) { |
|
137
|
|
|
return; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
if (strlen($this->configuration['statuses']) === 0) { |
|
141
|
|
|
return; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
$statuses = explode(',', $this->configuration['statuses']); |
|
145
|
|
|
|
|
146
|
|
|
if (empty($statuses)) { |
|
147
|
|
|
return; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
if (!in_array($status, $statuses)) { |
|
151
|
|
|
$this->cancelDispatch(); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
private function checkPid() |
|
156
|
|
|
{ |
|
157
|
|
|
if (!isset($this->configuration['pids'])) { |
|
158
|
|
|
return; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
if (!is_string($this->configuration['pids'])) { |
|
162
|
|
|
return; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
$authorizedPids = explode(',', $this->configuration['pids']); |
|
166
|
|
|
|
|
167
|
|
|
$currentPid = (int)$this->record['pid']; |
|
168
|
|
|
|
|
169
|
|
|
if ($currentPid === 0) { |
|
170
|
|
|
if (count($authorizedPids) === 0) { |
|
171
|
|
|
return; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
if (in_array($currentPid, $authorizedPids)) { |
|
175
|
|
|
return; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
$this->cancelDispatch(); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** @var ObjectManager $objectManager */ |
|
182
|
|
|
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
|
183
|
|
|
|
|
184
|
|
|
/** @var RootlineUtility $rootlineUtility */ |
|
185
|
|
|
$rootlineUtility = $objectManager->get(RootlineUtility::class, $currentPid); |
|
186
|
|
|
|
|
187
|
|
|
$rootline = array_map(function ($page) { |
|
188
|
|
|
return $page['pid']; |
|
189
|
|
|
}, $rootlineUtility->get()); |
|
190
|
|
|
|
|
191
|
|
|
$rootline[] = $currentPid; |
|
192
|
|
|
|
|
193
|
|
|
foreach ($rootline as $rootlinePid) { |
|
194
|
|
|
if (in_array($rootlinePid, $authorizedPids)) { |
|
195
|
|
|
return; |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
$this->cancelDispatch(); |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths