|
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 ApacheSolrForTypo3\Solr\Util; |
|
29
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Class PageStrategy |
|
33
|
|
|
* @package ApacheSolrForTypo3\Solr\Domain\Index\Queue\GarbageRemover |
|
34
|
|
|
*/ |
|
35
|
|
|
class PageStrategy extends AbstractStrategy { |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param string $table |
|
39
|
|
|
* @param int $uid |
|
40
|
|
|
* @return mixed |
|
41
|
|
|
*/ |
|
42
|
10 |
|
protected function removeGarbageOfByStrategy($table, $uid) |
|
43
|
|
|
{ |
|
44
|
10 |
|
if ($table === 'tt_content') { |
|
45
|
4 |
|
$this->collectPageGarbageByContentChange($uid); |
|
46
|
4 |
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
6 |
|
if ($table === 'pages_language_overlay') { |
|
50
|
|
|
$this->collectPageGarbageByPageOverlayChange($uid); |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
6 |
|
if ($table === 'pages') { |
|
55
|
6 |
|
$this->collectPageGarbageByPageChange($uid); |
|
56
|
6 |
|
return; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Determines the relevant page id for an content element update. Deletes the page from solr and requeues the |
|
62
|
|
|
* page for a reindex. |
|
63
|
|
|
* |
|
64
|
|
|
* @todo This case can be deleted when TYPO3 8 compatibility is dropped |
|
65
|
|
|
* @param int $ttContentUid |
|
66
|
|
|
*/ |
|
67
|
4 |
|
protected function collectPageGarbageByContentChange($ttContentUid) |
|
68
|
|
|
{ |
|
69
|
4 |
|
$contentElement = BackendUtility::getRecord('tt_content', $ttContentUid, 'uid, pid', '', false); |
|
70
|
4 |
|
$this->deleteInSolrAndUpdateIndexQueue('pages', $contentElement['pid']); |
|
71
|
4 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Determines the relavant page id for the pages_language_overlay. Deletes the page from solr and requeues the |
|
75
|
|
|
* page for a re index. |
|
76
|
|
|
* |
|
77
|
|
|
* @param int $pagesLanguageOverlayUid |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function collectPageGarbageByPageOverlayChange($pagesLanguageOverlayUid) |
|
80
|
|
|
{ |
|
81
|
|
|
$pageOverlayRecord = BackendUtility::getRecord('pages_language_overlay', $pagesLanguageOverlayUid, 'uid, pid', '', false); |
|
82
|
|
|
$this->deleteInSolrAndUpdateIndexQueue('pages', $pageOverlayRecord['pid']); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* When a page was changed it is removed from the index and index queue. |
|
87
|
|
|
* |
|
88
|
|
|
* @param int $uid |
|
89
|
|
|
*/ |
|
90
|
6 |
|
protected function collectPageGarbageByPageChange($uid) |
|
91
|
|
|
{ |
|
92
|
|
|
// @todo The content of this if statement can allways be executed when TYPO3 8 support is dropped |
|
93
|
6 |
|
if (!Util::getIsTYPO3VersionBelow9()) { |
|
94
|
|
|
$pageOverlay = BackendUtility::getRecord('pages', $uid, 'l10n_parent', '', false); |
|
95
|
|
|
$uid = empty($pageOverlay['l10n_parent']) ? $uid : $pageOverlay['l10n_parent']; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
6 |
|
$this->deleteInSolrAndRemoveFromIndexQueue('pages', $uid); |
|
99
|
|
|
} |
|
100
|
|
|
} |