| Total Complexity | 81 |
| Total Lines | 707 |
| Duplicated Lines | 0 % |
| Changes | 7 | ||
| Bugs | 2 | Features | 0 |
Complex classes like Indexer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Indexer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 51 | class Indexer extends AbstractIndexer |
||
| 52 | { |
||
| 53 | |||
| 54 | # TODO change to singular $document instead of plural $documents |
||
| 55 | |||
| 56 | /** |
||
| 57 | * A Solr service instance to interact with the Solr server |
||
| 58 | * |
||
| 59 | * @var SolrConnection |
||
| 60 | */ |
||
| 61 | protected $solr; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var ConnectionManager |
||
| 65 | */ |
||
| 66 | protected $connectionManager; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Holds options for a specific indexer |
||
| 70 | * |
||
| 71 | * @var array |
||
| 72 | */ |
||
| 73 | protected $options = []; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * To log or not to log... #Shakespeare |
||
| 77 | * |
||
| 78 | * @var bool |
||
| 79 | */ |
||
| 80 | protected $loggingEnabled = false; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var SolrLogManager |
||
| 84 | */ |
||
| 85 | protected $logger = null; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var PagesRepository |
||
| 89 | */ |
||
| 90 | protected $pagesRepository; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var Builder |
||
| 94 | */ |
||
| 95 | protected $documentBuilder; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var FrontendEnvironment |
||
| 99 | */ |
||
| 100 | protected $frontendEnvironment = null; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Constructor |
||
| 104 | * |
||
| 105 | * @param array $options array of indexer options |
||
| 106 | * @param PagesRepository|null $pagesRepository |
||
| 107 | * @param Builder|null $documentBuilder |
||
| 108 | * @param SolrLogManager|null $logger |
||
| 109 | * @param ConnectionManager|null $connectionManager |
||
| 110 | * @param FrontendEnvironment|null $frontendEnvironment |
||
| 111 | */ |
||
| 112 | public function __construct( |
||
| 113 | array $options = [], |
||
| 114 | PagesRepository $pagesRepository = null, |
||
| 115 | Builder $documentBuilder = null, |
||
| 116 | SolrLogManager $logger = null, |
||
| 117 | ConnectionManager $connectionManager = null, |
||
| 118 | FrontendEnvironment $frontendEnvironment = null |
||
| 119 | ) |
||
| 120 | { |
||
| 121 | $this->options = $options; |
||
| 122 | $this->pagesRepository = $pagesRepository ?? GeneralUtility::makeInstance(PagesRepository::class); |
||
| 123 | $this->documentBuilder = $documentBuilder ?? GeneralUtility::makeInstance(Builder::class); |
||
| 124 | $this->logger = $logger ?? GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__); |
||
| 125 | $this->connectionManager = $connectionManager ?? GeneralUtility::makeInstance(ConnectionManager::class); |
||
| 126 | $this->frontendEnvironment = $frontendEnvironment ?? GeneralUtility::makeInstance(FrontendEnvironment::class); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Indexes an item from the indexing queue. |
||
| 131 | * |
||
| 132 | * @param Item $item An index queue item |
||
| 133 | * @return bool returns true when indexed, false when not |
||
| 134 | */ |
||
| 135 | public function index(Item $item) |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Creates a single Solr Document for an item in a specific language. |
||
| 164 | * |
||
| 165 | * @param Item $item An index queue item to index. |
||
| 166 | * @param int $language The language to use. |
||
| 167 | * @return bool TRUE if item was indexed successfully, FALSE on failure |
||
| 168 | */ |
||
| 169 | protected function indexItem(Item $item, int $language = 0) |
||
| 170 | { |
||
| 171 | $itemIndexed = false; |
||
| 172 | $documents = []; |
||
| 173 | |||
| 174 | $itemDocument = $this->itemToDocument($item, $language); |
||
| 175 | if (is_null($itemDocument)) { |
||
| 176 | /* |
||
| 177 | * If there is no itemDocument, this means there was no translation |
||
| 178 | * for this record. This should not stop the current item to count as |
||
| 179 | * being valid because not-indexing not-translated items is perfectly |
||
| 180 | * fine. |
||
| 181 | */ |
||
| 182 | return true; |
||
| 183 | } |
||
| 184 | |||
| 185 | $documents[] = $itemDocument; |
||
| 186 | $documents = array_merge($documents, $this->getAdditionalDocuments($item, $language, $itemDocument)); |
||
| 187 | $documents = $this->processDocuments($item, $documents); |
||
| 188 | $documents = $this->preAddModifyDocuments($item, $language, $documents); |
||
| 189 | |||
| 190 | try { |
||
| 191 | $response = $this->solr->getWriteService()->addDocuments($documents); |
||
| 192 | if ($response->getHttpStatus() == 200) { |
||
| 193 | $itemIndexed = true; |
||
| 194 | } |
||
| 195 | } catch (HttpException $e) { |
||
| 196 | $response = new ResponseAdapter($e->getBody(), $httpStatus = 500, $e->getStatusMessage()); |
||
| 197 | } |
||
| 198 | |||
| 199 | $this->log($item, $documents, $response); |
||
| 200 | |||
| 201 | return $itemIndexed; |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Gets the full item record. |
||
| 206 | * |
||
| 207 | * This general record indexer simply gets the record from the item. Other |
||
| 208 | * more specialized indexers may provide more data for their specific item |
||
| 209 | * types. |
||
| 210 | * |
||
| 211 | * @param Item $item The item to be indexed |
||
| 212 | * @param int $language Language Id (sys_language.uid) |
||
| 213 | * @return array|NULL The full record with fields of data to be used for indexing or NULL to prevent an item from being indexed |
||
| 214 | */ |
||
| 215 | protected function getFullItemRecord(Item $item, int $language = 0) |
||
| 216 | { |
||
| 217 | $itemRecord = $this->getItemRecordOverlayed($item, $language); |
||
| 218 | |||
| 219 | if (!is_null($itemRecord)) { |
||
| 220 | $itemRecord['__solr_index_language'] = $language; |
||
| 221 | } |
||
| 222 | |||
| 223 | return $itemRecord; |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Returns the overlayed item record. |
||
| 228 | * |
||
| 229 | * @param Item $item |
||
| 230 | * @param int $language |
||
| 231 | * @return array|mixed|null |
||
| 232 | * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException |
||
| 233 | */ |
||
| 234 | protected function getItemRecordOverlayed(Item $item, int $language): ?array |
||
| 235 | { |
||
| 236 | $itemRecord = $item->getRecord(); |
||
| 237 | |||
| 238 | // Bugfix: This issue fixes a problem with the free mode temporary. |
||
| 239 | $languageField = $this->getLanguageFieldFromTable($item->getType()); |
||
| 240 | if ($languageField !== null && |
||
| 241 | (int)$itemRecord[$languageField] > 0 && |
||
| 242 | (int)$itemRecord[$languageField] !== $language) { |
||
| 243 | return null; |
||
| 244 | } |
||
| 245 | |||
| 246 | if ($language > 0) { |
||
| 247 | // @TODO Information from the site configuration are required! |
||
| 248 | /* @var Context $context */ |
||
| 249 | $context = GeneralUtility::makeInstance(Context::class); |
||
| 250 | /* @var LanguageAspect $languageAspect */ |
||
| 251 | if ($context->hasAspect('language')) { |
||
| 252 | $languageAspect = $context->getAspect('language'); |
||
| 253 | $languageAspect = new LanguageAspect( |
||
| 254 | $languageAspect->getId(), |
||
|
|
|||
| 255 | (int)$language, |
||
| 256 | $languageAspect->getOverlayType(), |
||
| 257 | $languageAspect->getFallbackChain() |
||
| 258 | ); |
||
| 259 | } else { |
||
| 260 | $languageAspect = new LanguageAspect( |
||
| 261 | 0, |
||
| 262 | (int)$language |
||
| 263 | ); |
||
| 264 | } |
||
| 265 | |||
| 266 | $context->setAspect('language', $languageAspect); |
||
| 267 | $page = GeneralUtility::makeInstance(PageRepository::class, $context); |
||
| 268 | $itemRecord = $page->getLanguageOverlay($item->getType(), $itemRecord); |
||
| 269 | } |
||
| 270 | |||
| 271 | if (!$itemRecord) { |
||
| 272 | $itemRecord = null; |
||
| 273 | } |
||
| 274 | |||
| 275 | return $itemRecord; |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Gets the configuration how to process an item's fields for indexing. |
||
| 280 | * |
||
| 281 | * @param Item $item An index queue item |
||
| 282 | * @param int $language Language ID |
||
| 283 | * @throws RuntimeException |
||
| 284 | * @return array Configuration array from TypoScript |
||
| 285 | */ |
||
| 286 | protected function getItemTypeConfiguration(Item $item, int $language = 0): array |
||
| 287 | { |
||
| 288 | $indexConfigurationName = $item->getIndexingConfigurationName(); |
||
| 289 | $fields = $this->getFieldConfigurationFromItemRecordPage($item, $language, $indexConfigurationName); |
||
| 290 | if (!$this->isRootPageIdPartOfRootLine($item) || count($fields) === 0) { |
||
| 291 | $fields = $this->getFieldConfigurationFromItemRootPage($item, $language, $indexConfigurationName); |
||
| 292 | if (count($fields) === 0) { |
||
| 293 | throw new RuntimeException('The item indexing configuration "' . $item->getIndexingConfigurationName() . |
||
| 294 | '" on root page uid ' . $item->getRootPageUid() . ' could not be found!', 1455530112); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | |||
| 298 | return $fields; |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * The method retrieves the field configuration of the items record page id (pid). |
||
| 303 | * |
||
| 304 | * @param Item $item |
||
| 305 | * @param integer $language |
||
| 306 | * @param string $indexConfigurationName |
||
| 307 | * @return array |
||
| 308 | */ |
||
| 309 | protected function getFieldConfigurationFromItemRecordPage(Item $item, int $language, $indexConfigurationName): array |
||
| 310 | { |
||
| 311 | try { |
||
| 312 | $pageId = $this->getPageIdOfItem($item); |
||
| 313 | $solrConfiguration = $this->frontendEnvironment->getSolrConfigurationFromPageId($pageId, $language); |
||
| 314 | return $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName, []); |
||
| 315 | } catch (Exception $e) { |
||
| 316 | return []; |
||
| 317 | } |
||
| 318 | } |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @param Item $item |
||
| 322 | * @return int |
||
| 323 | */ |
||
| 324 | protected function getPageIdOfItem(Item $item): int |
||
| 325 | { |
||
| 326 | if ($item->getType() === 'pages') { |
||
| 327 | return (int)$item->getRecordUid(); |
||
| 328 | } |
||
| 329 | return (int)$item->getRecordPageId(); |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * The method returns the field configuration of the items root page id (uid of the related root page). |
||
| 334 | * |
||
| 335 | * @param Item $item |
||
| 336 | * @param integer $language |
||
| 337 | * @param string $indexConfigurationName |
||
| 338 | * @return array |
||
| 339 | */ |
||
| 340 | protected function getFieldConfigurationFromItemRootPage(Item $item, int $language, $indexConfigurationName) |
||
| 341 | { |
||
| 342 | $solrConfiguration = $this->frontendEnvironment->getSolrConfigurationFromPageId($item->getRootPageUid(), $language); |
||
| 343 | |||
| 344 | return $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName, []); |
||
| 345 | } |
||
| 346 | |||
| 347 | /** |
||
| 348 | * In case of additionalStoragePid config recordPageId can be outside of siteroot. |
||
| 349 | * In that case we should not read TS config of foreign siteroot. |
||
| 350 | * |
||
| 351 | * @param Item $item |
||
| 352 | * @return bool |
||
| 353 | */ |
||
| 354 | protected function isRootPageIdPartOfRootLine(Item $item): bool |
||
| 355 | { |
||
| 356 | $rootPageId = (int)$item->getRootPageUid(); |
||
| 357 | $buildRootlineWithPid = $this->getPageIdOfItem($item); |
||
| 358 | $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $buildRootlineWithPid); |
||
| 359 | $rootline = $rootlineUtility->get(); |
||
| 360 | |||
| 361 | $pageInRootline = array_filter($rootline, function($page) use ($rootPageId) { |
||
| 362 | return (int)$page['uid'] === $rootPageId; |
||
| 363 | }); |
||
| 364 | return !empty($pageInRootline); |
||
| 365 | } |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Converts an item array (record) to a Solr document by mapping the |
||
| 369 | * record's fields onto Solr document fields as configured in TypoScript. |
||
| 370 | * |
||
| 371 | * @param Item $item An index queue item |
||
| 372 | * @param int $language Language Id |
||
| 373 | * @return Document|null The Solr document converted from the record |
||
| 374 | * @throws SiteNotFoundException |
||
| 375 | * @throws ServiceUnavailableException |
||
| 376 | * @throws ImmediateResponseException |
||
| 377 | */ |
||
| 378 | protected function itemToDocument(Item $item, int $language = 0): ?Document |
||
| 379 | { |
||
| 380 | $document = null; |
||
| 381 | if ($item->getType() === 'pages') { |
||
| 382 | $this->frontendEnvironment->initializeTsfe($item->getRecordUid(), $language); |
||
| 383 | } else { |
||
| 384 | $this->frontendEnvironment->initializeTsfe($item->getRootPageUid(), $language); |
||
| 385 | } |
||
| 386 | |||
| 387 | $itemRecord = $this->getFullItemRecord($item, $language); |
||
| 388 | if (!is_null($itemRecord)) { |
||
| 389 | $itemIndexingConfiguration = $this->getItemTypeConfiguration($item, $language); |
||
| 390 | $document = $this->getBaseDocument($item, $itemRecord); |
||
| 391 | $document = $this->addDocumentFieldsFromTyposcript($document, $itemIndexingConfiguration, $itemRecord); |
||
| 392 | } |
||
| 393 | |||
| 394 | return $document; |
||
| 395 | } |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Creates a Solr document with the basic / core fields set already. |
||
| 399 | * |
||
| 400 | * @param Item $item The item to index |
||
| 401 | * @param array $itemRecord The record to use to build the base document |
||
| 402 | * @return Document A basic Solr document |
||
| 403 | */ |
||
| 404 | protected function getBaseDocument(Item $item, array $itemRecord) |
||
| 405 | { |
||
| 406 | $type = $item->getType(); |
||
| 407 | $rootPageUid = $item->getRootPageUid(); |
||
| 408 | $accessRootLine = $this->getAccessRootline($item); |
||
| 409 | return $this->documentBuilder->fromRecord($itemRecord, $type, $rootPageUid, $accessRootLine); |
||
| 410 | } |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Generates an Access Rootline for an item. |
||
| 414 | * |
||
| 415 | * @param Item $item Index Queue item to index. |
||
| 416 | * @return string The Access Rootline for the item |
||
| 417 | */ |
||
| 418 | protected function getAccessRootline(Item $item) |
||
| 419 | { |
||
| 420 | $accessRestriction = '0'; |
||
| 421 | $itemRecord = $item->getRecord(); |
||
| 422 | |||
| 423 | // TODO support access restrictions set on storage page |
||
| 424 | |||
| 425 | if (isset($GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group'])) { |
||
| 426 | $accessRestriction = $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group']]; |
||
| 427 | |||
| 428 | if (empty($accessRestriction)) { |
||
| 429 | // public |
||
| 430 | $accessRestriction = '0'; |
||
| 431 | } |
||
| 432 | } |
||
| 433 | |||
| 434 | return 'r:' . $accessRestriction; |
||
| 435 | } |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Sends the documents to the field processing service which takes care of |
||
| 439 | * manipulating fields as defined in the field's configuration. |
||
| 440 | * |
||
| 441 | * @param Item $item An index queue item |
||
| 442 | * @param array $documents An array of Apache_Solr_Document objects to manipulate. |
||
| 443 | * @return Document[] array Array of manipulated Document objects. |
||
| 444 | */ |
||
| 445 | protected function processDocuments(Item $item, array $documents) |
||
| 446 | { |
||
| 447 | // needs to respect the TS settings for the page the item is on, conditions may apply |
||
| 448 | $solrConfiguration = $this->frontendEnvironment->getSolrConfigurationFromPageId($item->getRootPageUid()); |
||
| 449 | $fieldProcessingInstructions = $solrConfiguration->getIndexFieldProcessingInstructionsConfiguration(); |
||
| 450 | |||
| 451 | // same as in the FE indexer |
||
| 452 | if (is_array($fieldProcessingInstructions)) { |
||
| 453 | $service = GeneralUtility::makeInstance(Service::class); |
||
| 454 | $service->processDocuments($documents, $fieldProcessingInstructions); |
||
| 455 | } |
||
| 456 | |||
| 457 | return $documents; |
||
| 458 | } |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Allows third party extensions to provide additional documents which |
||
| 462 | * should be indexed for the current item. |
||
| 463 | * |
||
| 464 | * @param Item $item The item currently being indexed. |
||
| 465 | * @param int $language The language uid currently being indexed. |
||
| 466 | * @param Document $itemDocument The document representing the item for the given language. |
||
| 467 | * @return Document[] array An array of additional Document objects to index. |
||
| 468 | */ |
||
| 469 | protected function getAdditionalDocuments(Item $item, int $language, Document $itemDocument) |
||
| 470 | { |
||
| 471 | $documents = []; |
||
| 472 | |||
| 473 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments'])) { |
||
| 474 | foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments'] as $classReference) { |
||
| 475 | if (!class_exists($classReference)) { |
||
| 476 | throw new \InvalidArgumentException('Class does not exits' . $classReference, 1490363487); |
||
| 477 | } |
||
| 478 | $additionalIndexer = GeneralUtility::makeInstance($classReference); |
||
| 479 | if ($additionalIndexer instanceof AdditionalIndexQueueItemIndexer) { |
||
| 480 | $additionalDocuments = $additionalIndexer->getAdditionalItemDocuments($item, $language, $itemDocument); |
||
| 481 | |||
| 482 | if (is_array($additionalDocuments)) { |
||
| 483 | $documents = array_merge($documents, |
||
| 484 | $additionalDocuments); |
||
| 485 | } |
||
| 486 | } else { |
||
| 487 | throw new \UnexpectedValueException( |
||
| 488 | get_class($additionalIndexer) . ' must implement interface ' . AdditionalIndexQueueItemIndexer::class, |
||
| 489 | 1326284551 |
||
| 490 | ); |
||
| 491 | } |
||
| 492 | } |
||
| 493 | } |
||
| 494 | return $documents; |
||
| 495 | } |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Provides a hook to manipulate documents right before they get added to |
||
| 499 | * the Solr index. |
||
| 500 | * |
||
| 501 | * @param Item $item The item currently being indexed. |
||
| 502 | * @param int $language The language uid of the documents |
||
| 503 | * @param array $documents An array of documents to be indexed |
||
| 504 | * @return array An array of modified documents |
||
| 505 | */ |
||
| 506 | protected function preAddModifyDocuments(Item $item, int $language, array $documents) |
||
| 507 | { |
||
| 508 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'])) { |
||
| 509 | foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'] as $classReference) { |
||
| 510 | $documentsModifier = GeneralUtility::makeInstance($classReference); |
||
| 511 | |||
| 512 | if ($documentsModifier instanceof PageIndexerDocumentsModifier) { |
||
| 513 | $documents = $documentsModifier->modifyDocuments($item, $language, $documents); |
||
| 514 | } else { |
||
| 515 | throw new RuntimeException( |
||
| 516 | 'The class "' . get_class($documentsModifier) |
||
| 517 | . '" registered as document modifier in hook |
||
| 518 | preAddModifyDocuments must implement interface |
||
| 519 | ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerDocumentsModifier', |
||
| 520 | 1309522677 |
||
| 521 | ); |
||
| 522 | } |
||
| 523 | } |
||
| 524 | } |
||
| 525 | |||
| 526 | return $documents; |
||
| 527 | } |
||
| 528 | |||
| 529 | // Initialization |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Gets the Solr connections applicable for an item. |
||
| 533 | * |
||
| 534 | * The connections include the default connection and connections to be used |
||
| 535 | * for translations of an item. |
||
| 536 | * |
||
| 537 | * @param Item $item An index queue item |
||
| 538 | * @return array An array of ApacheSolrForTypo3\Solr\System\Solr\SolrConnection connections, the array's keys are the sys_language_uid of the language of the connection |
||
| 539 | */ |
||
| 540 | protected function getSolrConnectionsByItem(Item $item) |
||
| 541 | { |
||
| 542 | $solrConnections = []; |
||
| 543 | |||
| 544 | $rootPageId = $item->getRootPageUid(); |
||
| 545 | if ($item->getType() === 'pages') { |
||
| 546 | $pageId = $item->getRecordUid(); |
||
| 547 | } else { |
||
| 548 | $pageId = $item->getRecordPageId(); |
||
| 549 | } |
||
| 550 | |||
| 551 | // Solr configurations possible for this item |
||
| 552 | $site = $item->getSite(); |
||
| 553 | $solrConfigurationsBySite = $site->getAllSolrConnectionConfigurations(); |
||
| 554 | $siteLanguages = []; |
||
| 555 | foreach ($solrConfigurationsBySite as $solrConfiguration) { |
||
| 556 | $siteLanguages[] = $solrConfiguration['language']; |
||
| 557 | } |
||
| 558 | |||
| 559 | $defaultLanguageUid = $this->getDefaultLanguageUid($item, $site->getRootPage(), $siteLanguages); |
||
| 560 | $translationOverlays = $this->getTranslationOverlaysWithConfiguredSite((int)$pageId, $site, (array)$siteLanguages); |
||
| 561 | |||
| 562 | $defaultConnection = $this->connectionManager->getConnectionByPageId($rootPageId, $defaultLanguageUid, $item->getMountPointIdentifier()); |
||
| 563 | $translationConnections = $this->getConnectionsForIndexableLanguages($translationOverlays); |
||
| 564 | |||
| 565 | if ($defaultLanguageUid == 0) { |
||
| 566 | $solrConnections[0] = $defaultConnection; |
||
| 567 | } |
||
| 568 | |||
| 569 | foreach ($translationConnections as $systemLanguageUid => $solrConnection) { |
||
| 570 | $solrConnections[$systemLanguageUid] = $solrConnection; |
||
| 571 | } |
||
| 572 | return $solrConnections; |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * @param int $pageId |
||
| 577 | * @param Site $site |
||
| 578 | * @param array $siteLanguages |
||
| 579 | * @return array |
||
| 580 | */ |
||
| 581 | protected function getTranslationOverlaysWithConfiguredSite(int $pageId, Site $site, array $siteLanguages): array |
||
| 614 | } |
||
| 615 | |||
| 616 | /** |
||
| 617 | * @param Site $site |
||
| 618 | * @param int $languageId |
||
| 619 | * @param int $pageId |
||
| 620 | * @return array |
||
| 621 | */ |
||
| 622 | protected function getFallbackOrder(Site $site, int $languageId, int $pageId): array |
||
| 623 | { |
||
| 624 | $fallbackChain = []; |
||
| 625 | $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); |
||
| 634 | } |
||
| 635 | |||
| 636 | /** |
||
| 637 | * @param Item $item An index queue item |
||
| 638 | * @param array $rootPage |
||
| 639 | * @param array $siteLanguages |
||
| 640 | * |
||
| 641 | * @return int |
||
| 642 | * @throws RuntimeException |
||
| 643 | */ |
||
| 644 | protected function getDefaultLanguageUid(Item $item, array $rootPage, array $siteLanguages) |
||
| 645 | { |
||
| 646 | $defaultLanguageUid = 0; |
||
| 647 | if (($rootPage['l18n_cfg'] & 1) == 1 && count($siteLanguages) == 1 && $siteLanguages[min(array_keys($siteLanguages))] > 0) { |
||
| 648 | $defaultLanguageUid = $siteLanguages[min(array_keys($siteLanguages))]; |
||
| 649 | } elseif (($rootPage['l18n_cfg'] & 1) == 1 && count($siteLanguages) > 1) { |
||
| 650 | unset($siteLanguages[array_search('0', $siteLanguages)]); |
||
| 651 | $defaultLanguageUid = $siteLanguages[min(array_keys($siteLanguages))]; |
||
| 652 | } elseif (($rootPage['l18n_cfg'] & 1) == 1 && count($siteLanguages) == 1) { |
||
| 653 | $message = 'Root page ' . (int)$item->getRootPageUid() . ' is set to hide default translation, but no other language is configured!'; |
||
| 654 | throw new RuntimeException($message); |
||
| 655 | } |
||
| 656 | |||
| 657 | return $defaultLanguageUid; |
||
| 658 | } |
||
| 659 | |||
| 660 | /** |
||
| 661 | * Checks for which languages connections have been configured and returns |
||
| 662 | * these connections. |
||
| 663 | * |
||
| 664 | * @param array $translationOverlays An array of translation overlays to check for configured connections. |
||
| 665 | * @return array An array of ApacheSolrForTypo3\Solr\System\Solr\SolrConnection connections. |
||
| 666 | */ |
||
| 667 | protected function getConnectionsForIndexableLanguages(array $translationOverlays) |
||
| 685 | } |
||
| 686 | |||
| 687 | // Utility methods |
||
| 688 | |||
| 689 | // FIXME extract log() and setLogging() to ApacheSolrForTypo3\Solr\IndexQueue\AbstractIndexer |
||
| 690 | // FIXME extract an interface Tx_Solr_IndexQueue_ItemInterface |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Enables logging dependent on the configuration of the item's site |
||
| 694 | * |
||
| 695 | * @param Item $item An item being indexed |
||
| 696 | * @return void |
||
| 697 | */ |
||
| 698 | protected function setLogging(Item $item) |
||
| 699 | { |
||
| 700 | $solrConfiguration = $this->frontendEnvironment->getSolrConfigurationFromPageId($item->getRootPageUid()); |
||
| 701 | $this->loggingEnabled = $solrConfiguration->getLoggingIndexingQueueOperationsByConfigurationNameWithFallBack( |
||
| 702 | $item->getIndexingConfigurationName() |
||
| 703 | ); |
||
| 704 | } |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Logs the item and what document was created from it |
||
| 708 | * |
||
| 709 | * @param Item $item The item that is being indexed. |
||
| 710 | * @param array $itemDocuments An array of Solr documents created from the item's data |
||
| 711 | * @param ResponseAdapter $response The Solr response for the particular index document |
||
| 712 | */ |
||
| 713 | protected function log(Item $item, array $itemDocuments, ResponseAdapter $response) |
||
| 714 | { |
||
| 715 | if (!$this->loggingEnabled) { |
||
| 716 | return; |
||
| 717 | } |
||
| 718 | |||
| 719 | $message = 'Index Queue indexing ' . $item->getType() . ':' . $item->getRecordUid() . ' - '; |
||
| 720 | |||
| 721 | // preparing data |
||
| 722 | $documents = []; |
||
| 723 | foreach ($itemDocuments as $document) { |
||
| 724 | $documents[] = (array)$document; |
||
| 725 | } |
||
| 726 | |||
| 727 | $logData = ['item' => (array)$item, 'documents' => $documents, 'response' => (array)$response]; |
||
| 728 | |||
| 729 | if ($response->getHttpStatus() == 200) { |
||
| 730 | $severity = SolrLogManager::NOTICE; |
||
| 731 | $message .= 'Success'; |
||
| 732 | } else { |
||
| 733 | $severity = SolrLogManager::ERROR; |
||
| 734 | $message .= 'Failure'; |
||
| 735 | |||
| 736 | $logData['status'] = $response->getHttpStatus(); |
||
| 737 | $logData['status message'] = $response->getHttpStatusMessage(); |
||
| 738 | } |
||
| 739 | |||
| 740 | $this->logger->log($severity, $message, $logData); |
||
| 741 | } |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Returns the language field from given table or null |
||
| 745 | * |
||
| 746 | * @param string $tableName |
||
| 747 | * @return string|null |
||
| 748 | */ |
||
| 749 | protected function getLanguageFieldFromTable(string $tableName): ?string |
||
| 758 | } |
||
| 759 | } |
||
| 760 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.