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