Completed
Push — master ( 5919d7...94bd1b )
by Rafael
05:28
created

Indexer::getBaseDocument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1.0156
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
     *
99
     * @param array $options array of indexer options
100
     * @param PagesRepository|null $pagesRepository
101
     * @param Builder|null $documentBuilder
102
     */
103
    public function __construct(array $options = [], PagesRepository $pagesRepository = null, Builder $documentBuilder = null)
104
    {
105 25
        $this->logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
106
        $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 25
112 25
    /**
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
    public function index(Item $item)
119
    {
120 19
        $indexed = true;
121
122 19
        $this->type = $item->getType();
123
        $this->setLogging($item);
124 19
125 19
        $solrConnections = $this->getSolrConnectionsByItem($item);
126
127 19
        foreach ($solrConnections as $systemLanguageUid => $solrConnection) {
128
            $this->solr = $solrConnection;
129 19
130 19
            if (!$this->indexItem($item, $systemLanguageUid)) {
131
                /*
132 19
                 * A single language voting for "not indexed" should make the whole
133
                 * 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
                 * being reindexed during another index run.
138
                 */
139
                $indexed = false;
140
            }
141 19
        }
142
143
        return $indexed;
144
    }
145 19
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
    protected function indexItem(Item $item, $language = 0)
154
    {
155 19
        $itemIndexed = false;
156
        $documents = [];
157 19
158 19
        $itemDocument = $this->itemToDocument($item, $language);
159
        if (is_null($itemDocument)) {
160 19
            /*
161 19
             * 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
             * being valid because not-indexing not-translated items is perfectly
164
             * fine.
165
             */
166
            return true;
167
        }
168 1
169
        $documents[] = $itemDocument;
170
        $documents = array_merge($documents, $this->getAdditionalDocuments($item, $language, $itemDocument));
171 19
        $documents = $this->processDocuments($item, $documents);
172 19
        $documents = $this->preAddModifyDocuments($item, $language, $documents);
173 19
174 19
        $response = $this->solr->getWriteService()->addDocuments($documents);
175
        if ($response->getHttpStatus() == 200) {
176 19
            $itemIndexed = true;
177 19
        }
178 19
179
        $this->log($item, $documents, $response);
180
181 19
        return $itemIndexed;
182
    }
183 19
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
    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
        $itemRecord = $this->getItemRecordOverlayed($item, $language, $systemLanguageContentOverlay);
