1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\Events; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2021 Markus Friedrich <[email protected]> |
8
|
|
|
* All rights reserved |
9
|
|
|
* |
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
11
|
|
|
* free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* The GNU General Public License can be found at |
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
18
|
|
|
* |
19
|
|
|
* This script is distributed in the hope that it will be useful, |
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
|
|
|
* GNU General Public License for more details. |
23
|
|
|
* |
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
25
|
|
|
***************************************************************/ |
26
|
|
|
|
27
|
|
|
use Psr\EventDispatcher\StoppableEventInterface; |
28
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\DataUpdateHandler; |
29
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler\GarbageHandler; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Abstract data update event |
33
|
|
|
*/ |
34
|
|
|
abstract class AbstractDataUpdateEvent implements DataUpdateEventInterface, StoppableEventInterface |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Record uid |
38
|
|
|
* |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
protected $uid; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Record table |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
protected $table; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Updated record fields |
52
|
|
|
* |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
protected $fields = []; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Flag indicating that propagation is stopped |
59
|
|
|
* |
60
|
|
|
* @var bool |
61
|
|
|
*/ |
62
|
|
|
protected $stopProcessing = false; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Flag indicating that immediate processing is forced |
66
|
|
|
* |
67
|
|
|
* @var bool |
68
|
|
|
*/ |
69
|
|
|
protected $forceImmediateProcessing = false; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Constructor |
73
|
|
|
* |
74
|
|
|
* @param int $uid |
75
|
|
|
* @param string $uid |
76
|
|
|
* @param array $fields |
77
|
|
|
*/ |
78
|
|
|
public function __construct(int $uid, string $table, array $fields = []) |
79
|
|
|
{ |
80
|
|
|
$this->uid = $uid; |
81
|
|
|
$this->table = $table; |
82
|
|
|
$this->fields = $fields; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Cleans the event before serialisation |
87
|
|
|
* e.g. only required fields should be kept |
88
|
|
|
* in fields array |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public function __sleep(): array |
93
|
|
|
{ |
94
|
|
|
// always remove l10n_diffsource |
95
|
|
|
unset($this->fields['l10n_diffsource']); |
96
|
|
|
|
97
|
|
|
$properties = array_keys(get_object_vars($this)); |
98
|
|
|
if ($this->table == 'pages') { |
99
|
|
|
// skip cleanup for pages as there might be additional |
100
|
|
|
// required update fields in TypoScript which |
101
|
|
|
// we don't want to load here. (see: "recursiveUpdateFields") |
102
|
|
|
return $properties; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$requiredUpdateFields = array_unique(array_merge( |
106
|
|
|
DataUpdateHandler::getRequiredUpdatedFields(), |
107
|
|
|
GarbageHandler::getRequiredUpdatedFields() |
108
|
|
|
)); |
109
|
|
|
$this->fields = array_intersect_key($this->fields, array_flip($requiredUpdateFields)); |
110
|
|
|
|
111
|
|
|
return $properties; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Returns the uid of the updated record |
116
|
|
|
* |
117
|
|
|
* @return int |
118
|
|
|
*/ |
119
|
|
|
public function getUid(): int |
120
|
|
|
{ |
121
|
|
|
return $this->uid; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Returns the table of the updated record |
126
|
|
|
* |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function getTable(): string |
130
|
|
|
{ |
131
|
|
|
return $this->table; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Returns the updated fields |
136
|
|
|
* |
137
|
|
|
* @return array |
138
|
|
|
*/ |
139
|
|
|
public function getFields(): array |
140
|
|
|
{ |
141
|
|
|
return $this->fields; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Indicates if the event propagation is stopped |
146
|
|
|
* If stopped, it prevents other listeners from being called |
147
|
|
|
* |
148
|
|
|
* {@inheritDoc} |
149
|
|
|
* @see \Psr\EventDispatcher\StoppableEventInterface::isPropagationStopped() |
150
|
|
|
*/ |
151
|
|
|
final public function isPropagationStopped(): bool |
152
|
|
|
{ |
153
|
|
|
return $this->stopProcessing; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Sets the stop rendering flag |
158
|
|
|
* |
159
|
|
|
* If set, event propagation is stopped |
160
|
|
|
* |
161
|
|
|
* @param bool $stopRendering |
162
|
|
|
*/ |
163
|
|
|
final public function setStopProcessing(bool $stopProcessing): void |
164
|
|
|
{ |
165
|
|
|
$this->stopProcessing = $stopProcessing; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Indicates if event is a page update |
170
|
|
|
* |
171
|
|
|
* @return bool |
172
|
|
|
*/ |
173
|
|
|
public function isPageUpdate(): bool |
174
|
|
|
{ |
175
|
|
|
return ($this->table === 'pages'); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Indicates if event is a content element update |
180
|
|
|
* |
181
|
|
|
* @return bool |
182
|
|
|
*/ |
183
|
|
|
public function isContentElementUpdate(): bool |
184
|
|
|
{ |
185
|
|
|
return ($this->table === 'tt_content'); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Indicates if immediate processing is forced |
190
|
|
|
* |
191
|
|
|
* @return bool |
192
|
|
|
*/ |
193
|
|
|
final public function isImmediateProcessingForced(): bool |
194
|
|
|
{ |
195
|
|
|
return $this->forceImmediateProcessing; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Sets the flag indicating if immediate processing is forced |
200
|
|
|
* |
201
|
|
|
* @param bool $forceImmediateProcessing |
202
|
|
|
*/ |
203
|
|
|
final public function setForceImmediateProcessing(bool $forceImmediateProcessing): void |
204
|
|
|
{ |
205
|
|
|
$this->forceImmediateProcessing = $forceImmediateProcessing; |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|