Passed
Push — release-11.5.x ( eab588...506b54 )
by Rafael
49:07 queued 25:53
created

PageStrategy::collectPageGarbageByPageChange()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 5
cp 0.8
rs 10
cc 3
nc 2
nop 1
crap 3.072
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace ApacheSolrForTypo3\Solr\Domain\Index\Queue\GarbageRemover;
17
18
use TYPO3\CMS\Backend\Utility\BackendUtility;
19
20
/**
21
 * Class PageStrategy
22
 */
23
class PageStrategy extends AbstractStrategy
24
{
25
    /**
26
     * @param string $table
27
     * @param int $uid
28
     */
29 20
    protected function removeGarbageOfByStrategy(string $table, int $uid)
30
    {
31 20
        if ($table === 'tt_content') {
32 8
            $this->collectPageGarbageByContentChange($uid);
33 8
            return;
34
        }
35
36 12
        if ($table === 'pages') {
37 12
            $this->collectPageGarbageByPageChange($uid);
38
        }
39
    }
40
41
    /**
42
     * Determines the relevant page id for a content element update. Deletes the page from solr and requeues the
43
     * page for a reindex.
44
     *
45
     * @param int $ttContentUid
46
     */
47 8
    protected function collectPageGarbageByContentChange(int $ttContentUid)
48
    {
49 8
        $contentElement = BackendUtility::getRecord('tt_content', $ttContentUid, 'uid, pid', '', false);
50 8
        $this->deleteInSolrAndUpdateIndexQueue('pages', $contentElement['pid']);
51
    }
52
53
    /**
54
     * When a page was changed it is removed from the index and index queue.
55
     *
56
     * @param int $uid
57
     */
58 12
    protected function collectPageGarbageByPageChange(int $uid)
59
    {
60 12
        $pageOverlay = BackendUtility::getRecord('pages', $uid, 'l10n_parent, sys_language_uid', '', false);
61 12
        if (!empty($pageOverlay['l10n_parent']) && (int)($pageOverlay['l10n_parent']) !== 0) {
62
            $this->deleteIndexDocuments('pages', (int)$pageOverlay['l10n_parent'], (int)$pageOverlay['sys_language_uid']);
63
        } else {
64 12
            $this->deleteInSolrAndRemoveFromIndexQueue('pages', $uid);
65
        }
66
    }
67
}
68