201 19
202 19
        /*
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 19
        ) {
210 19
            $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
        $translationOriginalPointerField = 'l10n_parent';
224
        if (!empty($GLOBALS['TCA'][$item->getType()]['ctrl']['transOrigPointerField'])) {
225 19
            $translationOriginalPointerField = $GLOBALS['TCA'][$item->getType()]['ctrl']['transOrigPointerField'];
226 19
        }
227 18
228
        $languageField = $GLOBALS['TCA'][$item->getType()]['ctrl']['languageField'];
229
        if ($itemRecord[$translationOriginalPointerField] == 0
230 19
            && $systemLanguageContentOverlay != 1
231 19
            && !empty($languageField)
232 19
            && $itemRecord[$languageField] != $language
233 19
            && $itemRecord[$languageField] != '-1'
234 19
        ) {
235 19
            $itemRecord = null;
236
        }
237 1
238
        if (!is_null($itemRecord)) {
239
            $itemRecord['__solr_index_language'] = $language;
240 19
        }
241 19
242
        return $itemRecord;
243
    }
244 19
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
    protected function getItemRecordOverlayed(Item $item, $language, $systemLanguageContentOverlay)
254
    {
255 19
        $itemRecord = $item->getRecord();
256
257 19
        if ($language > 0) {
258
            $page = GeneralUtility::makeInstance(PageRepository::class);
259 19
            $page->init(false);
260 6
            $itemRecord = $page->getRecordOverlay($item->getType(), $itemRecord, $language, $systemLanguageContentOverlay);
261 6
        }
262 6
263
        if (!$itemRecord) {
264
            $itemRecord = null;
265 19
        }
266
267
        return $itemRecord;
268
    }
269 19
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
    protected function getItemTypeConfiguration(Item $item, $language = 0)
279
    {
280 19
        $indexConfigurationName = $item->getIndexingConfigurationName();
281
        $fields = $this->getFieldConfigurationFromItemRecordPage($item, $language, $indexConfigurationName);
282 19
        if (count($fields) === 0) {
283 19
            $fields = $this->getFieldConfigurationFromItemRootPage($item, $language, $indexConfigurationName);
284 19
            if (count($fields) === 0) {
285 1
                throw new \RuntimeException('The item indexing configuration "' . $item->getIndexingConfigurationName() .
286 1
                    '" on root page uid ' . $item->getRootPageUid() . ' could not be found!', 1455530112);
287
            }
288
        }
289
290
        return $fields;
291
    }
292 19
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
    protected function getFieldConfigurationFromItemRecordPage(Item $item, $language, $indexConfigurationName)
302
    {
303 19
        try {
304
            $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRecordPageId(), true, $language);
305
            return $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName, []);
306 19
        } catch (\Exception $e) {
307 18
            return [];
308 1
        }
309 1
    }
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
    protected function getFieldConfigurationFromItemRootPage(Item $item, $language, $indexConfigurationName)
320
    {
321 1
        $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRootPageUid(), true, $language);
322
        if (empty($solrConfiguration->getIndexQueueAdditionalPageIdsByConfigurationName($indexConfigurationName))) {
323 1
            return [];
324 1
        }
325
326
        return $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName, []);
327
    }
328 1
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
    protected function itemToDocument(Item $item, $language = 0)
338
    {
339 19
        $document = null;
340
341 19
        $itemRecord = $this->getFullItemRecord($item, $language);
342
        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 19
        }
347 19
348
        return $document;
349
    }
350 19
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
    protected function getBaseDocument(Item $item, array $itemRecord)
359
    {
360 19
        $type = $item->getType();
361
        $rootPageUid = $item->getRootPageUid();
362 19
        $accessRootLine = $this->getAccessRootline($item);
363 19
        return $this->documentBuilder->fromRecord($itemRecord, $type, $rootPageUid, $accessRootLine);
364
    }
365 19
366
    /**
367
     * Generates an Access Rootline for an item.
368
     *
369 19
     * @param Item $item Index Queue item to index.
370 19
     * @return string The Access Rootline for the item
371 19
     */
372
    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 19
379 19
        if (isset($GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group'])) {
380
            $accessRestriction = $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group']];
381
382 19
            if (empty($accessRestriction)) {
383 19
                // public
384
                $accessRestriction = '0';
385
            }
386 19
        }
387 19
388 19
        return 'r:' . $accessRestriction;
389
    }
390 19
391 19
    /**
392 19
     * 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 19
     * @param array $documents An array of Apache_Solr_Document objects to manipulate.
397 19
     * @return array Array of manipulated Apache_Solr_Document objects.
398 19
     */
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 19
405
        // same as in the FE indexer
406
        if (is_array($fieldProcessingInstructions)) {
407
            $service = GeneralUtility::makeInstance(Service::class);
408
            $service->processDocuments($documents, $fieldProcessingInstructions);
409
        }
410
411
        return $documents;
412
    }
413 19
414
    /**
415 19
     * Allows third party extensions to provide additional documents which
416 19
     * 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 19
     * @param Apache_Solr_Document $itemDocument The document representing the item for the given language.
421 1
     * @return array An array of additional Apache_Solr_Document objects to index.
422
     */
423 1
    protected function getAdditionalDocuments(Item $item, $language, Apache_Solr_Document $itemDocument)
