1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ApacheSolrForTypo3\Solr\IndexQueue; |
4
|
|
|
|
5
|
|
|
/*************************************************************** |
6
|
|
|
* Copyright notice |
7
|
|
|
* |
8
|
|
|
* (c) 2009-2015 Ingo Renner <[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\Domain\Index\Queue\QueueInitializationService; |
29
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\QueueItemRepository; |
30
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\ConfigurationAwareRecordService; |
31
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\RootPageResolver; |
32
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\Statistic\QueueStatistic; |
33
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\Statistic\QueueStatisticsRepository; |
34
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Site\Site; |
35
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; |
36
|
|
|
use ApacheSolrForTypo3\Solr\FrontendEnvironment; |
37
|
|
|
use ApacheSolrForTypo3\Solr\System\Cache\TwoLevelCache; |
38
|
|
|
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; |
39
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
40
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The Indexing Queue. It allows us to decouple from frontend indexing and |
44
|
|
|
* reacting to changes faster. |
45
|
|
|
* |
46
|
|
|
* @author Ingo Renner <[email protected]> |
47
|
|
|
*/ |
48
|
|
|
class Queue |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* @var RootPageResolver |
52
|
|
|
*/ |
53
|
|
|
protected $rootPageResolver; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var ConfigurationAwareRecordService |
57
|
|
|
*/ |
58
|
|
|
protected $recordService; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var \ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager |
62
|
|
|
*/ |
63
|
|
|
protected $logger = null; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var QueueItemRepository |
67
|
|
|
*/ |
68
|
|
|
protected $queueItemRepository; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var QueueStatisticsRepository |
72
|
|
|
*/ |
73
|
|
|
protected $queueStatisticsRepository; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var QueueInitializationService |
77
|
|
|
*/ |
78
|
|
|
protected $queueInitializationService; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var FrontendEnvironment |
82
|
|
|
*/ |
83
|
|
|
protected $frontendEnvironment = null; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Queue constructor. |
87
|
|
|
* @param RootPageResolver|null $rootPageResolver |
88
|
|
|
* @param ConfigurationAwareRecordService|null $recordService |
89
|
|
|
* @param QueueItemRepository|null $queueItemRepository |
90
|
|
|
* @param QueueStatisticsRepository|null $queueStatisticsRepository |
91
|
|
|
* @param QueueInitializationService|null $queueInitializationService |
92
|
|
|
*/ |
93
|
121 |
|
public function __construct( |
94
|
|
|
RootPageResolver $rootPageResolver = null, |
95
|
|
|
ConfigurationAwareRecordService $recordService = null, |
96
|
|
|
QueueItemRepository $queueItemRepository = null, |
97
|
|
|
QueueStatisticsRepository $queueStatisticsRepository = null, |
98
|
|
|
QueueInitializationService $queueInitializationService = null, |
99
|
|
|
FrontendEnvironment $frontendEnvironment = null |
100
|
|
|
) { |
101
|
121 |
|
$this->logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__); |
102
|
121 |
|
$this->rootPageResolver = $rootPageResolver ?? GeneralUtility::makeInstance(RootPageResolver::class); |
103
|
121 |
|
$this->recordService = $recordService ?? GeneralUtility::makeInstance(ConfigurationAwareRecordService::class); |
104
|
121 |
|
$this->queueItemRepository = $queueItemRepository ?? GeneralUtility::makeInstance(QueueItemRepository::class); |
105
|
121 |
|
$this->queueStatisticsRepository = $queueStatisticsRepository ?? GeneralUtility::makeInstance(QueueStatisticsRepository::class); |
106
|
121 |
|
$this->queueInitializationService = $queueInitializationService ?? GeneralUtility::makeInstance(QueueInitializationService::class, /** @scrutinizer ignore-type */ $this); |
107
|
121 |
|
$this->frontendEnvironment = $frontendEnvironment ?? GeneralUtility::makeInstance(FrontendEnvironment::class); |
108
|
121 |
|
} |
109
|
|
|
|
110
|
|
|
// FIXME some of the methods should be renamed to plural forms |
111
|
|
|
// FIXME singular form methods should deal with exactly one item only |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Returns the timestamp of the last indexing run. |
115
|
|
|
* |
116
|
|
|
* @param int $rootPageId The root page uid for which to get |
117
|
|
|
* the last indexed item id |
118
|
|
|
* @return int Timestamp of last index run. |
119
|
|
|
*/ |
120
|
2 |
|
public function getLastIndexTime($rootPageId) |
121
|
|
|
{ |
122
|
2 |
|
$lastIndexTime = 0; |
123
|
|
|
|
124
|
2 |
|
$lastIndexedRow = $this->queueItemRepository->findLastIndexedRow($rootPageId); |
125
|
|
|
|
126
|
2 |
|
if ($lastIndexedRow[0]['indexed']) { |
127
|
1 |
|
$lastIndexTime = $lastIndexedRow[0]['indexed']; |
128
|
|
|
} |
129
|
|
|
|
130
|
2 |
|
return $lastIndexTime; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Returns the uid of the last indexed item in the queue |
135
|
|
|
* |
136
|
|
|
* @param int $rootPageId The root page uid for which to get |
137
|
|
|
* the last indexed item id |
138
|
|
|
* @return int The last indexed item's ID. |
139
|
|
|
*/ |
140
|
3 |
|
public function getLastIndexedItemId($rootPageId) |
141
|
|
|
{ |
142
|
3 |
|
$lastIndexedItemId = 0; |
143
|
|
|
|
144
|
3 |
|
$lastIndexedItemRow = $this->queueItemRepository->findLastIndexedRow($rootPageId); |
145
|
3 |
|
if ($lastIndexedItemRow[0]['uid']) { |
146
|
2 |
|
$lastIndexedItemId = $lastIndexedItemRow[0]['uid']; |
147
|
|
|
} |
148
|
|
|
|
149
|
3 |
|
return $lastIndexedItemId; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return QueueInitializationService |
154
|
|
|
*/ |
155
|
6 |
|
public function getInitializationService() |
156
|
|
|
{ |
157
|
6 |
|
return $this->queueInitializationService; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Marks an item as needing (re)indexing. |
162
|
|
|
* |
163
|
|
|
* Like with Solr itself, there's no add method, just a simple update method |
164
|
|
|
* that handles the adds, too. |
165
|
|
|
* |
166
|
|
|
* The method creates or updates the index queue items for all related rootPageIds. |
167
|
|
|
* |
168
|
|
|
* @param string $itemType The item's type, usually a table name. |
169
|
|
|
* @param string $itemUid The item's uid, usually an integer uid, could be a different value for non-database-record types. |
170
|
|
|
* @param int $forcedChangeTime The change time for the item if set, otherwise value from getItemChangedTime() is used. |
171
|
|
|
* @return int Number of updated/created items |
172
|
|
|
*/ |
173
|
65 |
|
public function updateItem($itemType, $itemUid, $forcedChangeTime = 0) |
174
|
|
|
{ |
175
|
65 |
|
$updateCount = $this->updateOrAddItemForAllRelatedRootPages($itemType, $itemUid, $forcedChangeTime); |
176
|
64 |
|
$updateCount = $this->postProcessIndexQueueUpdateItem($itemType, $itemUid, $updateCount, $forcedChangeTime); |
|
|
|
|
177
|
|
|
|
178
|
64 |
|
return $updateCount; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Updates or add's the item for all relevant root pages. |
183
|
|
|
* |
184
|
|
|
* @param string $itemType The item's type, usually a table name. |
185
|
|
|
* @param string $itemUid The item's uid, usually an integer uid, could be a different value for non-database-record types. |
186
|
|
|
* @param int $forcedChangeTime The change time for the item if set, otherwise value from getItemChangedTime() is used. |
187
|
|
|
* @return int |
188
|
|
|
*/ |
189
|
63 |
|
protected function updateOrAddItemForAllRelatedRootPages($itemType, $itemUid, $forcedChangeTime): int |
190
|
|
|
{ |
191
|
63 |
|
$updateCount = 0; |
192
|
63 |
|
$rootPageIds = $this->rootPageResolver->getResponsibleRootPageIds($itemType, $itemUid); |
|
|
|
|
193
|
62 |
|
foreach ($rootPageIds as $rootPageId) { |
194
|
62 |
|
$skipInvalidRootPage = $rootPageId === 0; |
195
|
62 |
|
if ($skipInvalidRootPage) { |
196
|
|
|
continue; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/* @var SiteRepository $siteRepository */ |
200
|
62 |
|
$siteRepository = GeneralUtility::makeInstance(SiteRepository::class); |
201
|
62 |
|
$solrConfiguration = $siteRepository->getSiteByRootPageId($rootPageId)->getSolrConfiguration(); |
202
|
62 |
|
$indexingConfiguration = $this->recordService->getIndexingConfigurationName($itemType, $itemUid, $solrConfiguration); |
|
|
|
|
203
|
62 |
|
if ($indexingConfiguration === null) { |
204
|
2 |
|
continue; |
205
|
|
|
} |
206
|
61 |
|
$itemInQueueForRootPage = $this->containsItemWithRootPageId($itemType, $itemUid, $rootPageId); |
207
|
61 |
|
if ($itemInQueueForRootPage) { |
208
|
|
|
// update changed time if that item is in the queue already |
209
|
13 |
|
$changedTime = ($forcedChangeTime > 0) ? $forcedChangeTime : $this->getItemChangedTime($itemType, $itemUid); |
210
|
13 |
|
$updatedRows = $this->queueItemRepository->updateExistingItemByItemTypeAndItemUidAndRootPageId($itemType, $itemUid, $rootPageId, $changedTime, $indexingConfiguration); |
|
|
|
|
211
|
|
|
} else { |
212
|
|
|
// add the item since it's not in the queue yet |
213
|
55 |
|
$updatedRows = $this->addNewItem($itemType, $itemUid, $indexingConfiguration, $rootPageId); |
214
|
|
|
} |
215
|
|
|
|
216
|
61 |
|
$updateCount += $updatedRows; |
217
|
|
|
} |
218
|
|
|
|
219
|
62 |
|
return $updateCount; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Executes the updateItem post processing hook. |
224
|
|
|
* |
225
|
|
|
* @param string $itemType |
226
|
|
|
* @param int $itemUid |
227
|
|
|
* @param int $updateCount |
228
|
|
|
* @param int $forcedChangeTime |
229
|
|
|
* @return int |
230
|
|
|
*/ |
231
|
64 |
|
protected function postProcessIndexQueueUpdateItem($itemType, $itemUid, $updateCount, $forcedChangeTime = 0) |
232
|
|
|
{ |
233
|
64 |
|
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessIndexQueueUpdateItem'] ?? null)) { |
234
|
63 |
|
return $updateCount; |
235
|
|
|
} |
236
|
|
|
|
237
|
1 |
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessIndexQueueUpdateItem'] as $classReference) { |
238
|
1 |
|
$updateHandler = $this->getHookImplementation($classReference); |
239
|
1 |
|
$updateCount = $updateHandler->postProcessIndexQueueUpdateItem($itemType, $itemUid, $updateCount, $forcedChangeTime); |
240
|
|
|
} |
241
|
|
|
|
242
|
1 |
|
return $updateCount; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param string $classReference |
247
|
|
|
* @return object |
248
|
|
|
*/ |
249
|
|
|
protected function getHookImplementation($classReference) |
250
|
|
|
{ |
251
|
|
|
return GeneralUtility::makeInstance($classReference); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Finds indexing errors for the current site |
256
|
|
|
* |
257
|
|
|
* @param Site $site |
258
|
|
|
* @return array Error items for the current site's Index Queue |
259
|
|
|
*/ |
260
|
3 |
|
public function getErrorsBySite(Site $site) |
261
|
|
|
{ |
262
|
3 |
|
return $this->queueItemRepository->findErrorsBySite($site); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Resets all the errors for all index queue items. |
267
|
|
|
* |
268
|
|
|
* @return mixed |
269
|
|
|
*/ |
270
|
1 |
|
public function resetAllErrors() |
271
|
|
|
{ |
272
|
1 |
|
return $this->queueItemRepository->flushAllErrors(); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Resets the errors in the index queue for a specific site |
277
|
|
|
* |
278
|
|
|
* @param Site $site |
279
|
|
|
* @return mixed |
280
|
|
|
*/ |
281
|
1 |
|
public function resetErrorsBySite(Site $site) |
282
|
|
|
{ |
283
|
1 |
|
return $this->queueItemRepository->flushErrorsBySite($site); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Resets the error in the index queue for a specific item |
288
|
|
|
* |
289
|
|
|
* @param Item $item |
290
|
|
|
* @return mixed |
291
|
|
|
*/ |
292
|
1 |
|
public function resetErrorByItem(Item $item) |
293
|
|
|
{ |
294
|
1 |
|
return $this->queueItemRepository->flushErrorByItem($item); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Adds an item to the index queue. |
299
|
|
|
* |
300
|
|
|
* Not meant for public use. |
301
|
|
|
* |
302
|
|
|
* @param string $itemType The item's type, usually a table name. |
303
|
|
|
* @param string $itemUid The item's uid, usually an integer uid, could be a |
304
|
|
|
* different value for non-database-record types. |
305
|
|
|
* @param string $indexingConfiguration The item's indexing configuration to use. |
306
|
|
|
* Optional, overwrites existing / determined configuration. |
307
|
|
|
* @param $rootPageId |
308
|
|
|
* @return int |
309
|
|
|
*/ |
310
|
55 |
|
private function addNewItem($itemType, $itemUid, $indexingConfiguration, $rootPageId) |
311
|
|
|
{ |
312
|
55 |
|
$additionalRecordFields = ''; |
313
|
55 |
|
if ($itemType === 'pages') { |
314
|
32 |
|
$additionalRecordFields = ', doktype, uid'; |
315
|
|
|
} |
316
|
|
|
|
317
|
55 |
|
$record = $this->getRecordCached($itemType, $itemUid, $additionalRecordFields); |
318
|
|
|
|
319
|
55 |
|
if (empty($record) || ($itemType === 'pages' && !$this->frontendEnvironment->isAllowedPageType($record, $indexingConfiguration))) { |
320
|
|
|
return 0; |
321
|
|
|
} |
322
|
|
|
|
323
|
55 |
|
$changedTime = $this->getItemChangedTime($itemType, $itemUid); |
324
|
|
|
|
325
|
55 |
|
return $this->queueItemRepository->add($itemType, $itemUid, $rootPageId, $changedTime, $indexingConfiguration); |
|
|
|
|
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Get record to be added in addNewItem |
330
|
|
|
* |
331
|
|
|
* @param string $itemType The item's type, usually a table name. |
332
|
|
|
* @param string $itemUid The item's uid, usually an integer uid, could be a |
333
|
|
|
* different value for non-database-record types. |
334
|
|
|
* @param string $additionalRecordFields for sql-query |
335
|
|
|
* |
336
|
|
|
* @return array|NULL |
337
|
|
|
*/ |
338
|
55 |
|
protected function getRecordCached($itemType, $itemUid, $additionalRecordFields) |
339
|
|
|
{ |
340
|
55 |
|
$cache = GeneralUtility::makeInstance(TwoLevelCache::class, /** @scrutinizer ignore-type */ 'runtime'); |
341
|
55 |
|
$cacheId = md5('Queue' . ':' . 'getRecordCached' . ':' . $itemType . ':' . $itemUid . ':' . 'pid' . $additionalRecordFields); |
342
|
|
|
|
343
|
55 |
|
$record = $cache->get($cacheId); |
344
|
55 |
|
if (empty($record)) { |
345
|
55 |
|
$record = BackendUtility::getRecord($itemType, $itemUid, 'pid' . $additionalRecordFields); |
346
|
55 |
|
$cache->set($cacheId, $record); |
347
|
|
|
} |
348
|
|
|
|
349
|
55 |
|
return $record; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Determines the time for when an item should be indexed. This timestamp |
354
|
|
|
* is then stored in the changed column in the Index Queue. |
355
|
|
|
* |
356
|
|
|
* The changed timestamp usually is now - time(). For records which are set |
357
|
|
|
* to published at a later time, this timestamp is the start time. So if a |
358
|
|
|
* future start time has been set, that will be used to delay indexing |
359
|
|
|
* of an item. |
360
|
|
|
* |
361
|
|
|
* @param string $itemType The item's table name. |
362
|
|
|
* @param string $itemUid The item's uid, usually an integer uid, could be a |
363
|
|
|
* different value for non-database-record types. |
364
|
|
|
* @return int Timestamp of the item's changed time or future start time |
365
|
|
|
*/ |
366
|
61 |
|
protected function getItemChangedTime($itemType, $itemUid) |
367
|
|
|
{ |
368
|
61 |
|
$itemTypeHasStartTimeColumn = false; |
369
|
61 |
|
$changedTimeColumns = $GLOBALS['TCA'][$itemType]['ctrl']['tstamp']; |
370
|
61 |
|
$startTime = 0; |
371
|
61 |
|
$pageChangedTime = 0; |
372
|
|
|
|
373
|
61 |
|
if (!empty($GLOBALS['TCA'][$itemType]['ctrl']['enablecolumns']['starttime'])) { |
374
|
61 |
|
$itemTypeHasStartTimeColumn = true; |
375
|
61 |
|
$changedTimeColumns .= ', ' . $GLOBALS['TCA'][$itemType]['ctrl']['enablecolumns']['starttime']; |
376
|
|
|
} |
377
|
61 |
|
if ($itemType === 'pages') { |
378
|
|
|
// does not carry time information directly, but needed to support |
379
|
|
|
// canonical pages |
380
|
38 |
|
$changedTimeColumns .= ', content_from_pid'; |
381
|
|
|
} |
382
|
|
|
|
383
|
61 |
|
$record = BackendUtility::getRecord($itemType, $itemUid, $changedTimeColumns); |
384
|
61 |
|
$itemChangedTime = $record[$GLOBALS['TCA'][$itemType]['ctrl']['tstamp']]; |
385
|
|
|
|
386
|
61 |
|
if ($itemTypeHasStartTimeColumn) { |
387
|
61 |
|
$startTime = $record[$GLOBALS['TCA'][$itemType]['ctrl']['enablecolumns']['starttime']]; |
388
|
|
|
} |
389
|
|
|
|
390
|
61 |
|
if ($itemType === 'pages') { |
391
|
38 |
|
$record['uid'] = $itemUid; |
392
|
|
|
// overrule the page's last changed time with the most recent |
393
|
|
|
//content element change |
394
|
38 |
|
$pageChangedTime = $this->getPageItemChangedTime($record); |
|
|
|
|
395
|
|
|
} |
396
|
|
|
|
397
|
61 |
|
$localizationsChangedTime = $this->queueItemRepository->getLocalizableItemChangedTime($itemType, (int)$itemUid); |
398
|
|
|
|
399
|
|
|
// if start time exists and start time is higher than last changed timestamp |
400
|
|
|
// then set changed to the future start time to make the item |
401
|
|
|
// indexed at a later time |
402
|
61 |
|
$changedTime = max( |
403
|
61 |
|
$itemChangedTime, |
404
|
|
|
$pageChangedTime, |
405
|
|
|
$localizationsChangedTime, |
406
|
|
|
$startTime |
407
|
|
|
); |
408
|
|
|
|
409
|
61 |
|
return $changedTime; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* Gets the most recent changed time of a page's content elements |
414
|
|
|
* |
415
|
|
|
* @param array $page Partial page record |
416
|
|
|
* @return int Timestamp of the most recent content element change |
417
|
|
|
*/ |
418
|
38 |
|
protected function getPageItemChangedTime(array $page) |
419
|
|
|
{ |
420
|
38 |
|
if (!empty($page['content_from_pid'])) { |
421
|
|
|
// canonical page, get the original page's last changed time |
422
|
|
|
return $this->queueItemRepository->getPageItemChangedTimeByPageUid((int)$page['content_from_pid']); |
423
|
|
|
} |
424
|
38 |
|
return $this->queueItemRepository->getPageItemChangedTimeByPageUid((int)$page['uid']); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
/** |
428
|
|
|
* Checks whether the Index Queue contains a specific item. |
429
|
|
|
* |
430
|
|
|
* @param string $itemType The item's type, usually a table name. |
431
|
|
|
* @param string $itemUid The item's uid, usually an integer uid, could be a |
432
|
|
|
* different value for non-database-record types. |
433
|
|
|
* @return bool TRUE if the item is found in the queue, FALSE otherwise |
434
|
|
|
*/ |
435
|
8 |
|
public function containsItem($itemType, $itemUid) |
436
|
|
|
{ |
437
|
8 |
|
return $this->queueItemRepository->containsItem($itemType, (int)$itemUid); |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* Checks whether the Index Queue contains a specific item. |
442
|
|
|
* |
443
|
|
|
* @param string $itemType The item's type, usually a table name. |
444
|
|
|
* @param string $itemUid The item's uid, usually an integer uid, could be a |
445
|
|
|
* different value for non-database-record types. |
446
|
|
|
* @param integer $rootPageId |
447
|
|
|
* @return bool TRUE if the item is found in the queue, FALSE otherwise |
448
|
|
|
*/ |
449
|
61 |
|
public function containsItemWithRootPageId($itemType, $itemUid, $rootPageId) |
450
|
|
|
{ |
451
|
61 |
|
return $this->queueItemRepository->containsItemWithRootPageId($itemType, (int)$itemUid, (int)$rootPageId); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* Checks whether the Index Queue contains a specific item that has been |
456
|
|
|
* marked as indexed. |
457
|
|
|
* |
458
|
|
|
* @param string $itemType The item's type, usually a table name. |
459
|
|
|
* @param string $itemUid The item's uid, usually an integer uid, could be a |
460
|
|
|
* different value for non-database-record types. |
461
|
|
|
* @return bool TRUE if the item is found in the queue and marked as |
462
|
|
|
* indexed, FALSE otherwise |
463
|
|
|
*/ |
464
|
2 |
|
public function containsIndexedItem($itemType, $itemUid) |
465
|
|
|
{ |
466
|
2 |
|
return $this->queueItemRepository->containsIndexedItem($itemType, (int)$itemUid); |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* Removes an item from the Index Queue. |
471
|
|
|
* |
472
|
|
|
* @param string $itemType The type of the item to remove, usually a table name. |
473
|
|
|
* @param int $itemUid The uid of the item to remove |
474
|
|
|
*/ |
475
|
34 |
|
public function deleteItem($itemType, $itemUid) |
476
|
|
|
{ |
477
|
34 |
|
$this->queueItemRepository->deleteItem($itemType, (int)$itemUid); |
478
|
34 |
|
} |
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* Removes all items of a certain type from the Index Queue. |
482
|
|
|
* |
483
|
|
|
* @param string $itemType The type of items to remove, usually a table name. |
484
|
|
|
*/ |
485
|
1 |
|
public function deleteItemsByType($itemType) |
486
|
|
|
{ |
487
|
1 |
|
$this->queueItemRepository->deleteItemsByType($itemType); |
488
|
1 |
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Removes all items of a certain site from the Index Queue. Accepts an |
492
|
|
|
* optional parameter to limit the deleted items by indexing configuration. |
493
|
|
|
* |
494
|
|
|
* @param Site $site The site to remove items for. |
495
|
|
|
* @param string $indexingConfigurationName Name of a specific indexing |
496
|
|
|
* configuration |
497
|
|
|
*/ |
498
|
6 |
|
public function deleteItemsBySite(Site $site, $indexingConfigurationName = '') |
499
|
|
|
{ |
500
|
6 |
|
$this->queueItemRepository->deleteItemsBySite($site, $indexingConfigurationName); |
501
|
6 |
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* Removes all items from the Index Queue. |
505
|
|
|
* |
506
|
|
|
*/ |
507
|
1 |
|
public function deleteAllItems() |
508
|
|
|
{ |
509
|
1 |
|
$this->queueItemRepository->deleteAllItems(); |
510
|
1 |
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Gets a single Index Queue item by its uid. |
514
|
|
|
* |
515
|
|
|
* @param int $itemId Index Queue item uid |
516
|
|
|
* @return Item|null The request Index Queue item or NULL if no item with $itemId was found |
517
|
|
|
*/ |
518
|
26 |
|
public function getItem(int $itemId): ?Item |
519
|
|
|
{ |
520
|
26 |
|
return $this->queueItemRepository->findItemByUid($itemId); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* Gets Index Queue items by type and uid. |
525
|
|
|
* |
526
|
|
|
* @param string $itemType item type, usually the table name |
527
|
|
|
* @param int $itemUid item uid |
528
|
|
|
* @return Item[] An array of items matching $itemType and $itemUid |
529
|
|
|
*/ |
530
|
39 |
|
public function getItems($itemType, $itemUid) |
531
|
|
|
{ |
532
|
39 |
|
return $this->queueItemRepository->findItemsByItemTypeAndItemUid($itemType, (int)$itemUid); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* Returns all items in the queue. |
537
|
|
|
* |
538
|
|
|
* @return Item[] An array of items |
539
|
|
|
*/ |
540
|
|
|
public function getAllItems() |
541
|
|
|
{ |
542
|
|
|
return $this->queueItemRepository->findAll(); |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
/** |
546
|
|
|
* Returns the number of items for all queues. |
547
|
|
|
* |
548
|
|
|
* @return int |
549
|
|
|
*/ |
550
|
79 |
|
public function getAllItemsCount() |
551
|
|
|
{ |
552
|
79 |
|
return $this->queueItemRepository->count(); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
/** |
556
|
|
|
* Extracts the number of pending, indexed and erroneous items from the |
557
|
|
|
* Index Queue. |
558
|
|
|
* |
559
|
|
|
* @param Site $site |
560
|
|
|
* @param string $indexingConfigurationName |
561
|
|
|
* |
562
|
|
|
* @return QueueStatistic |
563
|
|
|
*/ |
564
|
5 |
|
public function getStatisticsBySite(Site $site, $indexingConfigurationName = '') |
565
|
|
|
{ |
566
|
5 |
|
return $this->queueStatisticsRepository->findOneByRootPidAndOptionalIndexingConfigurationName($site->getRootPageId(), $indexingConfigurationName); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* Gets $limit number of items to index for a particular $site. |
571
|
|
|
* |
572
|
|
|
* @param Site $site TYPO3 site |
573
|
|
|
* @param int $limit Number of items to get from the queue |
574
|
|
|
* @return Item[] Items to index to the given solr server |
575
|
|
|
*/ |
576
|
3 |
|
public function getItemsToIndex(Site $site, $limit = 50) |
577
|
|
|
{ |
578
|
3 |
|
return $this->queueItemRepository->findItemsToIndex($site, $limit); |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
/** |
582
|
|
|
* Marks an item as failed and causes the indexer to skip the item in the |
583
|
|
|
* next run. |
584
|
|
|
* |
585
|
|
|
* @param int|Item $item Either the item's Index Queue uid or the complete item |
586
|
|
|
* @param string $errorMessage Error message |
587
|
|
|
*/ |
588
|
6 |
|
public function markItemAsFailed($item, $errorMessage = '') |
589
|
|
|
{ |
590
|
6 |
|
$this->queueItemRepository->markItemAsFailed($item, $errorMessage); |
591
|
6 |
|
} |
592
|
|
|
|
593
|
|
|
/** |
594
|
|
|
* Sets the timestamp of when an item last has been indexed. |
595
|
|
|
* |
596
|
|
|
* @param Item $item |
597
|
|
|
*/ |
598
|
2 |
|
public function updateIndexTimeByItem(Item $item) |
599
|
|
|
{ |
600
|
2 |
|
$this->queueItemRepository->updateIndexTimeByItem($item); |
601
|
2 |
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* Sets the change timestamp of an item. |
605
|
|
|
* |
606
|
|
|
* @param Item $item |
607
|
|
|
* @param int $forcedChangeTime The change time for the item |
608
|
|
|
*/ |
609
|
|
|
public function setForcedChangeTimeByItem(Item $item, $forcedChangeTime) |
610
|
|
|
{ |
611
|
|
|
$this->queueItemRepository->updateChangedTimeByItem($item, $forcedChangeTime); |
612
|
|
|
} |
613
|
|
|
} |
614
|
|
|
|