Passed
Push — task/2976_TYPO3.11_compatibili... ( 803400...b598e4 )
by Rafael
33:58 queued 15:41
created

PageStrategy   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 13
dl 0
loc 42
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A collectPageGarbageByContentChange() 0 4 1
A removeGarbageOfByStrategy() 0 9 3
A collectPageGarbageByPageChange() 0 7 3
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\Domain\Index\Queue\GarbageRemover;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2018 - Timo Hund <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use TYPO3\CMS\Backend\Utility\BackendUtility;
29
30
31
/**
32
 * Class PageStrategy
33
 */
34
class PageStrategy extends AbstractStrategy {
35
36
    /**
37
     * @param string $table
38
     * @param int $uid
39
     */
40 22
    protected function removeGarbageOfByStrategy($table, $uid)
41
    {
42 22
        if ($table === 'tt_content') {
43 8
            $this->collectPageGarbageByContentChange($uid);
44 8
            return;
45
        }
46
47 14
        if ($table === 'pages') {
48 14
            $this->collectPageGarbageByPageChange($uid);
49
        }
50 14
    }
51
52
    /**
53
     * Determines the relevant page id for an content element update. Deletes the page from solr and requeues the
54
     * page for a reindex.
55
     *
56
     * @param int $ttContentUid
57
     */
58 8
    protected function collectPageGarbageByContentChange($ttContentUid)
59
    {
60 8
        $contentElement = BackendUtility::getRecord('tt_content', $ttContentUid, 'uid, pid', '', false);
61 8
        $this->deleteInSolrAndUpdateIndexQueue('pages', $contentElement['pid']);
62 8
    }
63
64
    /**
65
     * When a page was changed it is removed from the index and index queue.
66
     *
67
     * @param int $uid
68
     */
69 14
    protected function collectPageGarbageByPageChange($uid)
70
    {
71 14
        $pageOverlay = BackendUtility::getRecord('pages', $uid, 'l10n_parent, sys_language_uid', '', false);
72 14
        if (!empty($pageOverlay['l10n_parent']) && intval($pageOverlay['l10n_parent']) !== 0) {
73 2
            $this->deleteIndexDocuments('pages', (int)$pageOverlay['l10n_parent'], (int)$pageOverlay['sys_language_uid']);
74
        } else {
75 12
            $this->deleteInSolrAndRemoveFromIndexQueue('pages', $uid);
76
        }
77 14
    }
78
}
79