Completed
Push — master ( c1e277...400ba4 )
by Timo
05:20
created

Indexer::getFieldConfigurationFromItemRecordPage()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3.1852

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 1
cts 3
cp 0.3333
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 3
nop 3
crap 3.1852
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 2 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 Apache_Solr_Document;
28
use Apache_Solr_Response;
29
use ApacheSolrForTypo3\Solr\ConnectionManager;
30
use ApacheSolrForTypo3\Solr\Domain\Search\ApacheSolrDocument\Builder;
31
use ApacheSolrForTypo3\Solr\FieldProcessor\Service;
32
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
33
use ApacheSolrForTypo3\Solr\Site;
34
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
35
use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository;
36
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
37
use ApacheSolrForTypo3\Solr\Util;
38
use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
39
use TYPO3\CMS\Core\Utility\GeneralUtility;
40
use TYPO3\CMS\Frontend\Page\PageRepository;
41
42
/**
43
 * A general purpose indexer to be used for indexing of any kind of regular
44
 * records like tt_news, tt_address, and so on.
45
 * Specialized indexers can extend this class to handle advanced stuff like
46
 * category resolution in tt_news or file indexing.
47
 *
48
 * @author Ingo Renner <[email protected]>
49
 */
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 22
     *
99
     * @param array $options array of indexer options
100 22
     * @param PagesRepository|null $pagesRepository
101 22
     * @param Builder|null $documentBuilder
102 22
     */
103 22
    public function __construct(array $options = [], PagesRepository $pagesRepository = null, Builder $documentBuilder = null)
104 22
    {
105
        $this->logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
106
        $this->options = $options;
107
        $this->connectionManager = GeneralUtility::makeInstance(ConnectionManager::class);
108
        $this->pagesRepository = isset($pagesRepository) ? $pagesRepository : GeneralUtility::makeInstance(PagesRepository::class);
109
        $this->documentBuilder = isset($documentBuilder) ? $documentBuilder : GeneralUtility::makeInstance(Builder::class);
110
    }
111
112 16
    /**
113
     * Indexes an item from the indexing queue.
114 16
     *
115
     * @param Item $item An index queue item
116 16
     * @return bool returns true when indexed, false when not
117 16
     */
118
    public function index(Item $item)
119 16
    {
120
        $indexed = true;
121 16
122 16
        $this->type = $item->getType();
123
        $this->setLogging($item);
124 16
125
        $solrConnections = $this->getSolrConnectionsByItem($item);
126
127
        foreach ($solrConnections as $systemLanguageUid => $solrConnection) {
128
            $this->solr = $solrConnection;
129
130
            if (!$this->indexItem($item, $systemLanguageUid)) {
131
                /*
132
                 * A single language voting for "not indexed" should make the whole
133 16
                 * item count as being not indexed, even if all other languages are
134
                 * indexed.
135
                 * If there is no translation for a single language, this item counts
136
                 * as TRUE since it's not an error which that should make the item
137 16
                 * being reindexed during another index run.
138
                 */
139
                $indexed = false;
140
            }
141
        }
142
143
        return $indexed;
144
    }
145
146
    /**
147 16
     * Creates a single Solr Document for an item in a specific language.
148
     *
149 16
     * @param Item $item An index queue item to index.
150 16
     * @param int $language The language to use.
151
     * @return bool TRUE if item was indexed successfully, FALSE on failure
152 16
     */
153 16
    protected function indexItem(Item $item, $language = 0)
154
    {
155
        $itemIndexed = false;
156
        $documents = [];
157
158
        $itemDocument = $this->itemToDocument($item, $language);
159
        if (is_null($itemDocument)) {
160
            /*
161
             * If there is no itemDocument, this means there was no translation
162
             * for this record. This should not stop the current item to count as
163 16
             * being valid because not-indexing not-translated items is perfectly
164 16
             * fine.
165 16
             */
166 16
            return true;
167
        }
168 16
169 16
        $documents[] = $itemDocument;
170 16
        $documents = array_merge($documents, $this->getAdditionalDocuments($item, $language, $itemDocument));
171
        $documents = $this->processDocuments($item, $documents);
172
        $documents = $this->preAddModifyDocuments($item, $language, $documents);
173 16
174
        $response = $this->solr->getWriteService()->addDocuments($documents);
175 16
        if ($response->getHttpStatus() == 200) {
176
            $itemIndexed = true;
177
        }
178
179
        $this->log($item, $documents, $response);
180
181
        return $itemIndexed;
182
    }
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 16
     * types.
