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