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