190
     *
191 16
     * @param Item $item The item to be indexed
192
     * @param int $language Language Id (sys_language.uid)
193 16
     * @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 16
     */
195
    protected function getFullItemRecord(Item $item, $language = 0)
196
    {
197
        Util::initializeTsfe($item->getRootPageUid(), $language);
198
199
        $systemLanguageContentOverlay = $GLOBALS['TSFE']->sys_language_contentOL;
200
        $itemRecord = $this->getItemRecordOverlayed($item, $language, $systemLanguageContentOverlay);
201 16
202 16
        /*
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
        if (!empty($GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['disabled'])
208
            && $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 16
         * But if the requested language doesn't match the returned language and
218 16
         * the given record has no translation parent, the indexqueue_item most
219 15
         * 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 16
         */
223 16
        $translationOriginalPointerField = 'l10n_parent';
224 16
        if (!empty($GLOBALS['TCA'][$item->getType()]['ctrl']['transOrigPointerField'])) {
225 16
            $translationOriginalPointerField = $GLOBALS['TCA'][$item->getType()]['ctrl']['transOrigPointerField'];
226 16
        }
227 16
228
        $languageField = $GLOBALS['TCA'][$item->getType()]['ctrl']['languageField'];
229
        if ($itemRecord[$translationOriginalPointerField] == 0
230
            && $systemLanguageContentOverlay != 1
231
            && !empty($languageField)
232 16
            && $itemRecord[$languageField] != $language
233 16
            && $itemRecord[$languageField] != '-1'
234
        ) {
235
            $itemRecord = null;
236 16
        }
237
238
        if (!is_null($itemRecord)) {
239
            $itemRecord['__solr_index_language'] = $language;
240
        }
241
242
        return $itemRecord;
243
    }
244
245
    /**
246
     * Returns the overlayed item record.
247 16
     *
248
     * @param Item $item
249 16
     * @param int $language
250
     * @param string|null $systemLanguageContentOverlay
251 16
     * @return array|mixed|null
252 5
     */
253 5
    protected function getItemRecordOverlayed(Item $item, $language, $systemLanguageContentOverlay)
254 5
    {
255
        $itemRecord = $item->getRecord();
256
257 16
        if ($language > 0) {
258
            $page = GeneralUtility::makeInstance(PageRepository::class);
259
            $page->init(false);
260
            $itemRecord = $page->getRecordOverlay($item->getType(), $itemRecord, $language, $systemLanguageContentOverlay);
261 16
        }
262
263
        if (!$itemRecord) {
264
            $itemRecord = null;
265
        }
266
267
        return $itemRecord;
268
    }
269
270
    /**
271
     * Gets the configuration how to process an item's fields for indexing.
272 16
     *
273
     * @param Item $item An index queue item
274 16
     * @param int $language Language ID
275 16
     * @throws \RuntimeException
276 16
     * @return array Configuration array from TypoScript
277 1
     */
278 1
    protected function getItemTypeConfiguration(Item $item, $language = 0)
279
    {
280
        $indexConfigurationName = $item->getIndexingConfigurationName();
281
        $fields = $this->getFieldConfigurationFromItemRecordPage($item, $language, $indexConfigurationName);
282
        if (count($fields) === 0) {
283
            $fields = $this->getFieldConfigurationFromItemRootPage($item, $language, $indexConfigurationName);
284 16
            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
        return $fields;
291
    }
292
293
    /**
294
     * The method retrieves the field configuration of the items record page id (pid).
295 16
     *
296
     * @param Item $item
297
     * @param integer $language
298 16
     * @param string $indexConfigurationName
299 15
     * @return array
300 1
     */
301 1
    protected function getFieldConfigurationFromItemRecordPage(Item $item, $language, $indexConfigurationName)
302
    {
303
        try {
304
            $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRecordPageId(), true, $language);
305
            return $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName, []);
306
        } catch (\Exception $e) {
307
            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 1
     *
314
     * @param Item $item
315 1
     * @param integer $language
316 1
     * @param string $indexConfigurationName
317
     * @return array
318
     */
319
    protected function getFieldConfigurationFromItemRootPage(Item $item, $language, $indexConfigurationName)
320 1
    {
321
        $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRootPageUid(), true, $language);
322
        if (empty($solrConfiguration->getIndexQueueAdditionalPageIdsByConfigurationName($indexConfigurationName))) {
323
            return [];
324
        }
325
326
        return $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName, []);