424
    {
425 1
        $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 19
                if (!class_exists($classReference)) {
430
                    throw new \InvalidArgumentException('Class does not exits' . $classReference, 1490363487);
431
                }
432
                $additionalIndexer = GeneralUtility::makeInstance($classReference);
433
                if ($additionalIndexer instanceof AdditionalIndexQueueItemIndexer) {
434
                    $additionalDocuments = $additionalIndexer->getAdditionalItemDocuments($item, $language, $itemDocument);
435
436
                    if (is_array($additionalDocuments)) {
437
                        $documents = array_merge($documents,
438
                            $additionalDocuments);
439
                    }
440 19
                } else {
441
                    throw new \UnexpectedValueException(
442
                        get_class($additionalIndexer) . ' must implement interface ' . AdditionalIndexQueueItemIndexer::class,
443 19
                        1326284551
444 19
                    );
445
                }
446
            }
447 19
        }
448 19
        return $documents;
449 19
    }
450 19
451 19
    /**
452
     * Provides a hook to manipulate documents right before they get added to
453
     * the Solr index.
454
     *
455 19
     * @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
    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
                $documentsModifier = GeneralUtility::getUserObj($classReference);
465
466
                if ($documentsModifier instanceof PageIndexerDocumentsModifier) {
467 23
                    $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 23
							preAddModifyDocuments must implement interface
473
							ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerDocumentsModifier',
474 23
                        1309522677
475 4
                    );
476 4
                }
477 2
            }
478
        }
479 2
480 2
        return $documents;
481 1
    }
482 1
483
    // Initialization
484 1
485 1
    /**
486 1
     * Gets the Solr connections applicable for an item.
487
     *
488
     * The connections include the default connection and connections to be used
489 1
     * for translations of an item.
490 1
     *
491 2
     * @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 20
        $solrConnections = [];
497
498
        $pageId = $item->getRootPageUid();
499
        if ($item->getType() === 'pages') {
500
            $pageId = $item->getRecordUid();
501
        }
502
503
        // Solr configurations possible for this item
504
        $site = $item->getSite();
505
506
        $solrConfigurationsBySite = $this->connectionManager->getConfigurationsBySite($site);
507
        $siteLanguages = [];
508 19
        foreach ($solrConfigurationsBySite as $solrConfiguration) {
509
            $siteLanguages[] = $solrConfiguration['language'];
510
        }
511
512
        $defaultLanguageUid = $this->getDefaultLanguageUid($item, $site->getRootPage(), $siteLanguages);
513 19
        $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
        }
525
526
        return $solrConnections;
527
    }
528
529
    /**
530
     * Retrieves only translation overlays where a solr site is configured.
531
     *
532 19
     * @param int $pageId
533
     * @param Site $site
534
     * @param int $defaultLanguageUid
535
     * @param $siteLanguages
536
     * @return array
537
     */
538
    protected function getTranslationOverlaysWithConfiguredSite($pageId, Site $site, $defaultLanguageUid, $siteLanguages)
539
    {
540
        $translationOverlays = $this->getTranslationOverlaysForPage($pageId, $site->getSysLanguageMode($defaultLanguageUid));
541
542
        foreach ($translationOverlays as $key => $translationOverlay) {
543
            if (!in_array($translationOverlay['sys_language_uid'], $siteLanguages)) {
544
                unset($translationOverlays[$key]);
545
            }
546 21
        }
547
548 21
        return $translationOverlays;
549
    }
550 21
551 21
    /**
552 3
     * @param Item $item An index queue item
553
     * @param array $rootPage
554
     * @param array $siteLanguages
555
     *
556 21
     * @return int
557
     * @throws \Apache_Solr_Exception
558 21
     */
559 21
    private function getDefaultLanguageUid(Item $item, array $rootPage, array $siteLanguages)
560 21
    {
561 21
        $defaultLanguageUid = 0;
562
        if (($rootPage['l18n_cfg'] & 1) == 1 && count($siteLanguages) > 1) {
563
            unset($siteLanguages[array_search('0', $siteLanguages)]);
564 21
            $defaultLanguageUid = $siteLanguages[min(array_keys($siteLanguages))];
565 21
        } 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 21
            throw new \Apache_Solr_Exception($message);
568 21
        }
569
570 21
        return $defaultLanguageUid;
571 20
    }
