Passed
Push — master ( a5d0a9...8581cd )
by Timo
23:17
created

Queue::setForcedChangeTimeByItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
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 3 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\QueueInitializationService;
28
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\QueueItemRepository;
29
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\ConfigurationAwareRecordService;
30
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\RootPageResolver;
31
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\Statistic\QueueStatistic;
32
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\Statistic\QueueStatisticsRepository;
33
use ApacheSolrForTypo3\Solr\Site;
34
use ApacheSolrForTypo3\Solr\System\Cache\TwoLevelCache;
35
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
36
use ApacheSolrForTypo3\Solr\Util;
37
use TYPO3\CMS\Backend\Utility\BackendUtility;
38
use TYPO3\CMS\Core\Utility\GeneralUtility;
39
40
/**
41
 * The Indexing Queue. It allows us to decouple from frontend indexing and
42
 * reacting to changes faster.
43
 *
44
 * @author Ingo Renner <[email protected]>
45
 */
46
class Queue
47
{
48
    /**
49
     * @var RootPageResolver
50
     */
51
    protected $rootPageResolver;
52
53
    /**
54
     * @var ConfigurationAwareRecordService
55
     */
56
    protected $recordService;
57
58
    /**
59
     * @var \ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager
60
     */
61
    protected $logger = null;
62
63
    /**
64
     * @var QueueItemRepository
65
     */
66
    protected $queueItemRepository;
67
68
    /**
69
     * @var QueueStatisticsRepository
70
     */
71
    protected $queueStatisticsRepository;
72
73
    /**
74
     * @var QueueInitializationService
75
     */
76
    protected $queueInitializationService;
77
78
    /**
79
     * Queue constructor.
80
     * @param RootPageResolver|null $rootPageResolver
81
     * @param ConfigurationAwareRecordService|null $recordService
82
     * @param QueueItemRepository|null $queueItemRepository
83
     * @param QueueStatisticsRepository|null $queueStatisticsRepository
84
     * @param QueueInitializationService|null $queueInitializationService
85
     */
86 108
    public function __construct(RootPageResolver $rootPageResolver = null, ConfigurationAwareRecordService $recordService = null, QueueItemRepository $queueItemRepository = null, QueueStatisticsRepository $queueStatisticsRepository = null, QueueInitializationService $queueInitializationService = null)
87
    {
88 108
        $this->logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
89 108
        $this->rootPageResolver = $rootPageResolver ?? GeneralUtility::makeInstance(RootPageResolver::class);
90 108
        $this->recordService = $recordService ?? GeneralUtility::makeInstance(ConfigurationAwareRecordService::class);
91 108
        $this->queueItemRepository = $queueItemRepository ?? GeneralUtility::makeInstance(QueueItemRepository::class);
92 108
        $this->queueStatisticsRepository = $queueStatisticsRepository ??  GeneralUtility::makeInstance(QueueStatisticsRepository::class);
93 108
        $this->queueInitializationService = $queueInitializationService ?? GeneralUtility::makeInstance(QueueInitializationService::class, /** @scrutinizer ignore-type */ $this);
94 108
    }
95
96
    // FIXME some of the methods should be renamed to plural forms
97
    // FIXME singular form methods should deal with exactly one item only
98
99
    /**
100
     * Returns the timestamp of the last indexing run.
101
     *
102
     * @param int $rootPageId The root page uid for which to get
103
     *      the last indexed item id
104
     * @return int Timestamp of last index run.
105
     */
106 2
    public function getLastIndexTime($rootPageId)
107
    {
108 2
        $lastIndexTime = 0;
109
110 2
        $lastIndexedRow = $this->queueItemRepository->findLastIndexedRow($rootPageId);
111
112 2
        if ($lastIndexedRow[0]['indexed']) {
113 1
            $lastIndexTime = $lastIndexedRow[0]['indexed'];
114
        }
115
116 2
        return $lastIndexTime;
117
    }
118
119
    /**
120
     * Returns the uid of the last indexed item in the queue
121
     *
122
     * @param int $rootPageId The root page uid for which to get
123
     *      the last indexed item id
124
     * @return int The last indexed item's ID.
125
     */
126 3
    public function getLastIndexedItemId($rootPageId)
127
    {
128 3
        $lastIndexedItemId = 0;
129
130 3
        $lastIndexedItemRow = $this->queueItemRepository->findLastIndexedRow($rootPageId);
131 3
        if ($lastIndexedItemRow[0]['uid']) {
132 2
            $lastIndexedItemId = $lastIndexedItemRow[0]['uid'];
133
        }
134
135 3
        return $lastIndexedItemId;
136
    }
137
138
    /**
139
     * @return QueueInitializationService
140
     */
141 6
    public function getInitializationService()
142
    {
143 6
        return $this->queueInitializationService;
144
    }
145
146
    /**
147
     * Truncate and rebuild the tx_solr_indexqueue_item table. This is the most
148
     * complete way to force reindexing, or to build the Index Queue for the
149
     * first time. The Index Queue initialization is site-specific.
150
     *
151
     * @deprecated Deprecated sine 8.1.0 will be removed in 9.0.0 please use QueueInitializationService::initializeBySiteAndIndexConfiguration now
152
     * @param Site $site The site to initialize
153
     * @param string $indexingConfigurationName Name of a specific
154
     *      indexing configuration
155
     * @return array An array of booleans, each representing whether the
156
     *      initialization for an indexing configuration was successful
157
     */
158
    public function initialize(Site $site, $indexingConfigurationName = '')
159
    {
160
        trigger_error('Queue::initialize is deprecated please use QueueInitializationService::initializeBySiteAndIndexConfiguration now. Deprecated since 8.1.0 will be removed in 9.0.0', E_USER_DEPRECATED);
161
        // for backwards compatibility we convert '*' to the wildcard argument
162
        $indexingConfigurationName = $indexingConfigurationName === '' ? '*' : $indexingConfigurationName;
163
        return $this->queueInitializationService->initializeBySiteAndIndexConfiguration($site, $indexingConfigurationName);
164
    }
165
166
    /**
167
     * Initializes a set index configurations for a given site.
168
     *
169
     * @deprecated Deprecated sine 8.1.0 will be removed in 9.0.0 please use QueueInitializationService::initializeBySiteAndIndexConfigurations now
170
     * @param Site $site
171
     * @param array $indexingConfigurationNames
172
     * @return array An array of booleans, each representing whether the
173
     *      initialization for an indexing configuration was successful
174
     */
175
    public function initializeIndexingConfigurations(Site $site, array $indexingConfigurationNames)
176
    {
177
        trigger_error('Queue::initializeIndexingConfigurations is deprecated please use QueueInitializationService::initializeBySiteAndIndexConfigurations now. Deprecated since 8.1.0 will be removed in 9.0.0', E_USER_DEPRECATED);
178
        return $this->queueInitializationService->initializeBySiteAndIndexConfigurations($site, $indexingConfigurationNames);
179
    }
180
181
    /**
182
     * Marks an item as needing (re)indexing.
183
     *
184
     * Like with Solr itself, there's no add method, just a simple update method
185
     * that handles the adds, too.
186
     *
187
     * The method creates or updates the index queue items for all related rootPageIds.
188
     *
189
     * @param string $itemType The item's type, usually a table name.
190
     * @param string $itemUid The item's uid, usually an integer uid, could be a different value for non-database-record types.
191
     * @param int $forcedChangeTime The change time for the item if set, otherwise value from getItemChangedTime() is used.
192
     * @return int Number of updated/created items
193
     */
194 61
    public function updateItem($itemType, $itemUid, $forcedChangeTime = 0)
195
    {
196 61
        $updateCount = $this->updateOrAddItemForAllRelatedRootPages($itemType, $itemUid, $forcedChangeTime);
197 60
        $updateCount = $this->postProcessIndexQueueUpdateItem($itemType, $itemUid, $updateCount, $forcedChangeTime);
0 ignored issues
show
Bug introduced by
$itemUid of type string is incompatible with the type integer expected by parameter $itemUid of ApacheSolrForTypo3\Solr\...sIndexQueueUpdateItem(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

197
        $updateCount = $this->postProcessIndexQueueUpdateItem($itemType, /** @scrutinizer ignore-type */ $itemUid, $updateCount, $forcedChangeTime);
Loading history...
198
199 60
        return $updateCount;
200
    }
201
202
    /**
203
     * Updates or add's the item for all relevant root pages.
204
     *
205
     * @param string $itemType The item's type, usually a table name.
206
     * @param string $itemUid The item's uid, usually an integer uid, could be a different value for non-database-record types.
207
     * @param int $forcedChangeTime The change time for the item if set, otherwise value from getItemChangedTime() is used.
208
     * @return int
209
     */
210 59
    protected function updateOrAddItemForAllRelatedRootPages($itemType, $itemUid, $forcedChangeTime): int
211
    {
212 59
        $updateCount = 0;
213 59
        $rootPageIds = $this->rootPageResolver->getResponsibleRootPageIds($itemType, $itemUid);
0 ignored issues
show
Bug introduced by
$itemUid of type string is incompatible with the type integer expected by parameter $uid of ApacheSolrForTypo3\Solr\...esponsibleRootPageIds(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

213
        $rootPageIds = $this->rootPageResolver->getResponsibleRootPageIds($itemType, /** @scrutinizer ignore-type */ $itemUid);
Loading history...
214 58
        foreach ($rootPageIds as $rootPageId) {
215 58
            $skipInvalidRootPage = $rootPageId === 0;
216 58
            if ($skipInvalidRootPage) {
217
                continue;
218
            }
219
220 58
            $solrConfiguration = Util::getSolrConfigurationFromPageId($rootPageId);
221 58
            $indexingConfiguration = $this->recordService->getIndexingConfigurationName($itemType, $itemUid, $solrConfiguration);
0 ignored issues
show
Bug introduced by
$itemUid of type string is incompatible with the type integer expected by parameter $recordUid of ApacheSolrForTypo3\Solr\...xingConfigurationName(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

221
            $indexingConfiguration = $this->recordService->getIndexingConfigurationName($itemType, /** @scrutinizer ignore-type */ $itemUid, $solrConfiguration);
Loading history...
222 58
            $itemInQueueForRootPage = $this->containsItemWithRootPageId($itemType, $itemUid, $rootPageId);
223 58
            if ($itemInQueueForRootPage) {
224
                // update changed time if that item is in the queue already
225 11
                $changedTime = ($forcedChangeTime > 0) ? $forcedChangeTime : $this->getItemChangedTime($itemType, $itemUid);
226 11
                $updatedRows = $this->queueItemRepository->updateExistingItemByItemTypeAndItemUidAndRootPageId($itemType, $itemUid, $rootPageId, $changedTime, $indexingConfiguration);
0 ignored issues
show
Bug introduced by
$itemUid of type string is incompatible with the type integer expected by parameter $itemUid of ApacheSolrForTypo3\Solr\...dItemUidAndRootPageId(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

226
                $updatedRows = $this->queueItemRepository->updateExistingItemByItemTypeAndItemUidAndRootPageId($itemType, /** @scrutinizer ignore-type */ $itemUid, $rootPageId, $changedTime, $indexingConfiguration);
Loading history...
227
            } else {
228
                // add the item since it's not in the queue yet
229 52
                $updatedRows = $this->addNewItem($itemType, $itemUid, $indexingConfiguration, $rootPageId);
230
            }
231
232 58
            $updateCount += $updatedRows;
233
        }
234
235 58
        return $updateCount;
236
    }
237
238
    /**
239
     * Executes the updateItem post processing hook.
240
     *
241
     * @param string $itemType
242
     * @param int $itemUid
243
     * @param int $updateCount
244
     * @param int $forcedChangeTime
245
     * @return int
246
     */
247 60
    protected function postProcessIndexQueueUpdateItem($itemType, $itemUid, $updateCount, $forcedChangeTime = 0)
248
    {
249 60
        if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessIndexQueueUpdateItem'])) {
250 59
            return $updateCount;
251
        }
252
253 1
        foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessIndexQueueUpdateItem'] as $classReference) {
254 1
            $updateHandler = $this->getHookImplementation($classReference);
255 1
            $updateCount = $updateHandler->postProcessIndexQueueUpdateItem($itemType, $itemUid, $updateCount, $forcedChangeTime);
256
        }
257
258 1
        return $updateCount;
259
    }
260
261
    /**
262
     * @param string $classReference
263
     * @return object
264
     */
265
    protected function getHookImplementation($classReference)
266
    {
267
        return GeneralUtility::makeInstance($classReference);
268
    }
269
270
    /**
271
     * Finds indexing errors for the current site
272
     *
273
     * @param Site $site
274
     * @return array Error items for the current site's Index Queue
275
     */
276 2
    public function getErrorsBySite(Site $site)
277
    {
278 2
        return $this->queueItemRepository->findErrorsBySite($site);
279
    }
280
281
    /**
282
     * Resets all the errors for all index queue items.
283
     *
284
     * @return mixed
285
     */
286 1
    public function resetAllErrors()
287
    {
288 1
        return $this->queueItemRepository->flushAllErrors();
289
    }
290
291
    /**
292
     * Resets the errors in the index queue for a specific site
293
     *
294
     * @param Site $site
295
     * @return mixed
296
     */
297 1
    public function resetErrorsBySite(Site $site)
298
    {
299 1
        return $this->queueItemRepository->flushErrorsBySite($site);
300
    }
301
302
    /**
303
     * Adds an item to the index queue.
304
     *
305
     * Not meant for public use.
306
     *
307
     * @param string $itemType The item's type, usually a table name.
308
     * @param string $itemUid The item's uid, usually an integer uid, could be a
309
     *      different value for non-database-record types.
310
     * @param string $indexingConfiguration The item's indexing configuration to use.
311
     *      Optional, overwrites existing / determined configuration.
312
     * @param $rootPageId
313
     * @return int
314
     */
315 52
    private function addNewItem($itemType, $itemUid, $indexingConfiguration, $rootPageId)
316
    {
317 52
        $additionalRecordFields = '';
318 52
        if ($itemType === 'pages') {
319 30
            $additionalRecordFields = ', doktype, uid';
320
        }
321
322 52
        $record = $this->getRecordCached($itemType, $itemUid, $additionalRecordFields);
323
324 52
        if (empty($record) || ($itemType === 'pages' && !Util::isAllowedPageType($record, $indexingConfiguration))) {
325 1
            return 0;
326
        }
327
328 51
        $changedTime = $this->getItemChangedTime($itemType, $itemUid);
329
330 51
        return $this->queueItemRepository->add($itemType, $itemUid, $rootPageId, $changedTime, $indexingConfiguration);
0 ignored issues
show
Bug introduced by
$itemUid of type string is incompatible with the type integer expected by parameter $itemUid of ApacheSolrForTypo3\Solr\...ueItemRepository::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

330
        return $this->queueItemRepository->add($itemType, /** @scrutinizer ignore-type */ $itemUid, $rootPageId, $changedTime, $indexingConfiguration);
Loading history...
331
    }
332
333
    /**
334
     * Get record to be added in addNewItem
335
     *
336
     * @param string $itemType The item's type, usually a table name.
337
     * @param string $itemUid The item's uid, usually an integer uid, could be a
338
     *      different value for non-database-record types.
339
     * @param string $additionalRecordFields for sql-query
340
     *
341
     * @return array|NULL
342
     */
343 52
    protected function getRecordCached($itemType, $itemUid, $additionalRecordFields)
344
    {
345 52
        $cache = GeneralUtility::makeInstance(TwoLevelCache::class, /** @scrutinizer ignore-type */ 'cache_runtime');
346 52
        $cacheId = md5('Queue' . ':' . 'getRecordCached' . ':' . $itemType . ':' . $itemUid . ':' . 'pid' . $additionalRecordFields);
347
348 52
        $record = $cache->get($cacheId);
349 52
        if (empty($record)) {
350 52
            $record = BackendUtility::getRecord($itemType, $itemUid, 'pid' . $additionalRecordFields);
0 ignored issues
show
Bug introduced by
$itemUid of type string is incompatible with the type integer expected by parameter $uid of TYPO3\CMS\Backend\Utilit...endUtility::getRecord(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

350
            $record = BackendUtility::getRecord($itemType, /** @scrutinizer ignore-type */ $itemUid, 'pid' . $additionalRecordFields);
Loading history...
351 52
            $cache->set($cacheId, $record);
352
        }
353
354 52
        return $record;
355
    }
356
357
    /**
358
     * Determines the time for when an item should be indexed. This timestamp
359
     * is then stored in the changed column in the Index Queue.
360
     *
361
     * The changed timestamp usually is now - time(). For records which are set
362
     * to published at a later time, this timestamp is the start time. So if a
363
     * future start time has been set, that will be used to delay indexing
364
     * of an item.
365
     *
366
     * @param string $itemType The item's table name.
367
     * @param string $itemUid The item's uid, usually an integer uid, could be a
368
     *      different value for non-database-record types.
369
     * @return int Timestamp of the item's changed time or future start time
370
     */
371 57
    protected function getItemChangedTime($itemType, $itemUid)
372
    {
373 57
        $itemTypeHasStartTimeColumn = false;
374 57
        $changedTimeColumns = $GLOBALS['TCA'][$itemType]['ctrl']['tstamp'];
375 57
        $startTime = 0;
376 57
        $pageChangedTime = 0;
377
378 57
        if (!empty($GLOBALS['TCA'][$itemType]['ctrl']['enablecolumns']['starttime'])) {
379 57
            $itemTypeHasStartTimeColumn = true;
380 57
            $changedTimeColumns .= ', ' . $GLOBALS['TCA'][$itemType]['ctrl']['enablecolumns']['starttime'];
381
        }
382 57
        if ($itemType === 'pages') {
383
            // does not carry time information directly, but needed to support
384
            // canonical pages
385 35
            $changedTimeColumns .= ', content_from_pid';
386
        }
387
388 57
        $record = BackendUtility::getRecord($itemType, $itemUid, $changedTimeColumns);
0 ignored issues
show
Bug introduced by
$itemUid of type string is incompatible with the type integer expected by parameter $uid of TYPO3\CMS\Backend\Utilit...endUtility::getRecord(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

388
        $record = BackendUtility::getRecord($itemType, /** @scrutinizer ignore-type */ $itemUid, $changedTimeColumns);
Loading history...
389 57
        $itemChangedTime = $record[$GLOBALS['TCA'][$itemType]['ctrl']['tstamp']];
390
391 57
        if ($itemTypeHasStartTimeColumn) {
392 57
            $startTime = $record[$GLOBALS['TCA'][$itemType]['ctrl']['enablecolumns']['starttime']];
393
        }
394
395 57
        if ($itemType === 'pages') {
396 35
            $record['uid'] = $itemUid;
397
            // overrule the page's last changed time with the most recent
398
            //content element change
399 35
            $pageChangedTime = $this->getPageItemChangedTime($record);
400
        }
401
402 57
        $localizationsChangedTime = $this->queueItemRepository->getLocalizableItemChangedTime($itemType, (int)$itemUid);
403
404
        // if start time exists and start time is higher than last changed timestamp
405
        // then set changed to the future start time to make the item
406
        // indexed at a later time
407 57
        $changedTime = max(
408 57
            $itemChangedTime,
409 57
            $pageChangedTime,
410 57
            $localizationsChangedTime,
411 57
            $startTime
412
        );
413
414 57
        return $changedTime;
415
    }
416
417
    /**
418
     * Gets the most recent changed time of a page's content elements
419
     *
420
     * @param array $page Partial page record
421
     * @return int Timestamp of the most recent content element change
422
     */
423 35
    protected function getPageItemChangedTime(array $page)
424
    {
425 35
        if (!empty($page['content_from_pid'])) {
426
            // canonical page, get the original page's last changed time
427
            return $this->queueItemRepository->getPageItemChangedTimeByPageUid((int)$page['content_from_pid']);
428
        }
429 35
        return $this->queueItemRepository->getPageItemChangedTimeByPageUid((int)$page['uid']);
430
    }
431
432
    /**
433
     * Checks whether the Index Queue contains a specific item.
434
     *
435
     * @param string $itemType The item's type, usually a table name.
436
     * @param string $itemUid The item's uid, usually an integer uid, could be a
437
     *      different value for non-database-record types.
438
     * @return bool TRUE if the item is found in the queue, FALSE otherwise
439
     */
440 6
    public function containsItem($itemType, $itemUid)
441
    {
442 6
        return $this->queueItemRepository->containsItem($itemType, (int)$itemUid);
443
    }
444
445
    /**
446
     * Checks whether the Index Queue contains a specific item.
447
     *
448
     * @param string $itemType The item's type, usually a table name.
449
     * @param string $itemUid The item's uid, usually an integer uid, could be a
450
     *      different value for non-database-record types.
451
     * @param integer $rootPageId
452
     * @return bool TRUE if the item is found in the queue, FALSE otherwise
453
     */
454 58
    public function containsItemWithRootPageId($itemType, $itemUid, $rootPageId)
455
    {
456 58
        return $this->queueItemRepository->containsItemWithRootPageId($itemType, (int)$itemUid, (int)$rootPageId);
457
    }
458
459
    /**
460
     * Checks whether the Index Queue contains a specific item that has been
461
     * marked as indexed.
462
     *
463
     * @param string $itemType The item's type, usually a table name.
464
     * @param string $itemUid The item's uid, usually an integer uid, could be a
465
     *      different value for non-database-record types.
466
     * @return bool TRUE if the item is found in the queue and marked as
467
     *      indexed, FALSE otherwise
468
     */
469 2
    public function containsIndexedItem($itemType, $itemUid)
470
    {
471 2
        return $this->queueItemRepository->containsIndexedItem($itemType, (int)$itemUid);
472
    }
473
474
    /**
475
     * Removes an item from the Index Queue.
476
     *
477
     * @param string $itemType The type of the item to remove, usually a table name.
478
     * @param int $itemUid The uid of the item to remove
479
     */
480 29
    public function deleteItem($itemType, $itemUid)
481
    {
482 29
        $this->queueItemRepository->deleteItem($itemType, (int)$itemUid);
483 29
    }
484
485
    /**
486
     * Removes all items of a certain type from the Index Queue.
487
     *
488
     * @param string $itemType The type of items to remove, usually a table name.
489
     */
490 1
    public function deleteItemsByType($itemType)
491
    {
492 1
        $this->queueItemRepository->deleteItemsByType($itemType);
493 1
    }
494
495
    /**
496
     * Removes all items of a certain site from the Index Queue. Accepts an
497
     * optional parameter to limit the deleted items by indexing configuration.
498
     *
499
     * @param Site $site The site to remove items for.
500
     * @param string $indexingConfigurationName Name of a specific indexing
501
     *      configuration
502
     */
503 6
    public function deleteItemsBySite(Site $site, $indexingConfigurationName = '')
504
    {
505 6
        $this->queueItemRepository->deleteItemsBySite($site, $indexingConfigurationName);
506 6
    }
507
508
    /**
509
     * Removes all items from the Index Queue.
510
     *
511
     */
512 1
    public function deleteAllItems()
513
    {
514 1
        $this->queueItemRepository->deleteAllItems();
515 1
    }
516
517
    /**
518
     * Gets a single Index Queue item by its uid.
519
     *
520
     * @param int $itemId Index Queue item uid
521
     * @return Item The request Index Queue item or NULL if no item with $itemId was found
522
     */
523 23
    public function getItem($itemId)
524
    {
525 23
        return $this->queueItemRepository->findItemByUid($itemId);
526
    }
527
528
    /**
529
     * Gets Index Queue items by type and uid.
530
     *
531
     * @param string $itemType item type, usually  the table name
532
     * @param int $itemUid item uid
533
     * @return Item[] An array of items matching $itemType and $itemUid
534
     */
535 33
    public function getItems($itemType, $itemUid)
536
    {
537 33
        return $this->queueItemRepository->findItemsByItemTypeAndItemUid($itemType, (int)$itemUid);
538
    }
539
540
    /**
541
     * Returns all items in the queue.
542
     *
543
     * @return Item[] An array of items
544
     */
545
    public function getAllItems()
546
    {
547
        return $this->queueItemRepository->findAll();
548
    }
549
550
    /**
551
     * Returns the number of items for all queues.
552
     *
553
     * @return int
554
     */
555 71
    public function getAllItemsCount()
556
    {
557 71
        return $this->queueItemRepository->count();
558
    }
559
560
    /**
561
     * Extracts the number of pending, indexed and erroneous items from the
562
     * Index Queue.
563
     *
564
     * @param Site $site
565
     * @param string $indexingConfigurationName
566
     *
567
     * @return QueueStatistic
568
     */
569 5
    public function getStatisticsBySite(Site $site, $indexingConfigurationName = '')
570
    {
571 5
        return $this->queueStatisticsRepository->findOneByRootPidAndOptionalIndexingConfigurationName($site->getRootPageId(), $indexingConfigurationName);
572
    }
573
574
    /**
575
     * Gets $limit number of items to index for a particular $site.
576
     *
577
     * @param Site $site TYPO3 site
578
     * @param int $limit Number of items to get from the queue
579
     * @return Item[] Items to index to the given solr server
580
     */
581 6
    public function getItemsToIndex(Site $site, $limit = 50)
582
    {
583 6
        return $this->queueItemRepository->findItemsToIndex($site, $limit);
584
    }
585
586
    /**
587
     * Marks an item as failed and causes the indexer to skip the item in the
588
     * next run.
589
     *
590
     * @param int|Item $item Either the item's Index Queue uid or the complete item
591
     * @param string $errorMessage Error message
592
     */
593 6
    public function markItemAsFailed($item, $errorMessage = '')
594
    {
595 6
        $this->queueItemRepository->markItemAsFailed($item, $errorMessage);
596 6
    }
597
598
    /**
599
     * Sets the timestamp of when an item last has been indexed.
600
     *
601
     * @param Item $item
602
     */
603 5
    public function updateIndexTimeByItem(Item $item)
604
    {
605 5
        $this->queueItemRepository->updateIndexTimeByItem($item);
606 5
    }
607
608
    /**
609
     * Sets the change timestamp of an item.
610
     *
611
     * @param Item $item
612
     * @param int $forcedChangeTime The change time for the item
613
     */
614
    public function setForcedChangeTimeByItem(Item $item, $forcedChangeTime)
615
    {
616
        $this->queueItemRepository->updateChangedTimeByItem($item, $forcedChangeTime);
617
    }
618
}
619