327
    }
328
329
    /**
330
     * Converts an item array (record) to a Solr document by mapping the
331 16
     * record's fields onto Solr document fields as configured in TypoScript.
332
     *
333 16
     * @param Item $item An index queue item
334
     * @param int $language Language Id
335 16
     * @return Apache_Solr_Document The Solr document converted from the record
336 16
     */
337 16
    protected function itemToDocument(Item $item, $language = 0)
338 16
    {
339 16
        $document = null;
340
341
        $itemRecord = $this->getFullItemRecord($item, $language);
342 16
        if (!is_null($itemRecord)) {
343
            $itemIndexingConfiguration = $this->getItemTypeConfiguration($item, $language);
344
            $document = $this->getBaseDocument($item, $itemRecord);
345
            $document = $this->addDocumentFieldsFromTyposcript($document, $itemIndexingConfiguration, $itemRecord);
346
        }
347
348
        return $document;
349
    }
350
351
    /**
352 16
     * Creates a Solr document with the basic / core fields set already.
353
     *
354 16
     * @param Item $item The item to index
355 16
     * @param array $itemRecord The record to use to build the base document
356
     * @return Apache_Solr_Document A basic Solr document
357 16
     */
358
    protected function getBaseDocument(Item $item, array $itemRecord)
359
    {
360
        $type = $item->getType();
361 16
        $rootPageUid = $item->getRootPageUid();
362 16
        $accessRootLine = $this->getAccessRootline($item);
363 16
        return $this->documentBuilder->fromRecord($itemRecord, $type, $rootPageUid, $accessRootLine);
364
    }
365
366 16
    /**
367 16
     * Generates an Access Rootline for an item.
368
     *
369
     * @param Item $item Index Queue item to index.
370 16
     * @return string The Access Rootline for the item
371 16
     */
372
    protected function getAccessRootline(Item $item)
373
    {
374 16
        $accessRestriction = '0';
375 16
        $itemRecord = $item->getRecord();
376
377
        // TODO support access restrictions set on storage page
378 16
379 16
        if (isset($GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group'])) {
380 16
            $accessRestriction = $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group']];
381
382 16
            if (empty($accessRestriction)) {
383 16
                // public
384 16
                $accessRestriction = '0';
385
            }
386
        }
387
388 16
        return 'r:' . $accessRestriction;
389 16
    }
390 16
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 16
     * @param array $documents An array of Apache_Solr_Document objects to manipulate.
397
     * @return array Array of manipulated Apache_Solr_Document objects.
398
     */
399
    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
        $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRootPageUid());
403
        $fieldProcessingInstructions = $solrConfiguration->getIndexFieldProcessingInstructionsConfiguration();
404
405 16
        // same as in the FE indexer
406
        if (is_array($fieldProcessingInstructions)) {
407 16
            $service = GeneralUtility::makeInstance(Service::class);
408 16
            $service->processDocuments($documents, $fieldProcessingInstructions);
409
        }
410
411
        return $documents;
412 16
    }
413 1
414
    /**
415 1
     * Allows third party extensions to provide additional documents which
416
     * should be indexed for the current item.
417 1
     *
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 16
     * @return array An array of additional Apache_Solr_Document objects to index.
422
     */
423
    protected function getAdditionalDocuments(Item $item, $language, Apache_Solr_Document $itemDocument)
424
    {
425
        $documents = [];
426
427
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments'])) {
428
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments'] as $classReference) {
429
                if (!class_exists($classReference)) {
430
                    throw new \InvalidArgumentException('Class does not exits' . $classReference, 1490363487);
431
                }
432 16
                $additionalIndexer = GeneralUtility::makeInstance($classReference);
433
                if ($additionalIndexer instanceof AdditionalIndexQueueItemIndexer) {
434
                    $additionalDocuments = $additionalIndexer->getAdditionalItemDocuments($item, $language, $itemDocument);
435 16
436 16
                    if (is_array($additionalDocuments)) {
437
                        $documents = array_merge($documents,
438
                            $additionalDocuments);
439 16
                    }
440 16
                } else {
441 16
                    throw new \UnexpectedValueException(
442
                        get_class($additionalIndexer) . ' must implement interface ' . AdditionalIndexQueueItemIndexer::class,
443
                        1326284551
444
                    );
445
                }
446
            }
