|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2010-2015 Ingo Renner <[email protected]> |
|
8
|
|
|
* All rights reserved |
|
9
|
|
|
* |
|
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
11
|
|
|
* free software; you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* The GNU General Public License can be found at |
|
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
18
|
|
|
* |
|
19
|
|
|
* This script is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
25
|
|
|
***************************************************************/ |
|
26
|
|
|
|
|
27
|
|
|
use ApacheSolrForTypo3\Solr\ConnectionManager; |
|
28
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\Queue; |
|
29
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
30
|
|
|
use TYPO3\CMS\Core\DataHandling\DataHandler; |
|
31
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
|
32
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Garbage Collector, removes related documents from the index when a record is |
|
36
|
|
|
* set to hidden, is deleted or is otherwise made invisible to website visitors. |
|
37
|
|
|
* |
|
38
|
|
|
* Garbage collection will happen for online/LIVE workspaces only. |
|
39
|
|
|
* |
|
40
|
|
|
* @author Ingo Renner <[email protected]> |
|
41
|
|
|
* @author Timo Schmidt <[email protected]> |
|
42
|
|
|
*/ |
|
43
|
|
|
class GarbageCollector extends AbstractDataHandlerListener implements SingletonInterface |
|
44
|
|
|
{ |
|
45
|
|
|
protected $trackedRecords = array(); |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Hooks into TCE main and tracks record deletion commands. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $command The command. |
|
51
|
|
|
* @param string $table The table the record belongs to |
|
52
|
|
|
* @param int $uid The record's uid |
|
53
|
|
|
* @param string $value Not used |
|
54
|
|
|
* @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
|
55
|
|
|
* @return void |
|
56
|
|
|
*/ |
|
57
|
|
|
public function processCmdmap_preProcess( |
|
58
|
|
|
$command, |
|
59
|
|
|
$table, |
|
60
|
|
|
$uid, |
|
61
|
|
|
$value, |
|
|
|
|
|
|
62
|
|
|
DataHandler $tceMain |
|
|
|
|
|
|
63
|
|
|
) { |
|
64
|
|
|
// workspaces: collect garbage only for LIVE workspace |
|
65
|
|
|
if ($command == 'delete' && $GLOBALS['BE_USER']->workspace == 0) { |
|
66
|
|
|
$this->collectGarbage($table, $uid); |
|
67
|
|
|
|
|
68
|
|
|
if ($table == 'pages') { |
|
69
|
|
|
$this->getIndexQueue()->deleteItem($table, $uid); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Holds the configuration when a recursive page queing should be triggered. |
|
76
|
|
|
* |
|
77
|
|
|
* @var array |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
2 |
|
protected function getUpdateSubPagesRecursiveTriggerConfiguration() |
|
81
|
|
|
{ |
|
82
|
|
|
return array( |
|
83
|
|
|
// the current page has the field "extendToSubpages" enabled and the field "hidden" was set to 1 |
|
84
|
|
|
'extendToSubpageEnabledAndHiddenFlagWasAdded' => array( |
|
85
|
|
|
'currentState' => array('extendToSubpages' => '1'), |
|
86
|
|
|
'changeSet' => array('hidden' => '1') |
|
87
|
2 |
|
), |
|
88
|
|
|
// the current page has the field "hidden" enabled and the field "extendToSubpages" was set to 1 |
|
89
|
|
|
'hiddenIsEnabledAndExtendToSubPagesWasAdded' => array( |
|
90
|
|
|
'currentState' => array('hidden' => '1'), |
|
91
|
|
|
'changeSet' => array('extendToSubpages' => '1') |
|
92
|
|
|
) |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Tracks down index documents belonging to a particular record or page and |
|
98
|
|
|
* removes them from the index and the Index Queue. |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $table The record's table name. |
|
101
|
|
|
* @param int $uid The record's uid. |
|
102
|
|
|
* @throws \UnexpectedValueException if a hook object does not implement interface \ApacheSolrForTypo3\Solr\GarbageCollectorPostProcessor |
|
103
|
|
|
*/ |
|
104
|
4 |
|
public function collectGarbage($table, $uid) |
|
105
|
|
|
{ |
|
106
|
4 |
|
if ($table == 'tt_content' || $table == 'pages' || $table == 'pages_language_overlay') { |
|
107
|
4 |
|
$this->collectPageGarbage($table, $uid); |
|
108
|
|
|
} else { |
|
109
|
|
|
$this->collectRecordGarbage($table, $uid); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
4 |
|
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessGarbageCollector'])) { |
|
113
|
|
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessGarbageCollector'] as $classReference) { |
|
114
|
|
|
$garbageCollectorPostProcessor = GeneralUtility::getUserObj($classReference); |
|
115
|
|
|
|
|
116
|
|
|
if ($garbageCollectorPostProcessor instanceof GarbageCollectorPostProcessor) { |
|
117
|
|
|
$garbageCollectorPostProcessor->postProcessGarbageCollector($table, |
|
118
|
|
|
$uid); |
|
119
|
|
|
} else { |
|
120
|
|
|
throw new \UnexpectedValueException( |
|
121
|
|
|
get_class($garbageCollectorPostProcessor) . ' must implement interface ApacheSolrForTypo3\Solr\GarbageCollectorPostProcessor', |
|
122
|
|
|
1345807460 |
|
123
|
|
|
); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
4 |
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Tracks down index documents belonging to a particular page and |
|
131
|
|
|
* removes them from the index and the Index Queue. |
|
132
|
|
|
* |
|
133
|
|
|
* @param string $table The record's table name. |
|
134
|
|
|
* @param int $uid The record's uid. |
|
135
|
|
|
*/ |
|
136
|
4 |
|
protected function collectPageGarbage($table, $uid) |
|
137
|
|
|
{ |
|
138
|
|
|
switch ($table) { |
|
139
|
4 |
|
case 'tt_content': |
|
140
|
|
|
$contentElement = BackendUtility::getRecord('tt_content', $uid, 'uid, pid', '', false); |
|
141
|
|
|
|
|
142
|
|
|
$table = 'pages'; |
|
143
|
|
|
$uid = $contentElement['pid']; |
|
144
|
|
|
|
|
145
|
|
|
$this->deleteIndexDocuments($table, $uid); |
|
146
|
|
|
// only a content element was removed, now update/re-index the page |
|
147
|
|
|
$this->getIndexQueue()->updateItem($table, $uid); |
|
148
|
|
|
break; |
|
149
|
4 |
|
case 'pages_language_overlay': |
|
150
|
|
|
$pageOverlayRecord = BackendUtility::getRecord('pages_language_overlay', $uid, 'uid, pid', '', false); |
|
151
|
|
|
|
|
152
|
|
|
$table = 'pages'; |
|
153
|
|
|
$uid = $pageOverlayRecord['pid']; |
|
154
|
|
|
|
|
155
|
|
|
$this->deleteIndexDocuments($table, $uid); |
|
156
|
|
|
// only a page overlay was removed, now update/re-index the page |
|
157
|
|
|
$this->getIndexQueue()->updateItem($table, $uid); |
|
158
|
|
|
break; |
|
159
|
4 |
|
case 'pages': |
|
160
|
|
|
|
|
161
|
4 |
|
$this->deleteIndexDocuments($table, $uid); |
|
162
|
4 |
|
$this->getIndexQueue()->deleteItem($table, $uid); |
|
163
|
|
|
|
|
164
|
4 |
|
break; |
|
165
|
|
|
} |
|
166
|
4 |
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @param string $table |
|
170
|
|
|
* @param int $uid |
|
171
|
|
|
* @param array $changedFields |
|
172
|
|
|
*/ |
|
173
|
2 |
|
protected function deleteSubpagesWhenExtendToSubpagesIsSet($table, $uid, $changedFields) |
|
174
|
|
|
{ |
|
175
|
2 |
|
if (!$this->isRecursiveUpdateRequired($uid, $changedFields)) { |
|
176
|
|
|
return; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
2 |
|
$indexQueue = $this->getIndexQueue(); |
|
180
|
|
|
// get affected subpages when "extendToSubpages" flag was set |
|
181
|
2 |
|
$pagesToDelete = $this->getSubPageIds($uid); |
|
182
|
|
|
// we need to at least remove this page |
|
183
|
2 |
|
foreach ($pagesToDelete as $pageToDelete) { |
|
184
|
2 |
|
$this->deleteIndexDocuments($table, $pageToDelete); |
|
185
|
2 |
|
$indexQueue->deleteItem($table, $pageToDelete); |
|
186
|
|
|
} |
|
187
|
2 |
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Deletes index documents for a given record identification. |
|
191
|
|
|
* |
|
192
|
|
|
* @param string $table The record's table name. |
|
193
|
|
|
* @param int $uid The record's uid. |
|
194
|
|
|
*/ |
|
195
|
4 |
|
protected function deleteIndexDocuments($table, $uid) |
|
196
|
|
|
{ |
|
197
|
|
|
/** @var $connectionManager ConnectionManager */ |
|
198
|
4 |
|
$connectionManager = GeneralUtility::makeInstance(ConnectionManager::class); |
|
199
|
|
|
|
|
200
|
|
|
// record can be indexed for multiple sites |
|
201
|
4 |
|
$indexQueueItems = $this->getIndexQueue()->getItems($table, $uid); |
|
202
|
4 |
|
foreach ($indexQueueItems as $indexQueueItem) { |
|
203
|
3 |
|
$site = $indexQueueItem->getSite(); |
|
204
|
|
|
$solrConfiguration = $site->getSolrConfiguration(); |
|
205
|
|
|
$enableCommitsSetting = $solrConfiguration->getEnableCommits(); |
|
206
|
3 |
|
|
|
207
|
3 |
|
// a site can have multiple connections (cores / languages) |
|
208
|
3 |
|
$solrConnections = $connectionManager->getConnectionsBySite($site); |
|
209
|
3 |
|
foreach ($solrConnections as $solr) { |
|
210
|
|
|
$solr->deleteByQuery('type:' . $table . ' AND uid:' . intval($uid)); |
|
211
|
|
|
if ($enableCommitsSetting) { |
|
212
|
4 |
|
$solr->commit(false, false, false); |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Tracks down index documents belonging to a particular record and |
|
220
|
|
|
* removes them from the index and the Index Queue. |
|
221
|
|
|
* |
|
222
|
|
|
* @param string $table The record's table name. |
|
223
|
|
|
* @param int $uid The record's uid. |
|
224
|
|
|
*/ |
|
225
|
|
|
protected function collectRecordGarbage($table, $uid) |
|
226
|
|
|
{ |
|
227
|
|
|
$this->deleteIndexDocuments($table, $uid); |
|
228
|
|
|
$this->getIndexQueue()->deleteItem($table, $uid); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
// methods checking whether to trigger garbage collection |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Hooks into TCE main and tracks page move commands. |
|
235
|
|
|
* |
|
236
|
|
|
* @param string $command The command. |
|
237
|
|
|
* @param string $table The table the record belongs to |
|
238
|
|
|
* @param int $uid The record's uid |
|
239
|
|
|
* @param string $value Not used |
|
240
|
|
|
* @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
|
241
|
|
|
*/ |
|
242
|
|
|
public function processCmdmap_postProcess( |
|
243
|
|
|
$command, |
|
244
|
|
|
$table, |
|
245
|
|
|
$uid, |
|
246
|
|
|
$value, |
|
|
|
|
|
|
247
|
|
|
DataHandler $tceMain |
|
|
|
|
|
|
248
|
|
|
) { |
|
249
|
|
|
// workspaces: collect garbage only for LIVE workspace |
|
250
|
|
|
if ($command == 'move' && $table == 'pages' && $GLOBALS['BE_USER']->workspace == 0) { |
|
251
|
|
|
// TODO the below comment is not valid anymore, pid has been removed from doc ID |
|
252
|
|
|
// ...still needed? |
|
253
|
|
|
|
|
254
|
|
|
// must be removed from index since the pid changes and |
|
255
|
|
|
// is part of the Solr document ID |
|
256
|
|
|
$this->collectGarbage($table, $uid); |
|
257
|
|
|
|
|
258
|
|
|
// now re-index with new properties |
|
259
|
|
|
$this->getIndexQueue()->updateItem($table, $uid); |
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* Hooks into TCE main and tracks changed records. In this case the current |
|
265
|
|
|
* record's values are stored to do a change comparison later on for fields |
|
266
|
|
|
* like fe_group. |
|
267
|
|
|
* |
|
268
|
|
|
* @param array $incomingFields An array of incoming fields, new or changed, not used |
|
269
|
|
|
* @param string $table The table the record belongs to |
|
270
|
|
|
* @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...') |
|
271
|
|
|
* @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
|
272
|
|
|
*/ |
|
273
|
|
|
public function processDatamap_preProcessFieldArray( |
|
274
|
|
|
$incomingFields, |
|
|
|
|
|
|
275
|
|
|
$table, |
|
276
|
|
|
$uid, |
|
277
|
|
|
DataHandler $tceMain |
|
|
|
|
|
|
278
|
|
|
) { |
|
279
|
|
|
if (!is_int($uid)) { |
|
280
|
|
|
// a newly created record, skip |
|
281
|
|
|
return; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
if (Util::isDraftRecord($table, $uid)) { |
|
285
|
|
|
// skip workspaces: collect garbage only for LIVE workspace |
|
286
|
|
|
return; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
$visibilityAffectingFields = $this->getVisibilityAffectingFieldsByTable($table); |
|
290
|
|
|
|
|
291
|
|
|
if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']) |
|
292
|
|
|
&& array_key_exists('fe_group', |
|
293
|
|
|
$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']) |
|
294
|
|
|
) { |
|
295
|
|
|
$record = BackendUtility::getRecord( |
|
296
|
|
|
$table, |
|
297
|
|
|
$uid, |
|
298
|
|
|
$visibilityAffectingFields, |
|
299
|
|
|
'', |
|
300
|
|
|
false |
|
301
|
|
|
); |
|
302
|
|
|
$record = $this->normalizeFrontendGroupField($table, $record); |
|
|
|
|
|
|
303
|
|
|
|
|
304
|
|
|
// keep previous state of important fields for later comparison |
|
305
|
|
|
$this->trackedRecords[$table][$uid] = $record; |
|
306
|
|
|
} |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* Compiles a list of visibility affecting fields of a table so that it can |
|
311
|
|
|
* be used in SQL queries. |
|
312
|
2 |
|
* |
|
313
|
|
|
* @param string $table Table name to retrieve visibility affecting fields for |
|
314
|
2 |
|
* @return string Comma separated list of field names that affect the visibility of a record on the website |
|
315
|
|
|
*/ |
|
316
|
2 |
|
protected function getVisibilityAffectingFieldsByTable($table) |
|
317
|
|
|
{ |
|
318
|
2 |
|
static $visibilityAffectingFields; |
|
319
|
2 |
|
|
|
320
|
2 |
|
if (!isset($visibilityAffectingFields[$table])) { |
|
321
|
2 |
|
// we always want to get the uid and pid although they do not affect visibility |
|
322
|
|
|
$fields = array('uid', 'pid'); |
|
323
|
|
|
if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) { |
|
324
|
2 |
|
$fields = array_merge($fields, |
|
325
|
2 |
|
$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']); |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
2 |
|
if (isset($GLOBALS['TCA'][$table]['ctrl']['delete'])) { |
|
329
|
2 |
|
$fields[] = $GLOBALS['TCA'][$table]['ctrl']['delete']; |
|
330
|
2 |
|
} |
|
331
|
|
|
|
|
332
|
|
|
if ($table == 'pages') { |
|
333
|
2 |
|
$fields[] = 'no_search'; |
|
334
|
|
|
$fields[] = 'doktype'; |
|
335
|
|
|
} |
|
336
|
2 |
|
|
|
337
|
|
|
$visibilityAffectingFields[$table] = implode(', ', $fields); |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
return $visibilityAffectingFields[$table]; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* Makes sure that "empty" frontend group fields are always the same value. |
|
345
|
|
|
* |
|
346
|
2 |
|
* @param string $table The record's table name. |
|
347
|
|
|
* @param array $record the record array. |
|
348
|
2 |
|
* @return array The cleaned record |
|
349
|
2 |
|
*/ |
|
350
|
|
|
protected function normalizeFrontendGroupField($table, $record) |
|
351
|
2 |
|
{ |
|
352
|
|
|
if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'])) { |
|
353
|
|
|
$frontendGroupsField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group']; |
|
354
|
|
|
|
|
355
|
|
|
if ($record[$frontendGroupsField] == '') { |
|
356
|
2 |
|
$record[$frontendGroupsField] = '0'; |
|
357
|
|
|
} |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
return $record; |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* Hooks into TCE Main and watches all record updates. If a change is |
|
365
|
|
|
* detected that would remove the record from the website, we try to find |
|
366
|
|
|
* related documents and remove them from the index. |
|
367
|
|
|
* |
|
368
|
|
|
* @param string $status Status of the current operation, 'new' or 'update' |
|
369
|
|
|
* @param string $table The table the record belongs to |
|
370
|
2 |
|
* @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...') |
|
371
|
|
|
* @param array $fields The record's data, not used |
|
372
|
|
|
* @param DataHandler $tceMain TYPO3 Core Engine parent object, not used |
|
373
|
|
|
*/ |
|
374
|
|
|
public function processDatamap_afterDatabaseOperations( |
|
375
|
|
|
$status, |
|
376
|
|
|
$table, |
|
377
|
2 |
|
$uid, |
|
378
|
|
|
array $fields, |
|
379
|
|
|
DataHandler $tceMain |
|
|
|
|
|
|
380
|
|
|
) { |
|
381
|
|
|
if ($status == 'new') { |
|
382
|
2 |
|
// a newly created record, skip |
|
383
|
|
|
return; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
if (Util::isDraftRecord($table, $uid)) { |
|
387
|
2 |
|
// skip workspaces: collect garbage only for LIVE workspace |
|
388
|
|
|
return; |
|
389
|
2 |
|
} |
|
390
|
2 |
|
|
|
391
|
2 |
|
$garbageCollectionRelevantFields = $this->getVisibilityAffectingFieldsByTable($table); |
|
392
|
|
|
|
|
393
|
2 |
|
$record = BackendUtility::getRecord($table, $uid, |
|
394
|
|
|
$garbageCollectionRelevantFields, '', false); |
|
395
|
|
|
$record = $this->normalizeFrontendGroupField($table, $record); |
|
|
|
|
|
|
396
|
|
|
|
|
397
|
|
|
if ($this->isHidden($table, $record) |
|
398
|
|
|
|| (($this->isStartTimeInFuture($table, $record) |
|
399
|
|
|
|| $this->isEndTimeInPast($table, $record)) |
|
400
|
2 |
|
&& $this->isMarkedAsIndexed($table, $record) |
|
401
|
|
|
) |
|
402
|
2 |
|
|| $this->hasFrontendGroupsRemoved($table, $record) |
|
403
|
|
|
|| ($table == 'pages' && $this->isPageExcludedFromSearch($record)) |
|
404
|
2 |
|
|| ($table == 'pages' && !$this->isIndexablePageType($record)) |
|
405
|
2 |
|
) { |
|
406
|
|
|
$this->collectGarbage($table, $uid); |
|
407
|
|
|
|
|
408
|
2 |
|
if ($table == 'pages') { |
|
409
|
|
|
$this->deleteSubpagesWhenExtendToSubpagesIsSet($table, $uid, $fields); |
|
410
|
|
|
} |
|
411
|
|
|
} |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
/** |
|
415
|
|
|
* Checks whether a hidden field exists for the current table and if so |
|
416
|
|
|
* determines whether it is set on the current record. |
|
417
|
|
|
* |
|
418
|
2 |
|
* @param string $table The table name. |
|
419
|
|
|
* @param array $record An array with record fields that may affect visibility. |
|
420
|
2 |
|
* @return bool True if the record is hidden, FALSE otherwise. |
|
421
|
|
|
*/ |
|
422
|
2 |
|
protected function isHidden($table, $record) |
|
423
|
2 |
|
{ |
|
424
|
2 |
|
$hidden = false; |
|
425
|
|
|
|
|
426
|
|
|
if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'])) { |
|
427
|
2 |
|
$hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']; |
|
428
|
|
|
$hidden = (boolean)$record[$hiddenField]; |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
return $hidden; |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
/** |
|
435
|
|
|
* Checks whether a start time field exists for the record's table and if so |
|
436
|
|
|
* determines if a time is set and whether that time is in the future, |
|
437
|
|
|
* making the record invisible on the website. |
|
438
|
|
|
* |
|
439
|
|
|
* @param string $table The table name. |
|
440
|
|
|
* @param array $record An array with record fields that may affect visibility. |
|
441
|
|
|
* @return bool True if the record's start time is in the future, FALSE otherwise. |
|
442
|
|
|
*/ |
|
443
|
|
|
protected function isStartTimeInFuture($table, $record) |
|
444
|
|
|
{ |
|
445
|
|
|
$startTimeInFuture = false; |
|
446
|
|
|
|
|
447
|
|
|
if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'])) { |
|
448
|
|
|
$startTimeField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime']; |
|
449
|
|
|
$startTimeInFuture = $record[$startTimeField] > time(); |
|
450
|
|
|
} |
|
451
|
|
|
|
|
452
|
|
|
return $startTimeInFuture; |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
/** |
|
456
|
|
|
* Checks whether a end time field exists for the record's table and if so |
|
457
|
|
|
* determines if a time is set and whether that time is in the past, |
|
458
|
|
|
* making the record invisible on the website. |
|
459
|
|
|
* |
|
460
|
|
|
* @param string $table The table name. |
|
461
|
|
|
* @param array $record An array with record fields that may affect visibility. |
|
462
|
|
|
* @return bool True if the record's end time is in the past, FALSE otherwise. |
|
463
|
|
|
*/ |
|
464
|
|
|
protected function isEndTimeInPast($table, $record) |
|
465
|
|
|
{ |
|
466
|
|
|
$endTimeInPast = false; |
|
467
|
|
|
|
|
468
|
|
|
if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'])) { |
|
469
|
|
|
$endTimeField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime']; |
|
470
|
|
|
$endTimeInPast = $record[$endTimeField] < time(); |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
return $endTimeInPast; |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
/** |
|
477
|
|
|
* Checks whether the record is in the Index Queue and whether it has been |
|
478
|
|
|
* indexed already. |
|
479
|
|
|
* |
|
480
|
|
|
* @param string $table The table name. |
|
481
|
|
|
* @param array $record An array with record fields that may affect visibility. |
|
482
|
|
|
* @return bool True if the record is marked as being indexed |
|
483
|
|
|
*/ |
|
484
|
|
|
protected function isMarkedAsIndexed($table, $record) |
|
485
|
|
|
{ |
|
486
|
|
|
return $this->getIndexQueue()->containsIndexedItem($table, $record['uid']); |
|
487
|
|
|
} |
|
488
|
4 |
|
|
|
489
|
|
|
/** |
|
490
|
4 |
|
* @return Queue |
|
491
|
|
|
*/ |
|
492
|
|
|
private function getIndexQueue() |
|
493
|
|
|
{ |
|
494
|
|
|
return GeneralUtility::makeInstance(Queue::class); |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* Checks whether the a frontend group field exists for the record and if so |
|
499
|
|
|
* whether groups have been removed from accessing the record thus making |
|
500
|
|
|
* the record invisible to at least some people. |
|
501
|
|
|
* |
|
502
|
|
|
* @param string $table The table name. |
|
503
|
|
|
* @param array $record An array with record fields that may affect visibility. |
|
504
|
|
|
* @return bool TRUE if frontend groups have been removed from access to the record, FALSE otherwise. |
|
505
|
|
|
*/ |
|
506
|
|
|
protected function hasFrontendGroupsRemoved($table, $record) |
|
507
|
|
|
{ |
|
508
|
|
|
$frontendGroupsRemoved = false; |
|
509
|
|
|
|
|
510
|
|
|
if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'])) { |
|
511
|
|
|
$frontendGroupsField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group']; |
|
512
|
|
|
|
|
513
|
|
|
$previousGroups = explode(',', |
|
514
|
|
|
(string)$this->trackedRecords[$table][$record['uid']][$frontendGroupsField]); |
|
515
|
|
|
$currentGroups = explode(',', |
|
516
|
|
|
(string)$record[$frontendGroupsField]); |
|
517
|
|
|
|
|
518
|
|
|
$removedGroups = array_diff($previousGroups, $currentGroups); |
|
519
|
|
|
|
|
520
|
|
|
$frontendGroupsRemoved = (boolean)count($removedGroups); |
|
521
|
|
|
} |
|
522
|
|
|
|
|
523
|
|
|
return $frontendGroupsRemoved; |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
/** |
|
527
|
|
|
* Checks whether the page has been excluded from searching. |
|
528
|
|
|
* |
|
529
|
|
|
* @param array $record An array with record fields that may affect visibility. |
|
530
|
|
|
* @return bool True if the page has been excluded from searching, FALSE otherwise |
|
531
|
|
|
*/ |
|
532
|
|
|
protected function isPageExcludedFromSearch($record) |
|
533
|
|
|
{ |
|
534
|
|
|
return (boolean)$record['no_search']; |
|
535
|
|
|
} |
|
536
|
|
|
|
|
537
|
|
|
/** |
|
538
|
|
|
* Checks whether a page has a page type that can be indexed. |
|
539
|
|
|
* Currently standard pages and mount pages can be indexed. |
|
540
|
|
|
* |
|
541
|
|
|
* @param array $record A page record |
|
542
|
|
|
* @return bool TRUE if the page can be indexed according to its page type, FALSE otherwise |
|
543
|
|
|
*/ |
|
544
|
|
|
protected function isIndexablePageType(array $record) |
|
545
|
|
|
{ |
|
546
|
|
|
return Util::isAllowedPageType($record); |
|
547
|
|
|
} |
|
548
|
|
|
|
|
549
|
|
|
/** |
|
550
|
|
|
* Cleans an index from garbage entries. |
|
551
|
|
|
* |
|
552
|
|
|
* Was used to clean the index from expired documents/past endtime. Solr 4.8 |
|
553
|
|
|
* introduced DocExpirationUpdateProcessor to do that job by itself. |
|
554
|
|
|
* |
|
555
|
|
|
* The method remains as a dummy for possible later cleanups and to prevent |
|
556
|
|
|
* things from breaking if others were using it. |
|
557
|
|
|
* |
|
558
|
|
|
* @deprecated since 6.0 will be removed in 7.0. deletion is done by DocExpirationUpdateProcessor |
|
559
|
|
|
* @param Site $site The site to clean indexes on |
|
560
|
|
|
* @param bool $commitAfterCleanUp Whether to commit right after the clean up, defaults to TRUE |
|
561
|
|
|
* @return void |
|
562
|
|
|
*/ |
|
563
|
|
|
public function cleanIndex(Site $site, $commitAfterCleanUp = true) |
|
|
|
|
|
|
564
|
|
|
{ |
|
565
|
|
|
GeneralUtility::logDeprecatedFunction(); |
|
566
|
|
|
} |
|
567
|
|
|
} |
|
568
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.