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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 |
||
50 | class Indexer extends AbstractIndexer |
||
51 | { |
||
52 | |||
53 | # TODO change to singular $document instead of plural $documents |
||
54 | |||
55 | /** |
||
56 | * A Solr service instance to interact with the Solr server |
||
57 | * |
||
58 | * @var SolrConnection |
||
59 | */ |
||
60 | protected $solr; |
||
61 | |||
62 | /** |
||
63 | * @var ConnectionManager |
||
64 | */ |
||
65 | protected $connectionManager; |
||
66 | |||
67 | /** |
||
68 | * Holds options for a specific indexer |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $options = []; |
||
73 | |||
74 | /** |
||
75 | * To log or not to log... #Shakespeare |
||
76 | * |
||
77 | * @var bool |
||
78 | */ |
||
79 | protected $loggingEnabled = false; |
||
80 | |||
81 | /** |
||
82 | * @var \ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager |
||
83 | */ |
||
84 | protected $logger = null; |
||
85 | |||
86 | /** |
||
87 | * @var PagesRepository |
||
88 | */ |
||
89 | protected $pagesRepository; |
||
90 | |||
91 | /** |
||
92 | * @var Builder |
||
93 | */ |
||
94 | protected $documentBuilder; |
||
95 | |||
96 | /** |
||
97 | * Constructor |
||
98 | * |
||
99 | * @param array $options array of indexer options |
||
100 | * @param PagesRepository|null $pagesRepository |
||
101 | * @param Builder|null $documentBuilder |
||
102 | */ |
||
103 | 25 | public function __construct(array $options = [], PagesRepository $pagesRepository = null, Builder $documentBuilder = null) |
|
104 | { |
||
105 | 25 | $this->logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__); |
|
106 | 25 | $this->options = $options; |
|
107 | 25 | $this->connectionManager = GeneralUtility::makeInstance(ConnectionManager::class); |
|
108 | 25 | $this->pagesRepository = isset($pagesRepository) ? $pagesRepository : GeneralUtility::makeInstance(PagesRepository::class); |
|
109 | 25 | $this->documentBuilder = isset($documentBuilder) ? $documentBuilder : GeneralUtility::makeInstance(Builder::class); |
|
110 | 25 | } |
|
111 | |||
112 | /** |
||
113 | * Indexes an item from the indexing queue. |
||
114 | * |
||
115 | * @param Item $item An index queue item |
||
116 | * @return bool returns true when indexed, false when not |
||
117 | */ |
||
118 | 19 | public function index(Item $item) |
|
145 | |||
146 | /** |
||
147 | * Creates a single Solr Document for an item in a specific language. |
||
148 | * |
||
149 | * @param Item $item An index queue item to index. |
||
150 | * @param int $language The language to use. |
||
151 | * @return bool TRUE if item was indexed successfully, FALSE on failure |
||
152 | */ |
||
153 | 19 | protected function indexItem(Item $item, $language = 0) |
|
183 | |||
184 | /** |
||
185 | * Gets the full item record. |
||
186 | * |
||
187 | * This general record indexer simply gets the record from the item. Other |
||
188 | * more specialized indexers may provide more data for their specific item |
||
189 | * types. |
||
190 | * |
||
191 | * @param Item $item The item to be indexed |
||
192 | * @param int $language Language Id (sys_language.uid) |
||
193 | * @return array|NULL The full record with fields of data to be used for indexing or NULL to prevent an item from being indexed |
||
194 | */ |
||
195 | 19 | protected function getFullItemRecord(Item $item, $language = 0) |
|
196 | { |
||
197 | 19 | Util::initializeTsfe($item->getRootPageUid(), $language); |
|
198 | |||
199 | 19 | $systemLanguageContentOverlay = $GLOBALS['TSFE']->sys_language_contentOL; |
|
200 | 19 | $itemRecord = $this->getItemRecordOverlayed($item, $language, $systemLanguageContentOverlay); |
|
201 | |||
202 | /* |
||
203 | * Skip disabled records. This happens if the default language record |
||
204 | * is hidden but a certain translation isn't. Then the default language |
||
205 | * document appears here but must not be indexed. |
||
206 | */ |
||
207 | 19 | if (!empty($GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['disabled']) |
|
208 | 19 | && $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['disabled']] |
|
209 | ) { |
||
210 | $itemRecord = null; |
||
211 | } |
||
212 | |||
213 | /* |
||
214 | * Skip translation mismatching records. Sometimes the requested language |
||
215 | * doesn't fit the returned language. This might happen with content fallback |
||
216 | * and is perfectly fine in general. |
||
217 | * But if the requested language doesn't match the returned language and |
||
218 | * the given record has no translation parent, the indexqueue_item most |
||
219 | * probably pointed to a non-translated language record that is dedicated |
||
220 | * to a very specific language. Now we have to avoid indexing this record |
||
221 | * into all language cores. |
||
222 | */ |
||
223 | 19 | $translationOriginalPointerField = 'l10n_parent'; |
|
224 | 19 | if (!empty($GLOBALS['TCA'][$item->getType()]['ctrl']['transOrigPointerField'])) { |
|
225 | 18 | $translationOriginalPointerField = $GLOBALS['TCA'][$item->getType()]['ctrl']['transOrigPointerField']; |
|
226 | } |
||
227 | |||
228 | 19 | $languageField = $GLOBALS['TCA'][$item->getType()]['ctrl']['languageField']; |
|
229 | 19 | if ($itemRecord[$translationOriginalPointerField] == 0 |
|
230 | 19 | && $systemLanguageContentOverlay != 1 |
|
231 | 19 | && !empty($languageField) |
|
232 | 19 | && $itemRecord[$languageField] != $language |
|
233 | 19 | && $itemRecord[$languageField] != '-1' |
|
234 | ) { |
||
235 | 1 | $itemRecord = null; |
|
236 | } |
||
237 | |||
238 | 19 | if (!is_null($itemRecord)) { |
|
239 | 19 | $itemRecord['__solr_index_language'] = $language; |
|
240 | } |
||
241 | |||
242 | 19 | return $itemRecord; |
|
243 | } |
||
244 | |||
245 | /** |
||
246 | * Returns the overlayed item record. |
||
247 | * |
||
248 | * @param Item $item |
||
249 | * @param int $language |
||
250 | * @param string|null $systemLanguageContentOverlay |
||
251 | * @return array|mixed|null |
||
252 | */ |
||
253 | 19 | protected function getItemRecordOverlayed(Item $item, $language, $systemLanguageContentOverlay) |
|
254 | { |
||
255 | 19 | $itemRecord = $item->getRecord(); |
|
256 | |||
257 | 19 | if ($language > 0) { |
|
258 | 6 | $page = GeneralUtility::makeInstance(PageRepository::class); |
|
259 | 6 | $page->init(false); |
|
260 | 6 | $itemRecord = $page->getRecordOverlay($item->getType(), $itemRecord, $language, $systemLanguageContentOverlay); |
|
261 | } |
||
262 | |||
263 | 19 | if (!$itemRecord) { |
|
264 | $itemRecord = null; |
||
265 | } |
||
266 | |||
267 | 19 | return $itemRecord; |
|
268 | } |
||
269 | |||
270 | /** |
||
271 | * Gets the configuration how to process an item's fields for indexing. |
||
272 | * |
||
273 | * @param Item $item An index queue item |
||
274 | * @param int $language Language ID |
||
275 | * @throws \RuntimeException |
||
276 | * @return array Configuration array from TypoScript |
||
277 | */ |
||
278 | 19 | protected function getItemTypeConfiguration(Item $item, $language = 0) |
|
279 | { |
||
280 | 19 | $indexConfigurationName = $item->getIndexingConfigurationName(); |
|
281 | 19 | $fields = $this->getFieldConfigurationFromItemRecordPage($item, $language, $indexConfigurationName); |
|
282 | 19 | if (count($fields) === 0) { |
|
283 | 1 | $fields = $this->getFieldConfigurationFromItemRootPage($item, $language, $indexConfigurationName); |
|
284 | 1 | if (count($fields) === 0) { |
|
285 | throw new \RuntimeException('The item indexing configuration "' . $item->getIndexingConfigurationName() . |
||
286 | '" on root page uid ' . $item->getRootPageUid() . ' could not be found!', 1455530112); |
||
287 | } |
||
288 | } |
||
289 | |||
290 | 19 | return $fields; |
|
291 | } |
||
292 | |||
293 | /** |
||
294 | * The method retrieves the field configuration of the items record page id (pid). |
||
295 | * |
||
296 | * @param Item $item |
||
297 | * @param integer $language |
||
298 | * @param string $indexConfigurationName |
||
299 | * @return array |
||
300 | */ |
||
301 | 19 | protected function getFieldConfigurationFromItemRecordPage(Item $item, $language, $indexConfigurationName) |
|
302 | { |
||
303 | try { |
||
304 | 19 | $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRecordPageId(), true, $language); |
|
305 | 18 | return $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName, []); |
|
306 | 1 | } catch (\Exception $e) { |
|
307 | 1 | return []; |
|
308 | } |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * The method returns the field configuration of the items root page id (uid of the related root page). |
||
313 | * |
||
314 | * @param Item $item |
||
315 | * @param integer $language |
||
316 | * @param string $indexConfigurationName |
||
317 | * @return array |
||
318 | */ |
||
319 | 1 | protected function getFieldConfigurationFromItemRootPage(Item $item, $language, $indexConfigurationName) |
|
320 | { |
||
321 | 1 | $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRootPageUid(), true, $language); |
|
322 | 1 | if (empty($solrConfiguration->getIndexQueueAdditionalPageIdsByConfigurationName($indexConfigurationName))) { |
|
323 | return []; |
||
324 | } |
||
325 | |||
326 | 1 | return $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName, []); |
|
327 | } |
||
328 | |||
329 | /** |
||
330 | * Converts an item array (record) to a Solr document by mapping the |
||
331 | * record's fields onto Solr document fields as configured in TypoScript. |
||
332 | * |
||
333 | * @param Item $item An index queue item |
||
334 | * @param int $language Language Id |
||
335 | * @return Apache_Solr_Document The Solr document converted from the record |
||
336 | */ |
||
337 | 19 | protected function itemToDocument(Item $item, $language = 0) |
|
338 | { |
||
339 | 19 | $document = null; |
|
340 | |||
341 | 19 | $itemRecord = $this->getFullItemRecord($item, $language); |
|
342 | 19 | if (!is_null($itemRecord)) { |
|
343 | 19 | $itemIndexingConfiguration = $this->getItemTypeConfiguration($item, $language); |
|
344 | 19 | $document = $this->getBaseDocument($item, $itemRecord); |
|
345 | 19 | $document = $this->addDocumentFieldsFromTyposcript($document, $itemIndexingConfiguration, $itemRecord); |
|
346 | } |
||
347 | |||
348 | 19 | return $document; |
|
349 | } |
||
350 | |||
351 | /** |
||
352 | * Creates a Solr document with the basic / core fields set already. |
||
353 | * |
||
354 | * @param Item $item The item to index |
||
355 | * @param array $itemRecord The record to use to build the base document |
||
356 | * @return Apache_Solr_Document A basic Solr document |
||
357 | */ |
||
358 | 19 | protected function getBaseDocument(Item $item, array $itemRecord) |
|
359 | { |
||
360 | 19 | $type = $item->getType(); |
|
361 | 19 | $rootPageUid = $item->getRootPageUid(); |
|
362 | 19 | $accessRootLine = $this->getAccessRootline($item); |
|
363 | 19 | return $this->documentBuilder->fromRecord($itemRecord, $type, $rootPageUid, $accessRootLine); |
|
364 | } |
||
365 | |||
366 | /** |
||
367 | * Generates an Access Rootline for an item. |
||
368 | * |
||
369 | * @param Item $item Index Queue item to index. |
||
370 | * @return string The Access Rootline for the item |
||
371 | */ |
||
372 | 19 | protected function getAccessRootline(Item $item) |
|
373 | { |
||
374 | 19 | $accessRestriction = '0'; |
|
375 | 19 | $itemRecord = $item->getRecord(); |
|
376 | |||
377 | // TODO support access restrictions set on storage page |
||
378 | |||
379 | 19 | if (isset($GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group'])) { |
|
380 | 1 | $accessRestriction = $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group']]; |
|
381 | |||
382 | 1 | if (empty($accessRestriction)) { |
|
383 | // public |
||
384 | 1 | $accessRestriction = '0'; |
|
385 | } |
||
386 | } |
||
387 | |||
388 | 19 | return 'r:' . $accessRestriction; |
|
389 | } |
||
390 | |||
391 | /** |
||
392 | * Sends the documents to the field processing service which takes care of |
||
393 | * manipulating fields as defined in the field's configuration. |
||
394 | * |
||
395 | * @param Item $item An index queue item |
||
396 | * @param array $documents An array of Apache_Solr_Document objects to manipulate. |
||
397 | * @return array Array of manipulated Apache_Solr_Document objects. |
||
398 | */ |
||
399 | 19 | protected function processDocuments(Item $item, array $documents) |
|
400 | { |
||
401 | // needs to respect the TS settings for the page the item is on, conditions may apply |
||
402 | 19 | $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRootPageUid()); |
|
403 | 19 | $fieldProcessingInstructions = $solrConfiguration->getIndexFieldProcessingInstructionsConfiguration(); |
|
404 | |||
405 | // same as in the FE indexer |
||
406 | 19 | if (is_array($fieldProcessingInstructions)) { |
|
407 | 19 | $service = GeneralUtility::makeInstance(Service::class); |
|
408 | 19 | $service->processDocuments($documents, $fieldProcessingInstructions); |
|
409 | } |
||
410 | |||
411 | 19 | return $documents; |
|
412 | } |
||
413 | |||
414 | /** |
||
415 | * Allows third party extensions to provide additional documents which |
||
416 | * should be indexed for the current item. |
||
417 | * |
||
418 | * @param Item $item The item currently being indexed. |
||
419 | * @param int $language The language uid currently being indexed. |
||
420 | * @param Apache_Solr_Document $itemDocument The document representing the item for the given language. |
||
421 | * @return array An array of additional Apache_Solr_Document objects to index. |
||
422 | */ |
||
423 | 23 | protected function getAdditionalDocuments(Item $item, $language, Apache_Solr_Document $itemDocument) |
|
424 | { |
||
425 | 23 | $documents = []; |
|
426 | |||
427 | 23 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments'])) { |
|
428 | 4 | foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments'] as $classReference) { |
|
429 | 4 | if (!class_exists($classReference)) { |
|
430 | 2 | throw new \InvalidArgumentException('Class does not exits' . $classReference, 1490363487); |
|
431 | } |
||
432 | 2 | $additionalIndexer = GeneralUtility::makeInstance($classReference); |
|
433 | 2 | if ($additionalIndexer instanceof AdditionalIndexQueueItemIndexer) { |
|
434 | 1 | $additionalDocuments = $additionalIndexer->getAdditionalItemDocuments($item, $language, $itemDocument); |
|
435 | |||
436 | 1 | if (is_array($additionalDocuments)) { |
|
437 | 1 | $documents = array_merge($documents, |
|
438 | 1 | $additionalDocuments); |
|
439 | } |
||
440 | } else { |
||
441 | 1 | throw new \UnexpectedValueException( |
|
442 | 1 | get_class($additionalIndexer) . ' must implement interface ' . AdditionalIndexQueueItemIndexer::class, |
|
443 | 2 | 1326284551 |
|
444 | ); |
||
445 | } |
||
446 | } |
||
447 | } |
||
448 | 20 | return $documents; |
|
449 | } |
||
450 | |||
451 | /** |
||
452 | * Provides a hook to manipulate documents right before they get added to |
||
453 | * the Solr index. |
||
454 | * |
||
455 | * @param Item $item The item currently being indexed. |
||
456 | * @param int $language The language uid of the documents |
||
457 | * @param array $documents An array of documents to be indexed |
||
458 | * @return array An array of modified documents |
||
459 | */ |
||
460 | 19 | protected function preAddModifyDocuments(Item $item, $language, array $documents) |
|
461 | { |
||
462 | 19 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'])) { |
|
463 | foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'] as $classReference) { |
||
464 | $documentsModifier = GeneralUtility::getUserObj($classReference); |
||
465 | |||
466 | if ($documentsModifier instanceof PageIndexerDocumentsModifier) { |
||
467 | $documents = $documentsModifier->modifyDocuments($item, $language, $documents); |
||
468 | } else { |
||
469 | throw new \RuntimeException( |
||
470 | 'The class "' . get_class($documentsModifier) |
||
471 | . '" registered as document modifier in hook |
||
472 | preAddModifyDocuments must implement interface |
||
473 | ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerDocumentsModifier', |
||
474 | 1309522677 |
||
475 | ); |
||
476 | } |
||
477 | } |
||
478 | } |
||
479 | |||
480 | 19 | return $documents; |
|
481 | } |
||
482 | |||
483 | // Initialization |
||
484 | |||
485 | /** |
||
486 | * Gets the Solr connections applicable for an item. |
||
487 | * |
||
488 | * The connections include the default connection and connections to be used |
||
489 | * for translations of an item. |
||
490 | * |
||
491 | * @param Item $item An index queue item |
||
492 | * @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 |
||
493 | */ |
||
494 | 21 | protected function getSolrConnectionsByItem(Item $item) |
|
495 | { |
||
496 | 21 | $solrConnections = []; |
|
497 | |||
498 | 21 | $pageId = $item->getRootPageUid(); |
|
499 | 21 | if ($item->getType() === 'pages') { |
|
500 | 3 | $pageId = $item->getRecordUid(); |
|
501 | } |
||
502 | |||
503 | // Solr configurations possible for this item |
||
504 | 21 | $site = $item->getSite(); |
|
505 | |||
506 | 21 | $solrConfigurationsBySite = $this->connectionManager->getConfigurationsBySite($site); |
|
507 | 21 | $siteLanguages = []; |
|
508 | 21 | foreach ($solrConfigurationsBySite as $solrConfiguration) { |
|
509 | 21 | $siteLanguages[] = $solrConfiguration['language']; |
|
510 | } |
||
511 | |||
512 | 21 | $defaultLanguageUid = $this->getDefaultLanguageUid($item, $site->getRootPage(), $siteLanguages); |
|
513 | 21 | $translationOverlays = $this->getTranslationOverlaysWithConfiguredSite($pageId, $site, $defaultLanguageUid, $siteLanguages); |
|
514 | |||
515 | 21 | $defaultConnection = $this->connectionManager->getConnectionByPageId($pageId, 0, $item->getMountPointIdentifier()); |
|
516 | 21 | $translationConnections = $this->getConnectionsForIndexableLanguages($translationOverlays); |
|
517 | |||
518 | 21 | if ($defaultLanguageUid == 0) { |
|
519 | 20 | $solrConnections[0] = $defaultConnection; |
|
520 | } |
||
521 | |||
522 | 21 | foreach ($translationConnections as $systemLanguageUid => $solrConnection) { |
|
523 | 7 | $solrConnections[$systemLanguageUid] = $solrConnection; |
|
524 | } |
||
525 | |||
526 | 21 | return $solrConnections; |
|
527 | } |
||
528 | |||
529 | /** |
||
530 | * Retrieves only translation overlays where a solr site is configured. |
||
531 | * |
||
532 | * @param int $pageId |
||
533 | * @param Site $site |
||
534 | * @param int $defaultLanguageUid |
||
535 | * @param $siteLanguages |
||
536 | * @return array |
||
537 | */ |
||
538 | 21 | protected function getTranslationOverlaysWithConfiguredSite($pageId, Site $site, $defaultLanguageUid, $siteLanguages) |
|
539 | { |
||
540 | 21 | $translationOverlays = $this->getTranslationOverlaysForPage($pageId, $site->getSysLanguageMode($defaultLanguageUid)); |
|
541 | |||
542 | 21 | foreach ($translationOverlays as $key => $translationOverlay) { |
|
543 | 7 | if (!in_array($translationOverlay['sys_language_uid'], $siteLanguages)) { |
|
544 | 7 | unset($translationOverlays[$key]); |
|
545 | } |
||
546 | } |
||
547 | |||
548 | 21 | return $translationOverlays; |
|
549 | } |
||
550 | |||
551 | /** |
||
552 | * @param Item $item An index queue item |
||
553 | * @param array $rootPage |
||
554 | * @param array $siteLanguages |
||
555 | * |
||
556 | * @return int |
||
557 | * @throws \Apache_Solr_Exception |
||
558 | */ |
||
559 | 21 | private function getDefaultLanguageUid(Item $item, array $rootPage, array $siteLanguages) |
|
560 | { |
||
561 | 21 | $defaultLanguageUid = 0; |
|
562 | 21 | if (($rootPage['l18n_cfg'] & 1) == 1 && count($siteLanguages) > 1) { |
|
563 | 1 | unset($siteLanguages[array_search('0', $siteLanguages)]); |
|
564 | 1 | $defaultLanguageUid = $siteLanguages[min(array_keys($siteLanguages))]; |
|
565 | 20 | } elseif (($rootPage['l18n_cfg'] & 1) == 1 && count($siteLanguages) == 1) { |
|
566 | $message = 'Root page ' . (int)$item->getRootPageUid() . ' is set to hide default translation, but no other language is configured!'; |
||
567 | throw new \Apache_Solr_Exception($message); |
||
568 | } |
||
569 | |||
570 | 21 | return $defaultLanguageUid; |
|
571 | } |
||
572 | |||
573 | /** |
||
574 | * Finds the alternative page language overlay records for a page based on |
||
575 | * the sys_language_mode. |
||
576 | * |
||
577 | * Possible Language Modes: |
||
578 | * 1) content_fallback --> all languages |
||
579 | * 2) strict --> available languages with page overlay |
||
580 | * 3) ignore --> available languages with page overlay |
||
581 | * 4) unknown mode or blank --> all languages |
||
582 | * |
||
583 | * @param int $pageId Page ID. |
||
584 | * @param string $languageMode |
||
585 | * @return array An array of translation overlays (or fake overlays) found for the given page. |
||
586 | */ |
||
587 | 21 | protected function getTranslationOverlaysForPage($pageId, $languageMode) |
|
588 | { |
||
589 | 21 | $translationOverlays = []; |
|
590 | 21 | $pageId = intval($pageId); |
|
591 | |||
592 | 21 | $languageModes = ['content_fallback', 'strict', 'ignore']; |
|
593 | 21 | $hasOverlayMode = in_array($languageMode, $languageModes, |
|
594 | 21 | true); |
|
595 | 21 | $isContentFallbackMode = ($languageMode === 'content_fallback'); |
|
596 | |||
597 | 21 | if ($hasOverlayMode && !$isContentFallbackMode) { |
|
598 | 6 | $translationOverlays = $this->pagesRepository->findTranslationOverlaysByPageId($pageId); |
|
599 | } else { |
||
600 | // ! If no sys_language_mode is configured, all languages will be indexed ! |
||
601 | 15 | $languages = $this->getSystemLanguages(); |
|
602 | 15 | foreach ($languages as $language) { |
|
603 | 15 | if ($language['uid'] <= 0) { |
|
604 | 15 | continue; |
|
605 | } |
||
606 | 1 | $translationOverlays[] = [ |
|
607 | 1 | 'pid' => $pageId, |
|
608 | 1 | 'sys_language_uid' => $language['uid'], |
|
609 | ]; |
||
610 | } |
||
611 | } |
||
612 | |||
613 | 21 | return $translationOverlays; |
|
614 | } |
||
615 | |||
616 | /** |
||
617 | * Returns an array of system languages. |
||
618 | * |
||
619 | * @return array |
||
620 | */ |
||
621 | 15 | protected function getSystemLanguages() |
|
622 | { |
||
623 | 15 | return GeneralUtility::makeInstance(TranslationConfigurationProvider::class)->getSystemLanguages(); |
|
624 | } |
||
625 | |||
626 | /** |
||
627 | * Checks for which languages connections have been configured and returns |
||
628 | * these connections. |
||
629 | * |
||
630 | * @param array $translationOverlays An array of translation overlays to check for configured connections. |
||
631 | * @return array An array of ApacheSolrForTypo3\Solr\System\Solr\SolrConnection connections. |
||
632 | */ |
||
633 | 21 | protected function getConnectionsForIndexableLanguages(array $translationOverlays) |
|
634 | { |
||
635 | 21 | $connections = []; |
|
636 | |||
637 | 21 | foreach ($translationOverlays as $translationOverlay) { |
|
638 | 7 | $pageId = $translationOverlay['pid']; |
|
639 | 7 | $languageId = $translationOverlay['sys_language_uid']; |
|
640 | |||
641 | try { |
||
642 | 7 | $connection = $this->connectionManager->getConnectionByPageId($pageId, $languageId); |
|
643 | 7 | $connections[$languageId] = $connection; |
|
644 | 7 | } catch (NoSolrConnectionFoundException $e) { |
|
645 | // ignore the exception as we seek only those connections |
||
646 | // actually available |
||
647 | } |
||
648 | } |
||
649 | |||
650 | 21 | return $connections; |
|
651 | } |
||
652 | |||
653 | // Utility methods |
||
654 | |||
655 | // FIXME extract log() and setLogging() to ApacheSolrForTypo3\Solr\IndexQueue\AbstractIndexer |
||
656 | // FIXME extract an interface Tx_Solr_IndexQueue_ItemInterface |
||
657 | |||
658 | /** |
||
659 | * Enables logging dependent on the configuration of the item's site |
||
660 | * |
||
661 | * @param Item $item An item being indexed |
||
662 | * @return void |
||
663 | */ |
||
664 | 20 | protected function setLogging(Item $item) |
|
671 | |||
672 | /** |
||
673 | * Logs the item and what document was created from it |
||
674 | * |
||
675 | * @param Item $item The item that is being indexed. |
||
676 | * @param array $itemDocuments An array of Solr documents created from the item's data |
||
677 | * @param Apache_Solr_Response $response The Solr response for the particular index document |
||
678 | */ |
||
679 | 19 | protected function log(Item $item, array $itemDocuments, Apache_Solr_Response $response) |
|
708 | } |
||
709 |