1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TYPO3 CMS project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
10
|
|
|
* of the License, or any later version. |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please read the |
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* The TYPO3 project - inspiring people to share! |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Index\Queue\UpdateHandler; |
19
|
|
|
|
20
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\ConfigurationAwareRecordService; |
21
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\MountPagesUpdater; |
22
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\RootPageResolver; |
23
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Site\SiteInterface; |
24
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; |
25
|
|
|
use ApacheSolrForTypo3\Solr\FrontendEnvironment; |
26
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\Queue; |
27
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
28
|
|
|
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; |
29
|
|
|
use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository; |
30
|
|
|
use ApacheSolrForTypo3\Solr\System\TCA\TCAService; |
31
|
|
|
use ApacheSolrForTypo3\Solr\Util; |
32
|
|
|
use Doctrine\DBAL\Driver\Exception as DBALDriverException; |
33
|
|
|
use Doctrine\DBAL\Exception as DBALException; |
34
|
|
|
use InvalidArgumentException; |
35
|
|
|
use Throwable; |
36
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
37
|
|
|
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; |
38
|
|
|
use TYPO3\CMS\Core\DataHandling\DataHandler; |
39
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Data update handler |
43
|
|
|
* |
44
|
|
|
* Handles update on potential relevant records e.g. |
45
|
|
|
* an update might require index queue updates |
46
|
|
|
*/ |
47
|
|
|
class DataUpdateHandler extends AbstractUpdateHandler |
48
|
|
|
{ |
49
|
|
|
/** |
50
|
|
|
* List of fields in the update field array that |
51
|
|
|
* are required for processing |
52
|
|
|
* |
53
|
|
|
* Note: For pages all fields except l10n_diffsource are |
54
|
|
|
* kept, as additional fields can be configured in |
55
|
|
|
* TypoScript, see AbstractDataUpdateEvent->_sleep. |
56
|
|
|
* |
57
|
|
|
* @var array |
58
|
|
|
*/ |
59
|
|
|
protected static array $requiredUpdatedFields = [ |
60
|
|
|
'pid', |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Configuration used to check if recursive updates are required |
65
|
|
|
* |
66
|
|
|
* Holds the configuration when a recursive page queuing should be triggered, while processing record |
67
|
|
|
* updates |
68
|
|
|
* |
69
|
|
|
* Note: The SQL transaction is already committed, so the current state covers only "non"-changed fields. |
70
|
|
|
* |
71
|
|
|
* @var array |
72
|
|
|
*/ |
73
|
|
|
protected array $updateSubPagesRecursiveTriggerConfiguration = [ |
74
|
|
|
// the current page has the both fields "extendToSubpages" and "hidden" set from 1 to 0 => requeue subpages |
75
|
|
|
'HiddenAndExtendToSubpageWereDisabled' => [ |
76
|
|
|
'changeSet' => [ |
77
|
|
|
'hidden' => '0', |
78
|
|
|
'extendToSubpages' => '0', |
79
|
|
|
], |
80
|
|
|
], |
81
|
|
|
// the current page has the field "extendToSubpages" enabled and the field "hidden" was set to 0 => requeue subpages |
82
|
|
|
'extendToSubpageEnabledAndHiddenFlagWasRemoved' => [ |
83
|
|
|
'currentState' => ['extendToSubpages' => '1'], |
84
|
|
|
'changeSet' => ['hidden' => '0'], |
85
|
|
|
], |
86
|
|
|
// the current page has the field "hidden" enabled and the field "extendToSubpages" was set to 0 => requeue subpages |
87
|
|
|
'hiddenIsEnabledAndExtendToSubPagesWasRemoved' => [ |
88
|
|
|
'currentState' => ['hidden' => '1'], |
89
|
|
|
'changeSet' => ['extendToSubpages' => '0'], |
90
|
|
|
], |
91
|
|
|
// the field "no_search_sub_entries" of current page was set to 0 |
92
|
|
|
'no_search_sub_entriesFlagWasAdded' => [ |
93
|
|
|
'changeSet' => ['no_search_sub_entries' => '0'], |
94
|
|
|
], |
95
|
|
|
]; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var MountPagesUpdater |
99
|
|
|
*/ |
100
|
|
|
protected MountPagesUpdater $mountPageUpdater; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @var RootPageResolver |
104
|
|
|
*/ |
105
|
|
|
protected RootPageResolver $rootPageResolver; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @var PagesRepository|null |
109
|
|
|
*/ |
110
|
|
|
protected ?PagesRepository $pagesRepository; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var SolrLogManager |
114
|
|
|
*/ |
115
|
|
|
protected SolrLogManager $logger; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @var DataHandler |
119
|
|
|
*/ |
120
|
|
|
protected DataHandler $dataHandler; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param ConfigurationAwareRecordService $recordService |
124
|
|
|
* @param FrontendEnvironment $frontendEnvironment |
125
|
|
|
* @param TCAService $tcaService |
126
|
|
|
* @param Queue $indexQueue |
127
|
|
|
* @param MountPagesUpdater $mountPageUpdater |
128
|
|
|
* @param RootPageResolver $rootPageResolver |
129
|
|
|
* @param PagesRepository $pagesRepository |
130
|
|
|
* @param DataHandler $dataHandler |
131
|
|
|
* @param SolrLogManager|null $solrLogManager |
132
|
|
|
*/ |
133
|
83 |
|
public function __construct( |
134
|
|
|
ConfigurationAwareRecordService $recordService, |
135
|
|
|
FrontendEnvironment $frontendEnvironment, |
136
|
|
|
TCAService $tcaService, |
137
|
|
|
Queue $indexQueue, |
138
|
|
|
MountPagesUpdater $mountPageUpdater, |
139
|
|
|
RootPageResolver $rootPageResolver, |
140
|
|
|
PagesRepository $pagesRepository, |
141
|
|
|
DataHandler $dataHandler, |
142
|
|
|
SolrLogManager $solrLogManager = null |
143
|
|
|
) { |
144
|
83 |
|
parent::__construct($recordService, $frontendEnvironment, $tcaService, $indexQueue); |
145
|
|
|
|
146
|
83 |
|
$this->mountPageUpdater = $mountPageUpdater; |
147
|
83 |
|
$this->rootPageResolver = $rootPageResolver; |
148
|
83 |
|
$this->pagesRepository = $pagesRepository; |
149
|
83 |
|
$this->dataHandler = $dataHandler; |
150
|
83 |
|
$this->logger = $solrLogManager ?? GeneralUtility::makeInstance( |
151
|
|
|
SolrLogManager::class, |
152
|
|
|
/** @scrutinizer ignore-type */ |
153
|
|
|
__CLASS__ |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Handle content element update |
159
|
|
|
* |
160
|
|
|
* @param int $uid |
161
|
|
|
* @param array $updatedFields |
162
|
|
|
* @throws DBALDriverException |
163
|
|
|
* @throws Throwable |
164
|
|
|
*/ |
165
|
15 |
|
public function handleContentElementUpdate(int $uid, array $updatedFields = []): void |
166
|
|
|
{ |
167
|
15 |
|
$pid = $updatedFields['pid'] ?? $this->getValidatedPid('tt_content', $uid); |
168
|
15 |
|
if ($pid === null) { |
169
|
1 |
|
return; |
170
|
|
|
} |
171
|
|
|
|
172
|
14 |
|
$this->processPageRecord($pid, (int)$pid, $updatedFields); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Handles the deletion of a content element |
177
|
|
|
* |
178
|
|
|
* @param int $uid |
179
|
|
|
* @throws AspectNotFoundException |
180
|
|
|
* @throws DBALDriverException |
181
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
182
|
|
|
* @throws Throwable |
183
|
|
|
*/ |
184
|
3 |
|
public function handleContentElementDeletion(int $uid): void |
185
|
|
|
{ |
186
|
|
|
// @TODO: Should be checked, is possibly unnecessary as |
187
|
|
|
// also done via GarbageCollector & PageStrategy |
188
|
|
|
|
189
|
3 |
|
$pid = $this->getValidatedPid('tt_content', $uid); |
190
|
3 |
|
if ($pid === null) { |
191
|
|
|
return; |
192
|
|
|
} |
193
|
|
|
|
194
|
3 |
|
$this->indexQueue->updateItem('pages', $pid, Util::getExceptionTime()); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Handles page updates |
199
|
|
|
* |
200
|
|
|
* @param int $uid |
201
|
|
|
* @param array $updatedFields |
202
|
|
|
* @throws DBALDriverException |
203
|
|
|
* @throws Throwable |
204
|
|
|
*/ |
205
|
44 |
|
public function handlePageUpdate(int $uid, array $updatedFields = []): void |
206
|
|
|
{ |
207
|
44 |
|
if ($uid === 0) { |
208
|
|
|
return; |
209
|
|
|
} |
210
|
|
|
try { |
211
|
44 |
|
if (isset($updatedFields['l10n_parent']) && (int)($updatedFields['l10n_parent']) > 0) { |
212
|
2 |
|
$pid = $updatedFields['l10n_parent']; |
213
|
42 |
|
} elseif ($this->rootPageResolver->getIsRootPageId($uid)) { |
214
|
9 |
|
$pid = $uid; |
215
|
|
|
} else { |
216
|
42 |
|
$pid = $updatedFields['pid'] ?? $this->getValidatedPid('pages', $uid); |
217
|
|
|
} |
218
|
2 |
|
} catch (Throwable $e) { |
219
|
2 |
|
$pid = null; |
220
|
|
|
} |
221
|
|
|
|
222
|
44 |
|
if ($pid === null) { |
223
|
2 |
|
$this->removeFromIndexAndQueueWhenItemInQueue('pages', $uid); |
224
|
2 |
|
return; |
225
|
|
|
} |
226
|
|
|
|
227
|
42 |
|
$this->processPageRecord($uid, (int)$pid, $updatedFields); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Handles record updates |
232
|
|
|
* |
233
|
|
|
* @param int $uid |
234
|
|
|
* @param string $table |
235
|
|
|
* @throws DBALDriverException |
236
|
|
|
* @throws Throwable |
237
|
|
|
*/ |
238
|
13 |
|
public function handleRecordUpdate(int $uid, string $table): void |
239
|
|
|
{ |
240
|
13 |
|
$rootPageIds = $this->getRecordRootPageIds($table, $uid); |
241
|
13 |
|
$this->processRecord($table, $uid, $rootPageIds); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Handles a version swap |
246
|
|
|
* |
247
|
|
|
* @param int $uid |
248
|
|
|
* @param string $table |
249
|
|
|
* @throws DBALDriverException |
250
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
251
|
|
|
* @throws Throwable |
252
|
|
|
*/ |
253
|
6 |
|
public function handleVersionSwap(int $uid, string $table): void |
254
|
|
|
{ |
255
|
6 |
|
$isPageRelatedRecord = ($table === 'tt_content' || $table === 'pages'); |
256
|
6 |
|
if ($isPageRelatedRecord) { |
257
|
4 |
|
$uid = ($table === 'tt_content' ? $this->getValidatedPid($table, $uid) : $uid); |
258
|
4 |
|
if ($uid === null) { |
259
|
|
|
return; |
260
|
|
|
} |
261
|
4 |
|
$this->applyPageChangesToQueue($uid); |
262
|
|
|
} else { |
263
|
2 |
|
$recordPageId = $this->getValidatedPid($table, $uid); |
264
|
2 |
|
if ($recordPageId === null) { |
265
|
|
|
return; |
266
|
|
|
} |
267
|
2 |
|
$this->applyRecordChangesToQueue($table, $uid, $recordPageId); |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Handle page move |
273
|
|
|
* |
274
|
|
|
* @param int $uid |
275
|
|
|
* @throws DBALDriverException |
276
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
277
|
|
|
* @throws Throwable |
278
|
|
|
*/ |
279
|
1 |
|
public function handleMovedPage(int $uid): void |
280
|
|
|
{ |
281
|
1 |
|
$this->applyPageChangesToQueue($uid); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Handle record move |
286
|
|
|
* |
287
|
|
|
* @param int $uid |
288
|
|
|
* @param string $table |
289
|
|
|
* @throws DBALDriverException |
290
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
291
|
|
|
* @throws Throwable |
292
|
|
|
*/ |
293
|
1 |
|
public function handleMovedRecord(int $uid, string $table): void |
294
|
|
|
{ |
295
|
1 |
|
$pid = $this->getValidatedPid($table, $uid); |
296
|
1 |
|
if ($pid === null) { |
297
|
|
|
return; |
298
|
|
|
} |
299
|
|
|
|
300
|
1 |
|
$this->applyRecordChangesToQueue($table, $uid, $pid); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* Adds a page to the queue and updates mounts, when it is enabled, otherwise ensure that the page is removed |
305
|
|
|
* from the queue. |
306
|
|
|
* |
307
|
|
|
* @param int $uid |
308
|
|
|
* @throws DBALDriverException |
309
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
310
|
|
|
* @throws Throwable |
311
|
|
|
*/ |
312
|
5 |
|
protected function applyPageChangesToQueue(int $uid): void |
313
|
|
|
{ |
314
|
5 |
|
$solrConfiguration = $this->getSolrConfigurationFromPageId($uid); |
315
|
5 |
|
$record = $this->configurationAwareRecordService->getRecord('pages', $uid, $solrConfiguration); |
316
|
5 |
|
if (!empty($record) && $this->tcaService->isEnabledRecord('pages', $record)) { |
317
|
4 |
|
$this->mountPageUpdater->update($uid); |
318
|
4 |
|
$this->indexQueue->updateItem('pages', $uid); |
319
|
|
|
} else { |
320
|
1 |
|
$this->removeFromIndexAndQueueWhenItemInQueue('pages', $uid); |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Adds a record to the queue if it is monitored and enabled, otherwise it removes the record from the queue. |
326
|
|
|
* |
327
|
|
|
* @param string $table |
328
|
|
|
* @param int $uid |
329
|
|
|
* @param int $pid |
330
|
|
|
* @throws DBALDriverException |
331
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
332
|
|
|
* @throws Throwable |
333
|
|
|
*/ |
334
|
3 |
|
protected function applyRecordChangesToQueue(string $table, int $uid, int $pid): void |
335
|
|
|
{ |
336
|
3 |
|
$solrConfiguration = $this->getSolrConfigurationFromPageId($pid); |
337
|
3 |
|
$isMonitoredTable = $solrConfiguration->getIndexQueueIsMonitoredTable($table); |
338
|
|
|
|
339
|
3 |
|
if ($isMonitoredTable) { |
340
|
3 |
|
$record = $this->configurationAwareRecordService->getRecord($table, $uid, $solrConfiguration); |
341
|
|
|
|
342
|
3 |
|
if (!empty($record) && $this->tcaService->isEnabledRecord($table, $record)) { |
343
|
2 |
|
$uid = $this->tcaService->getTranslationOriginalUidIfTranslated($table, $record, $uid); |
344
|
2 |
|
$this->indexQueue->updateItem($table, $uid); |
345
|
|
|
} else { |
346
|
|
|
// TODO should be moved to garbage collector |
347
|
1 |
|
$this->removeFromIndexAndQueueWhenItemInQueue($table, $uid); |
348
|
|
|
} |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Removes record from the index queue and from the solr index |
354
|
|
|
* |
355
|
|
|
* @param string $recordTable Name of table where the record lives |
356
|
|
|
* @param int $recordUid id of record |
357
|
|
|
*/ |
358
|
6 |
|
protected function removeFromIndexAndQueue(string $recordTable, int $recordUid): void |
359
|
|
|
{ |
360
|
6 |
|
$this->getGarbageHandler()->collectGarbage($recordTable, $recordUid); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* Removes record from the index queue and from the solr index when the item is in the queue. |
365
|
|
|
* |
366
|
|
|
* @param string $recordTable Name of table where the record lives |
367
|
|
|
* @param int $recordUid id of record |
368
|
|
|
* @throws DBALDriverException |
369
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
370
|
|
|
*/ |
371
|
8 |
|
protected function removeFromIndexAndQueueWhenItemInQueue(string $recordTable, int $recordUid): void |
372
|
|
|
{ |
373
|
8 |
|
if (!$this->indexQueue->containsItem($recordTable, $recordUid)) { |
374
|
2 |
|
return; |
375
|
|
|
} |
376
|
|
|
|
377
|
6 |
|
$this->removeFromIndexAndQueue($recordTable, $recordUid); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* @param int $pageId |
382
|
|
|
* @return TypoScriptConfiguration |
383
|
|
|
* @throws DBALDriverException |
384
|
|
|
*/ |
385
|
8 |
|
protected function getSolrConfigurationFromPageId(int $pageId): TypoScriptConfiguration |
386
|
|
|
{ |
387
|
8 |
|
return $this->frontendEnvironment->getSolrConfigurationFromPageId($pageId); |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Fetch record root page ids |
392
|
|
|
* |
393
|
|
|
* @param string $recordTable The table the record belongs to |
394
|
|
|
* @param int $recordUid |
395
|
|
|
* @return int[] |
396
|
|
|
* @throws DBALDriverException |
397
|
|
|
* @throws Throwable |
398
|
|
|
*/ |
399
|
13 |
|
protected function getRecordRootPageIds(string $recordTable, int $recordUid): array |
400
|
|
|
{ |
401
|
|
|
try { |
402
|
13 |
|
$rootPageIds = $this->rootPageResolver->getResponsibleRootPageIds($recordTable, $recordUid); |
403
|
|
|
} catch (InvalidArgumentException $e) { |
404
|
|
|
$rootPageIds = []; |
405
|
|
|
} |
406
|
|
|
|
407
|
13 |
|
return $rootPageIds; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Processes a page record |
412
|
|
|
* |
413
|
|
|
* Note: Also used if content element is updated, the page |
414
|
|
|
* of the content element is processed here |
415
|
|
|
* |
416
|
|
|
* @param int $uid |
417
|
|
|
* @param int $pid |
418
|
|
|
* @param array $updatedFields |
419
|
|
|
* @throws DBALDriverException |
420
|
|
|
* @throws Throwable |
421
|
|
|
*/ |
422
|
56 |
|
protected function processPageRecord(int $uid, int $pid, array $updatedFields = []): void |
423
|
|
|
{ |
424
|
56 |
|
$configurationPageId = $this->getConfigurationPageId('pages', $pid, $uid); |
425
|
56 |
|
if ($configurationPageId === 0) { |
426
|
2 |
|
$this->mountPageUpdater->update($uid); |
427
|
2 |
|
return; |
428
|
|
|
} |
429
|
54 |
|
$rootPageIds = [$configurationPageId]; |
430
|
|
|
|
431
|
54 |
|
$this->processRecord('pages', $uid, $rootPageIds); |
432
|
|
|
|
433
|
54 |
|
$this->updateCanonicalPages($uid); |
434
|
54 |
|
$this->mountPageUpdater->update($uid); |
435
|
|
|
|
436
|
54 |
|
$recursiveUpdateRequired = $this->isRecursivePageUpdateRequired($uid, $updatedFields); |
437
|
54 |
|
if ($recursiveUpdateRequired) { |
438
|
12 |
|
$treePageIds = $this->getSubPageIds($uid); |
439
|
12 |
|
$this->updatePageIdItems($treePageIds); |
440
|
|
|
} |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* Process a record |
445
|
|
|
* |
446
|
|
|
* @param string $recordTable |
447
|
|
|
* @param int $recordUid |
448
|
|
|
* @param array $rootPageIds |
449
|
|
|
* @throws DBALDriverException |
450
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
451
|
|
|
* @throws Throwable |
452
|
|
|
*/ |
453
|
67 |
|
protected function processRecord(string $recordTable, int $recordUid, array $rootPageIds): void |
454
|
|
|
{ |
455
|
67 |
|
if (empty($rootPageIds)) { |
456
|
|
|
$this->removeFromIndexAndQueueWhenItemInQueue($recordTable, $recordUid); |
457
|
|
|
return; |
458
|
|
|
} |
459
|
|
|
|
460
|
67 |
|
foreach ($rootPageIds as $configurationPageId) { |
461
|
67 |
|
$site = $this->getSiteRepository()->getSiteByPageId($configurationPageId); |
462
|
67 |
|
if (!$site instanceof SiteInterface) { |
463
|
|
|
continue; |
464
|
|
|
} |
465
|
67 |
|
$solrConfiguration = $site->getSolrConfiguration(); |
466
|
67 |
|
$isMonitoredRecord = $solrConfiguration->getIndexQueueIsMonitoredTable($recordTable); |
467
|
67 |
|
if (!$isMonitoredRecord) { |
468
|
|
|
// when it is a non monitored record, we can skip it. |
469
|
1 |
|
continue; |
470
|
|
|
} |
471
|
|
|
|
472
|
66 |
|
$record = $this->configurationAwareRecordService->getRecord($recordTable, $recordUid, $solrConfiguration); |
473
|
66 |
|
if (empty($record)) { |
474
|
|
|
// TODO move this part to the garbage collector |
475
|
|
|
// check if the item should be removed from the index because it no longer matches the conditions |
476
|
4 |
|
$this->removeFromIndexAndQueueWhenItemInQueue($recordTable, $recordUid); |
477
|
4 |
|
continue; |
478
|
|
|
} |
479
|
|
|
// Clear existing index queue items to prevent mount point duplicates. |
480
|
|
|
// This needs to be done before the overlay handling, because handling an overlay record should |
481
|
|
|
// not trigger a deletion. |
482
|
64 |
|
$isTranslation = !empty($record['sys_language_uid']) && $record['sys_language_uid'] !== 0; |
483
|
64 |
|
if ($recordTable === 'pages' && !$isTranslation) { |
484
|
49 |
|
$this->indexQueue->deleteItem('pages', $recordUid); |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
// The pages localized record can not consist without l10n_parent, so apply "free-content-mode" on records only. |
488
|
64 |
|
if ($recordTable === 'pages' || !$site->hasFreeContentModeLanguages() || !in_array($record['sys_language_uid'], $site->getFreeContentModeLanguages())) { |
|
|
|
|
489
|
64 |
|
$recordUid = $this->tcaService->getTranslationOriginalUidIfTranslated($recordTable, $record, $recordUid); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
// only update/insert the item if we actually found a record |
493
|
64 |
|
$isLocalizedRecord = $this->tcaService->isLocalizedRecord($recordTable, $record); |
494
|
|
|
|
495
|
64 |
|
if ($isLocalizedRecord && !$this->getIsTranslationParentRecordEnabled($recordTable, $recordUid)) { |
|
|
|
|
496
|
|
|
// we have a localized record without a visible parent record. Nothing to do. |
497
|
|
|
continue; |
498
|
|
|
} |
499
|
|
|
|
500
|
64 |
|
if ($this->tcaService->isEnabledRecord($recordTable, $record)) { |
501
|
58 |
|
$this->indexQueue->updateItem($recordTable, $recordUid); |
502
|
|
|
} |
503
|
|
|
} |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* This method is used to determine the pageId that should be used to retrieve the index queue configuration. |
508
|
|
|
* |
509
|
|
|
* @param string $recordTable |
510
|
|
|
* @param int $recordPageId |
511
|
|
|
* @param int $recordUid |
512
|
|
|
* @return int |
513
|
|
|
* @throws DBALDriverException |
514
|
|
|
* @throws Throwable |
515
|
|
|
*/ |
516
|
56 |
|
protected function getConfigurationPageId(string $recordTable, int $recordPageId, int $recordUid): int |
517
|
|
|
{ |
518
|
56 |
|
$rootPageId = $this->rootPageResolver->getRootPageId($recordPageId); |
519
|
56 |
|
$rootPageRecord = $this->getPagesRepository()->getPage($rootPageId); |
520
|
56 |
|
if (isset($rootPageRecord['sys_language_uid']) |
521
|
56 |
|
&& (int)$rootPageRecord['sys_language_uid'] > 0 |
522
|
56 |
|
&& isset($rootPageRecord['l10n_parent']) |
523
|
56 |
|
&& (int)$rootPageRecord['l10n_parent'] > 0 |
524
|
|
|
) { |
525
|
2 |
|
$rootPageId = $recordPageId = $rootPageRecord['l10n_parent']; |
526
|
|
|
} |
527
|
56 |
|
if ($this->rootPageResolver->getIsRootPageId($rootPageId)) { |
528
|
54 |
|
return $recordPageId; |
529
|
|
|
} |
530
|
|
|
|
531
|
2 |
|
$alternativeSiteRoots = $this->rootPageResolver->getAlternativeSiteRootPagesIds( |
532
|
|
|
$recordTable, |
533
|
|
|
$recordUid, |
534
|
|
|
$recordPageId |
535
|
|
|
); |
536
|
2 |
|
return (int)array_pop($alternativeSiteRoots); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
/** |
540
|
|
|
* Checks if the parent record of the translated record is enabled. |
541
|
|
|
* |
542
|
|
|
* @param string $recordTable |
543
|
|
|
* @param int $recordUid |
544
|
|
|
* @return bool |
545
|
|
|
*/ |
546
|
3 |
|
protected function getIsTranslationParentRecordEnabled(string $recordTable, int $recordUid): bool |
547
|
|
|
{ |
548
|
3 |
|
$l10nParentRecord = (array)BackendUtility::getRecord($recordTable, $recordUid, '*', '', false); |
549
|
3 |
|
return $this->tcaService->isEnabledRecord($recordTable, $l10nParentRecord); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
/** |
553
|
|
|
* Applies the updateItem instruction on a collection of pageIds. |
554
|
|
|
* |
555
|
|
|
* @param array $treePageIds |
556
|
|
|
* @throws DBALDriverException |
557
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
558
|
|
|
* @throws Throwable |
559
|
|
|
*/ |
560
|
12 |
|
protected function updatePageIdItems(array $treePageIds): void |
561
|
|
|
{ |
562
|
12 |
|
foreach ($treePageIds as $treePageId) { |
563
|
10 |
|
$this->indexQueue->updateItem('pages', $treePageId); |
564
|
|
|
} |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* Triggers Index Queue updates for other pages showing content from the |
569
|
|
|
* page currently being updated. |
570
|
|
|
* |
571
|
|
|
* @param int $pageId UID of the page currently being updated |
572
|
|
|
* @throws DBALDriverException |
573
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
574
|
|
|
* @throws Throwable |
575
|
|
|
*/ |
576
|
54 |
|
protected function updateCanonicalPages(int $pageId): void |
577
|
|
|
{ |
578
|
54 |
|
$canonicalPages = $this->pagesRepository->findPageUidsWithContentsFromPid($pageId); |
|
|
|
|
579
|
54 |
|
foreach ($canonicalPages as $page) { |
580
|
|
|
$this->indexQueue->updateItem('pages', $page['uid']); |
581
|
|
|
} |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
/** |
585
|
|
|
* Retrieves the pid of a record, returns null if no pid could be found |
586
|
|
|
* |
587
|
|
|
* @param string $table |
588
|
|
|
* @param int $uid |
589
|
|
|
* @return int|null |
590
|
|
|
*/ |
591
|
46 |
|
protected function getValidatedPid(string $table, int $uid): ?int |
592
|
|
|
{ |
593
|
46 |
|
$pid = $this->dataHandler->getPID($table, $uid); |
594
|
46 |
|
if ($pid === false) { |
595
|
1 |
|
$message = 'Record without valid pid was processed ' . $table . ':' . $uid; |
596
|
1 |
|
$this->logger->log(SolrLogManager::WARNING, $message); |
597
|
1 |
|
return null; |
598
|
|
|
} |
599
|
|
|
|
600
|
45 |
|
return $pid; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* @return GarbageHandler |
605
|
|
|
*/ |
606
|
6 |
|
protected function getGarbageHandler(): GarbageHandler |
607
|
|
|
{ |
608
|
6 |
|
return GeneralUtility::makeInstance(GarbageHandler::class); |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
/** |
612
|
|
|
* @return SiteRepository |
613
|
|
|
*/ |
614
|
67 |
|
protected function getSiteRepository(): SiteRepository |
615
|
|
|
{ |
616
|
67 |
|
return GeneralUtility::makeInstance(SiteRepository::class); |
617
|
|
|
} |
618
|
|
|
} |
619
|
|
|
|