447 16
        }
448
        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 20
     */
460
    protected function preAddModifyDocuments(Item $item, $language, array $documents)
461
    {
462
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'])) {
463
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'] as $classReference) {
464 20
                $documentsModifier = GeneralUtility::getUserObj($classReference);
465
466 20
                if ($documentsModifier instanceof PageIndexerDocumentsModifier) {
467 4
                    $documents = $documentsModifier->modifyDocuments($item, $language, $documents);
468 4
                } else {
469 2
                    throw new \RuntimeException(
470
                        'The class "' . get_class($documentsModifier)
471 2
                        . '" registered as document modifier in hook
472 2
							preAddModifyDocuments must implement interface
473 1
							ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerDocumentsModifier',
474
                        1309522677
475
                    );
476 1
                }
477 1
            }
478
        }
479
480
        return $documents;
481 1
    }
482 1
483 2
    // Initialization
484
485
    /**
486
     * Gets the Solr connections applicable for an item.
487
     *
488 17
     * 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
    protected function getSolrConnectionsByItem(Item $item)
495
    {
496
        $solrConnections = [];
497
498
        $pageId = $item->getRootPageUid();
499
        if ($item->getType() === 'pages') {
500 16
            $pageId = $item->getRecordUid();
501
        }
502
503
        // Solr configurations possible for this item
504
        $site = $item->getSite();
505 16
506
        $solrConfigurationsBySite = $this->connectionManager->getConfigurationsBySite($site);
507
        $siteLanguages = [];
508
        foreach ($solrConfigurationsBySite as $solrConfiguration) {
509
            $siteLanguages[] = $solrConfiguration['language'];
510
        }
511
512
        $defaultLanguageUid = $this->getDefaultLanguageUid($item, $site->getRootPage(), $siteLanguages);
513
        $translationOverlays = $this->getTranslationOverlaysWithConfiguredSite($pageId, $site, $defaultLanguageUid, $siteLanguages);
514
515
        $defaultConnection = $this->connectionManager->getConnectionByPageId($pageId, 0, $item->getMountPointIdentifier());
516
        $translationConnections = $this->getConnectionsForIndexableLanguages($translationOverlays);
517
518
        if ($defaultLanguageUid == 0) {
519
            $solrConnections[0] = $defaultConnection;
520
        }
521
522
        foreach ($translationConnections as $systemLanguageUid => $solrConnection) {
523
            $solrConnections[$systemLanguageUid] = $solrConnection;
524 16
        }
525
526
        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 18
    protected function getTranslationOverlaysWithConfiguredSite($pageId, Site $site, $defaultLanguageUid, $siteLanguages)
539
    {
540 18
        $translationOverlays = $this->getTranslationOverlaysForPage($pageId, $site->getSysLanguageMode($defaultLanguageUid));
541
542 18
        foreach ($translationOverlays as $key => $translationOverlay) {
543 18
            if (!in_array($translationOverlay['sys_language_uid'], $siteLanguages)) {
544 3
                unset($translationOverlays[$key]);
545
            }
546
        }
547
548 18
        return $translationOverlays;
549
    }
550 18
551 18
    /**
552 18
     * @param Item $item An index queue item
553 18
     * @param array $rootPage
554
     * @param array $siteLanguages
555
     *
556 18
     * @return int
557 18
     * @throws \Apache_Solr_Exception
558
     */
559 18
    private function getDefaultLanguageUid(Item $item, array $rootPage, array $siteLanguages)