572
573
    /**
574 21
     * Finds the alternative page language overlay records for a page based on
575 7
     * the sys_language_mode.
576
     *
577
     * Possible Language Modes:
578 21
     * 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
    protected function getTranslationOverlaysForPage($pageId, $languageMode)
588
    {
589
        $translationOverlays = [];
590 21
        $pageId = intval($pageId);
591
592 21
        $languageModes = ['content_fallback', 'strict', 'ignore'];
593
        $hasOverlayMode = in_array($languageMode, $languageModes,
594 21
            true);
595 7
        $isContentFallbackMode = ($languageMode === 'content_fallback');
596 7
597
        if ($hasOverlayMode && !$isContentFallbackMode) {
598
            $translationOverlays = $this->pagesRepository->findTranslationOverlaysByPageId($pageId);
599
        } else {
600 21
            // ! If no sys_language_mode is configured, all languages will be indexed !
601
            $languages = $this->getSystemLanguages();
602
            foreach ($languages as $language) {
603
                if ($language['uid'] <= 0) {
604
                    continue;
605
                }
606
                $translationOverlays[] = [
607
                    'pid' => $pageId,
608
                    'sys_language_uid' => $language['uid'],
609
                ];
610
            }
611 21
        }
612
613 21
        return $translationOverlays;
614 21
    }
615 1
616 1
    /**
617 20
     * Returns an array of system languages.
618
     *
619
     * @return array
620
     */
621
    protected function getSystemLanguages()
622 21
    {
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
     * @return array An array of ApacheSolrForTypo3\Solr\System\Solr\SolrConnection connections.
632
     */
633
    protected function getConnectionsForIndexableLanguages(array $translationOverlays)
634
    {
635
        $connections = [];
636
637
        foreach ($translationOverlays as $translationOverlay) {
638
            $pageId = $translationOverlay['pid'];
639 21
            $languageId = $translationOverlay['sys_language_uid'];
640
641 21
            try {
642 21
                $connection = $this->connectionManager->getConnectionByPageId($pageId, $languageId);
643
                $connections[$languageId] = $connection;
644 21
            } catch (NoSolrConnectionFoundException $e) {
645 21
                // ignore the exception as we seek only those connections
646 21
                // actually available
647 21
            }
648
        }
649 21
650 6
        return $connections;
651
    }
652
653 15
    // Utility methods
654 15
655 15
    // FIXME extract log() and setLogging() to ApacheSolrForTypo3\Solr\IndexQueue\AbstractIndexer
656 15
    // FIXME extract an interface Tx_Solr_IndexQueue_ItemInterface
657
658 1
    /**
659 1
     * Enables logging dependent on the configuration of the item's site
660 1
     *
661
     * @param Item $item An item being indexed
662
     * @return    void
663
     */
664
    protected function setLogging(Item $item)
665 21
    {
666
        $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRootPageUid());
667
        $this->loggingEnabled = $solrConfiguration->getLoggingIndexingQueueOperationsByConfigurationNameWithFallBack(
668
            $item->getIndexingConfigurationName()
669
        );
670
    }
671
672
    /**
673 15
     * Logs the item and what document was created from it
674
     *
675 15
     * @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
        }
684
685 21
        $message = 'Index Queue indexing ' . $item->getType() . ':' . $item->getRecordUid() . ' - ';
686
687
        // preparing data
688 21
        $documents = [];
689
        foreach ($itemDocuments as $document) {
690 21
            $documents[] = (array)$document;
691 7
        }
692 7
693
        $logData = ['item' => (array)$item, 'documents' => $documents, 'response' => (array)$response];
694
695 7
        if ($response->getHttpStatus() == 200) {
696 7
            $severity = SolrLogManager::NOTICE;
697 7
            $message .= 'Success';
698 7
        } else {
699
            $severity = SolrLogManager::ERROR;
700
            $message .= 'Failure';
701
702
            $logData['status'] = $response->getHttpStatus();
703
            $logData['status message'] = $response->getHttpStatusMessage();
704 21
        }
705
706
        $this->logger->log($severity, $message, $logData);
707
    }
708
}
709