Passed
Push — release-11.5.x ( 1b5a31...ef0664 )
by Markus
31:41
created

DataUpdateHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 21
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 9
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 92
    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 92
        parent::__construct($recordService, $frontendEnvironment, $tcaService, $indexQueue);
145
146 92
        $this->mountPageUpdater = $mountPageUpdater;
147 92
        $this->rootPageResolver = $rootPageResolver;
148 92
        $this->pagesRepository = $pagesRepository;
149 92
        $this->dataHandler = $dataHandler;
150 92
        $this->logger = $solrLogManager ?? GeneralUtility::makeInstance(
151 92
            SolrLogManager::class,
152
            /** @scrutinizer ignore-type */
153 92
            __CLASS__
154 92
        );
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 6
    public function handleContentElementDeletion(int $uid): void
185
    {
186
        // @TODO: Should be checked, is possibly unnecessary as
187
        //        also done via GarbageCollector & PageStrategy
188
189 6
        $pid = $this->getValidatedPid('tt_content', $uid);
190 6
        if ($pid === null) {
191
            return;
192
        }
193
194 6
        $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
     * @param int|null $previousParentId
276
     * @throws DBALDriverException
277
     * @throws DBALException|\Doctrine\DBAL\DBALException
278
     * @throws Throwable
279
     */
280 7
    public function handleMovedPage(int $uid, ?int $previousParentId = null): void
281
    {
282 7
        $excludedPages = $this->pagesRepository->findAllPagesWithinNoSearchSubEntriesMarkedPages();
0 ignored issues
show
Bug introduced by
The method findAllPagesWithinNoSearchSubEntriesMarkedPages() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

282
        /** @scrutinizer ignore-call */ 
283
        $excludedPages = $this->pagesRepository->findAllPagesWithinNoSearchSubEntriesMarkedPages();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
283 7
        if (in_array($uid, $excludedPages)) {
284 2
            return;
285
        }
286
287 5
        $this->applyPageChangesToQueue($uid);
288
289 5
        if ($previousParentId !== null) {
290 4
            $pageRecord = BackendUtility::getRecord('pages', $uid);
291 4
            if ($pageRecord !== null && (int)$pageRecord['pid'] !== $previousParentId) {
292 3
                $treePageIds = $this->getSubPageIds($uid);
293 3
                $this->updatePageIdItems($treePageIds);
294
            }
295
        }
296
    }
297
298
    /**
299
     * Handle record move
300
     *
301
     * @param int $uid
302
     * @param string $table
303
     * @throws DBALDriverException
304
     * @throws DBALException|\Doctrine\DBAL\DBALException
305
     * @throws Throwable
306
     */
307 1
    public function handleMovedRecord(int $uid, string $table): void
308
    {
309 1
        $pid = $this->getValidatedPid($table, $uid);
310 1
        if ($pid === null) {
311
            return;
312
        }
313
314 1
        $this->applyRecordChangesToQueue($table, $uid, $pid);
315
    }
316
317
    /**
318
     * Adds a page to the queue and updates mounts, when it is enabled, otherwise ensure that the page is removed
319
     * from the queue.
320
     *
321
     * @param int $uid
322
     * @throws DBALDriverException
323
     * @throws DBALException|\Doctrine\DBAL\DBALException
324
     * @throws Throwable
325
     */
326 9
    protected function applyPageChangesToQueue(int $uid): void
327
    {
328 9
        $solrConfiguration = $this->getSolrConfigurationFromPageId($uid);
329 9
        $record = $this->configurationAwareRecordService->getRecord('pages', $uid, $solrConfiguration);
330 9
        if (!empty($record) && $this->tcaService->isEnabledRecord('pages', $record)) {
331 8
            $this->mountPageUpdater->update($uid);
332 8
            $this->indexQueue->updateItem('pages', $uid);
333
        } else {
334 1
            $this->removeFromIndexAndQueueWhenItemInQueue('pages', $uid);
335
        }
336
    }
337
338
    /**
339
     * Adds a record to the queue if it is monitored and enabled, otherwise it removes the record from the queue.
340
     *
341
     * @param string $table
342
     * @param int $uid
343
     * @param int $pid
344
     * @throws DBALDriverException
345
     * @throws DBALException|\Doctrine\DBAL\DBALException
346
     * @throws Throwable
347
     */
348 3
    protected function applyRecordChangesToQueue(string $table, int $uid, int $pid): void
349
    {
350 3
        $solrConfiguration = $this->getSolrConfigurationFromPageId($pid);
351 3
        $isMonitoredTable = $solrConfiguration->getIndexQueueIsMonitoredTable($table);
352
353 3
        if ($isMonitoredTable) {
354 3
            $record = $this->configurationAwareRecordService->getRecord($table, $uid, $solrConfiguration);
355
356 3
            if (!empty($record) && $this->tcaService->isEnabledRecord($table, $record)) {
357 2
                $uid = $this->tcaService->getTranslationOriginalUidIfTranslated($table, $record, $uid);
358 2
                $this->indexQueue->updateItem($table, $uid);
359
            } else {
360
                // TODO should be moved to garbage collector
361 1
                $this->removeFromIndexAndQueueWhenItemInQueue($table, $uid);
362
            }
363
        }
364
    }
365
366
    /**
367
     * Removes record from the index queue and from the solr index
368
     *
369
     * @param string $recordTable Name of table where the record lives
370
     * @param int $recordUid id of record
371
     */
372 6
    protected function removeFromIndexAndQueue(string $recordTable, int $recordUid): void
373
    {
374 6
        $this->getGarbageHandler()->collectGarbage($recordTable, $recordUid);
375
    }
376
377
    /**
378
     * Removes record from the index queue and from the solr index when the item is in the queue.
379
     *
380
     * @param string $recordTable Name of table where the record lives
381
     * @param int $recordUid id of record
382
     * @throws DBALDriverException
383
     * @throws DBALException|\Doctrine\DBAL\DBALException
384
     */
385 8
    protected function removeFromIndexAndQueueWhenItemInQueue(string $recordTable, int $recordUid): void
386
    {
387 8
        if (!$this->indexQueue->containsItem($recordTable, $recordUid)) {
388 2
            return;
389
        }
390
391 6
        $this->removeFromIndexAndQueue($recordTable, $recordUid);
392
    }
393
394
    /**
395
     * @param int $pageId
396
     * @return TypoScriptConfiguration
397
     * @throws DBALDriverException
398
     */
399 12
    protected function getSolrConfigurationFromPageId(int $pageId): TypoScriptConfiguration
400
    {
401 12
        return $this->frontendEnvironment->getSolrConfigurationFromPageId($pageId);
402
    }
403
404
    /**
405
     * Fetch record root page ids
406
     *
407
     * @param string $recordTable The table the record belongs to
408
     * @param int $recordUid
409
     * @return int[]
410
     * @throws DBALDriverException
411
     * @throws Throwable
412
     */
413 13
    protected function getRecordRootPageIds(string $recordTable, int $recordUid): array
414
    {
415
        try {
416 13
            $rootPageIds = $this->rootPageResolver->getResponsibleRootPageIds($recordTable, $recordUid);
417
        } catch (InvalidArgumentException $e) {
418
            $rootPageIds = [];
419
        }
420
421 13
        return $rootPageIds;
422
    }
423
424
    /**
425
     * Processes a page record
426
     *
427
     * Note: Also used if content element is updated, the page
428
     * of the content element is processed here
429
     *
430
     * @param int $uid
431
     * @param int $pid
432
     * @param array $updatedFields
433
     * @throws DBALDriverException
434
     * @throws Throwable
435
     */
436 56
    protected function processPageRecord(int $uid, int $pid, array $updatedFields = []): void
437
    {
438 56
        $configurationPageId = $this->getConfigurationPageId('pages', $pid, $uid);
439 56
        if ($configurationPageId === 0) {
440 2
            $this->mountPageUpdater->update($uid);
441 2
            return;
442
        }
443 54
        $rootPageIds = [$configurationPageId];
444
445 54
        $this->processRecord('pages', $uid, $rootPageIds);
446
447 54
        $this->updateCanonicalPages($uid);
448 54
        $this->mountPageUpdater->update($uid);
449
450 54
        $recursiveUpdateRequired = $this->isRecursivePageUpdateRequired($uid, $updatedFields);
451 54
        if ($recursiveUpdateRequired) {
452 12
            $treePageIds = $this->getSubPageIds($uid);
453 12
            $this->updatePageIdItems($treePageIds);
454
        }
455
    }
456
457
    /**
458
     * Process a record
459
     *
460
     * @param string $recordTable
461
     * @param int $recordUid
462
     * @param array $rootPageIds
463
     * @throws DBALDriverException
464
     * @throws DBALException|\Doctrine\DBAL\DBALException
465
     * @throws Throwable
466
     */
467 67
    protected function processRecord(string $recordTable, int $recordUid, array $rootPageIds): void
468
    {
469 67
        if (empty($rootPageIds)) {
470
            $this->removeFromIndexAndQueueWhenItemInQueue($recordTable, $recordUid);
471
            return;
472
        }
473
474 67
        foreach ($rootPageIds as $configurationPageId) {
475 67
            $site = $this->getSiteRepository()->getSiteByPageId($configurationPageId);
476 67
            if (!$site instanceof SiteInterface) {
477
                continue;
478
            }
479 67
            $solrConfiguration = $site->getSolrConfiguration();
480 67
            $isMonitoredRecord = $solrConfiguration->getIndexQueueIsMonitoredTable($recordTable);
481 67
            if (!$isMonitoredRecord) {
482
                // when it is a non monitored record, we can skip it.
483 1
                continue;
484
            }
485
486 66
            $record = $this->configurationAwareRecordService->getRecord($recordTable, $recordUid, $solrConfiguration);
487 66
            if (empty($record)) {
488
                // TODO move this part to the garbage collector
489
                // check if the item should be removed from the index because it no longer matches the conditions
490 4
                $this->removeFromIndexAndQueueWhenItemInQueue($recordTable, $recordUid);
491 4
                continue;
492
            }
493
            // Clear existing index queue items to prevent mount point duplicates.
494
            // This needs to be done before the overlay handling, because handling an overlay record should
495
            // not trigger a deletion.
496 64
            $isTranslation = !empty($record['sys_language_uid']) && $record['sys_language_uid'] !== 0;
497 64
            if ($recordTable === 'pages' && !$isTranslation) {
498 49
                $this->indexQueue->deleteItem('pages', $recordUid);
499
            }
500
501
            // The pages localized record can not consist without l10n_parent, so apply "free-content-mode" on records only.
502 64
            if ($recordTable === 'pages' || !$site->hasFreeContentModeLanguages() || !in_array($record['sys_language_uid'], $site->getFreeContentModeLanguages())) {
0 ignored issues
show
Bug introduced by
The method hasFreeContentModeLanguages() does not exist on ApacheSolrForTypo3\Solr\Domain\Site\SiteInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to ApacheSolrForTypo3\Solr\Domain\Site\SiteInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

502
            if ($recordTable === 'pages' || !$site->/** @scrutinizer ignore-call */ hasFreeContentModeLanguages() || !in_array($record['sys_language_uid'], $site->getFreeContentModeLanguages())) {
Loading history...
Bug introduced by
The method getFreeContentModeLanguages() does not exist on ApacheSolrForTypo3\Solr\Domain\Site\SiteInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to ApacheSolrForTypo3\Solr\Domain\Site\SiteInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

502
            if ($recordTable === 'pages' || !$site->hasFreeContentModeLanguages() || !in_array($record['sys_language_uid'], $site->/** @scrutinizer ignore-call */ getFreeContentModeLanguages())) {
Loading history...
503 64
                $recordUid = $this->tcaService->getTranslationOriginalUidIfTranslated($recordTable, $record, $recordUid);
504
            }
505
506
            // only update/insert the item if we actually found a record
507 64
            $isLocalizedRecord = $this->tcaService->isLocalizedRecord($recordTable, $record);
508
509 64
            if ($isLocalizedRecord && !$this->getIsTranslationParentRecordEnabled($recordTable, $recordUid)) {
0 ignored issues
show
Bug introduced by
It seems like $recordUid can also be of type null; however, parameter $recordUid of ApacheSolrForTypo3\Solr\...onParentRecordEnabled() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

509
            if ($isLocalizedRecord && !$this->getIsTranslationParentRecordEnabled($recordTable, /** @scrutinizer ignore-type */ $recordUid)) {
Loading history...
510
                // we have a localized record without a visible parent record. Nothing to do.
511
                continue;
512
            }
513
514 64
            if ($this->tcaService->isEnabledRecord($recordTable, $record)) {
515 58
                $this->indexQueue->updateItem($recordTable, $recordUid);
516
            }
517
        }
518
    }
519
520
    /**
521
     * This method is used to determine the pageId that should be used to retrieve the index queue configuration.
522
     *
523
     * @param string $recordTable
524
     * @param int $recordPageId
525
     * @param int $recordUid
526
     * @return int
527
     * @throws DBALDriverException
528
     * @throws Throwable
529
     */
530 56
    protected function getConfigurationPageId(string $recordTable, int $recordPageId, int $recordUid): int
531
    {
532 56
        $rootPageId = $this->rootPageResolver->getRootPageId($recordPageId);
533 56
        $rootPageRecord = $this->getPagesRepository()->getPage($rootPageId);
534 56
        if (isset($rootPageRecord['sys_language_uid'])
535 56
            && (int)$rootPageRecord['sys_language_uid'] > 0
536 56
            && isset($rootPageRecord['l10n_parent'])
537 56
            && (int)$rootPageRecord['l10n_parent'] > 0
538
        ) {
539 2
            $rootPageId = $recordPageId = $rootPageRecord['l10n_parent'];
540
        }
541 56
        if ($this->rootPageResolver->getIsRootPageId($rootPageId)) {
542 54
            return $recordPageId;
543
        }
544
545 2
        $alternativeSiteRoots = $this->rootPageResolver->getAlternativeSiteRootPagesIds(
546 2
            $recordTable,
547 2
            $recordUid,
548 2
            $recordPageId
549 2
        );
550 2
        return (int)array_pop($alternativeSiteRoots);
551
    }
552
553
    /**
554
     * Checks if the parent record of the translated record is enabled.
555
     *
556
     * @param string $recordTable
557
     * @param int $recordUid
558
     * @return bool
559
     */
560 3
    protected function getIsTranslationParentRecordEnabled(string $recordTable, int $recordUid): bool
561
    {
562 3
        $l10nParentRecord = (array)BackendUtility::getRecord($recordTable, $recordUid, '*', '', false);
563 3
        return $this->tcaService->isEnabledRecord($recordTable, $l10nParentRecord);
564
    }
565
566
    /**
567
     * Applies the updateItem instruction on a collection of pageIds.
568
     *
569
     * @param array $treePageIds
570
     * @throws DBALDriverException
571
     * @throws DBALException|\Doctrine\DBAL\DBALException
572
     * @throws Throwable
573
     */
574 15
    protected function updatePageIdItems(array $treePageIds): void
575
    {
576 15
        foreach ($treePageIds as $treePageId) {
577 13
            $this->indexQueue->updateItem('pages', $treePageId, time());
578 13
            $this->mountPageUpdater->update($treePageId);
579
        }
580
    }
581
582
    /**
583
     * Triggers Index Queue updates for other pages showing content from the
584
     * page currently being updated.
585
     *
586
     * @param int $pageId UID of the page currently being updated
587
     * @throws DBALDriverException
588
     * @throws DBALException|\Doctrine\DBAL\DBALException
589
     * @throws Throwable
590
     */
591 54
    protected function updateCanonicalPages(int $pageId): void
592
    {
593 54
        $canonicalPages = $this->pagesRepository->findPageUidsWithContentsFromPid($pageId);
594 54
        foreach ($canonicalPages as $page) {
595
            $this->indexQueue->updateItem('pages', $page['uid']);
596
        }
597
    }
598
599
    /**
600
     * Retrieves the pid of a record, returns null if no pid could be found
601
     *
602
     * @param string $table
603
     * @param int $uid
604
     * @return int|null
605
     */
606 49
    protected function getValidatedPid(string $table, int $uid): ?int
607
    {
608 49
        $pid = $this->dataHandler->getPID($table, $uid);
609 49
        if ($pid === false) {
610 1
            $message = 'Record without valid pid was processed ' . $table . ':' . $uid;
611 1
            $this->logger->log(SolrLogManager::WARNING, $message);
612 1
            return null;
613
        }
614
615 48
        return $pid;
616
    }
617
618
    /**
619
     * @return GarbageHandler
620
     */
621 6
    protected function getGarbageHandler(): GarbageHandler
622
    {
623 6
        return GeneralUtility::makeInstance(GarbageHandler::class);
624
    }
625
626
    /**
627
     * @return SiteRepository
628
     */
629 67
    protected function getSiteRepository(): SiteRepository
630
    {
631 67
        return GeneralUtility::makeInstance(SiteRepository::class);
632
    }
633
}
634