560 18
    {
561
        $defaultLanguageUid = 0;
562 18
        if (($rootPage['l18n_cfg'] & 1) == 1 && count($siteLanguages) > 1) {
563 17
            unset($siteLanguages[array_search('0', $siteLanguages)]);
564
            $defaultLanguageUid = $siteLanguages[min(array_keys($siteLanguages))];
565
        } elseif (($rootPage['l18n_cfg'] & 1) == 1 && count($siteLanguages) == 1) {
566 18
            $message = 'Root page ' . (int)$item->getRootPageUid() . ' is set to hide default translation, but no other language is configured!';
567 6
            throw new \Apache_Solr_Exception($message);
568
        }
569
570 18
        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 18
     *
583
     * @param int $pageId Page ID.
584 18
     * @param string $languageMode
585
     * @return array An array of translation overlays (or fake overlays) found for the given page.
586 18
     */
587 6
    protected function getTranslationOverlaysForPage($pageId, $languageMode)
588 6
    {
589
        $translationOverlays = [];
590
        $pageId = intval($pageId);
591
592 18
        $languageModes = ['content_fallback', 'strict', 'ignore'];
593
        $hasOverlayMode = in_array($languageMode, $languageModes,
594
            true);
595
        $isContentFallbackMode = ($languageMode === 'content_fallback');
596
597
        if ($hasOverlayMode && !$isContentFallbackMode) {
598
            $translationOverlays = $this->pagesRepository->findTranslationOverlaysByPageId($pageId);
599
        } else {
600
            // ! If no sys_language_mode is configured, all languages will be indexed !
601
            $languages = $this->getSystemLanguages();
602
            foreach ($languages as $language) {
603 18
                if ($language['uid'] <= 0) {
604
                    continue;
605 18
                }
606 18
                $translationOverlays[] = [
607 1
                    'pid' => $pageId,
608 1
                    'sys_language_uid' => $language['uid'],
609 17
                ];
610
            }
611
        }
612
613
        return $translationOverlays;
614 18
    }
615
616
    /**
617
     * Returns an array of system languages.
618
     *
619
     * @return array
620
     */
621
    protected function getSystemLanguages()
622
    {
623
        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 18
     * @return array An array of ApacheSolrForTypo3\Solr\System\Solr\SolrConnection connections.
632
     */
633 18
    protected function getConnectionsForIndexableLanguages(array $translationOverlays)
634 18
    {
635
        $connections = [];
636 18
637 18
        foreach ($translationOverlays as $translationOverlay) {
638 18
            $pageId = $translationOverlay['pid'];
639 18
            $languageId = $translationOverlay['sys_language_uid'];
640
641 18
            try {
642 5
                $connection = $this->connectionManager->getConnectionByPageId($pageId, $languageId);
643 5
                $connections[$languageId] = $connection;
644 5
            } catch (NoSolrConnectionFoundException $e) {
645 5
                // ignore the exception as we seek only those connections
646 5
                // actually available
647 5
            }
648
        }
649
650
        return $connections;
651 13
    }
652 13
653 13
    // Utility methods
654 13
655
    // FIXME extract log() and setLogging() to ApacheSolrForTypo3\Solr\IndexQueue\AbstractIndexer
656 1
    // FIXME extract an interface Tx_Solr_IndexQueue_ItemInterface
657 1
658 1
    /**
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 18
     */
664
    protected function setLogging(Item $item)
665
    {
666
        $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRootPageUid());
667
        $this->loggingEnabled = $solrConfiguration->getLoggingIndexingQueueOperationsByConfigurationNameWithFallBack(
668
            $item->getIndexingConfigurationName()
669
        );
670
    }
671 13
672
    /**
673 13
     * 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
    protected function log(Item $item, array $itemDocuments, Apache_Solr_Response $response)
680
    {
681
        if (!$this->loggingEnabled) {
682
            return;
683 18
        }
684
685
        $message = 'Index Queue indexing ' . $item->getType() . ':' . $item->getRecordUid() . ' - ';
686 18
687
        // preparing data
688 18
        $documents = [];
689 6
        foreach ($itemDocuments as $document) {
690 6
            $documents[] = (array)$document;
691
        }
692
693 6
        $logData = ['item' => (array)$item, 'documents' => $documents, 'response' => (array)$response];
694
695 6
        if ($response->getHttpStatus() == 200) {
696 6
            $severity = SolrLogManager::NOTICE;
697
            $message .= 'Success';
698
        } else {
699
            $severity = SolrLogManager::ERROR;
700
            $message .= 'Failure';
701
702 18
            $logData['status'] = $response->getHttpStatus();
703
            $logData['status message'] = $response->getHttpStatusMessage();
704
        }
705
706
        $this->logger->log($severity, $message, $logData);
707
    }
708
}
709