Passed
Push — master ( 90cea8...3d6c73 )
by Timo
01:26
created

Indexer::log()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 41
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 16.1287

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 3
cts 34
cp 0.0882
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 27
nc 5
nop 3
crap 16.1287
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\Variants\IdBuilder;
31
use ApacheSolrForTypo3\Solr\FieldProcessor\Service;
32
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
33
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository;
34
use ApacheSolrForTypo3\Solr\SolrService;
35
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
36
use ApacheSolrForTypo3\Solr\Util;
37
use TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider;
38
use TYPO3\CMS\Backend\Utility\BackendUtility;
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 SolrService
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 IdBuilder
83
     */
84
    protected $variantIdBuilder;
85
86
    /**
87
     * Cache of the sys_language_overlay information
88
     *
89
     * @var array
90
     */
91
    protected static $sysLanguageOverlay = [];
92
93
    /**
94
     * @var \ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager
95
     */
96
    protected $logger = null;
97
98
    /**
99
     * Constructor
100
     *
101
     * @param array $options array of indexer options
102
     * @param IdBuilder $idBuilder
103
     */
104 16
    public function __construct(array $options = [], IdBuilder $idBuilder = null)
105
    {
106 16
        $this->logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
107 16
        $this->options = $options;
108 16
        $this->connectionManager = GeneralUtility::makeInstance(ConnectionManager::class);
109 16
        $this->variantIdBuilder = is_null($idBuilder) ? GeneralUtility::makeInstance(IdBuilder::class) : $idBuilder;
110 16
    }
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 11
    public function index(Item $item)
119
    {
120 11
        $indexed = true;
121
122 11
        $this->type = $item->getType();
123 11
        $this->setLogging($item);
124
125 11
        $solrConnections = $this->getSolrConnectionsByItem($item);
126
127 11
        foreach ($solrConnections as $systemLanguageUid => $solrConnection) {
128 11
            $this->solr = $solrConnection;
129
130 11
            if (!$this->indexItem($item, $systemLanguageUid)) {
131
                /*
132
                 * 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 11
        }
142
143 11
        return $indexed;
144
    }
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 11
    protected function indexItem(Item $item, $language = 0)
154
    {
155 11
        $itemIndexed = false;
156 11
        $documents = [];
157
158 11
        $itemDocument = $this->itemToDocument($item, $language);
159 11
        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
             * being valid because not-indexing not-translated items is perfectly
164
             * fine.
165
             */
166
            return true;
167
        }
168
169 11
        $documents[] = $itemDocument;
170 11
        $documents = array_merge($documents, $this->getAdditionalDocuments($item, $language, $itemDocument));
171 11
        $documents = $this->processDocuments($item, $documents);
172 11
        $documents = $this->preAddModifyDocuments($item, $language, $documents);
173
174 11
        $response = $this->solr->addDocuments($documents);
175 11
        if ($response->getHttpStatus() == 200) {
176 11
            $itemIndexed = true;
177 11
        }
178
179 11
        $this->log($item, $documents, $response);
180
181 11
        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
     * 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 11
    protected function getFullItemRecord(Item $item, $language = 0)
196
    {
197 11
        $rootPageUid = $item->getRootPageUid();
198 11
        $overlayIdentifier = $rootPageUid . '|' . $language;
199 11
        if (!isset(self::$sysLanguageOverlay[$overlayIdentifier])) {
200 11
            Util::initializeTsfe($rootPageUid, $language);
201 11
            self::$sysLanguageOverlay[$overlayIdentifier] = $GLOBALS['TSFE']->sys_language_contentOL;
202 11
        }
203
204 11
        $itemRecord = $item->getRecord();
205
206 11
        if ($language > 0) {
207 1
            $page = GeneralUtility::makeInstance(PageRepository::class);
208 1
            $page->init(false);
209
210 1
            $itemRecord = $page->getRecordOverlay(
211 1
                $item->getType(),
212 1
                $itemRecord,
213 1
                $language,
214 1
                self::$sysLanguageOverlay[$overlayIdentifier]
215 1
            );
216 1
        }
217
218 11
        if (!$itemRecord) {
219
            $itemRecord = null;
220
        }
221
222
        /*
223
         * Skip disabled records. This happens if the default language record
224
         * is hidden but a certain translation isn't. Then the default language
225
         * document appears here but must not be indexed.
226
         */
227 11
        if (!empty($GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['disabled'])
228 11
            && $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['disabled']]
229 11
        ) {
230
            $itemRecord = null;
231
        }
232
233
        /*
234
         * Skip translation mismatching records. Sometimes the requested language
235
         * doesn't fit the returned language. This might happen with content fallback
236
         * and is perfectly fine in general.
237
         * But if the requested language doesn't match the returned language and
238
         * the given record has no translation parent, the indexqueue_item most
239
         * probably pointed to a non-translated language record that is dedicated
240
         * to a very specific language. Now we have to avoid indexing this record
241
         * into all language cores.
242
         */
243 11
        $translationOriginalPointerField = 'l10n_parent';
244 11
        if (!empty($GLOBALS['TCA'][$item->getType()]['ctrl']['transOrigPointerField'])) {
245 10
            $translationOriginalPointerField = $GLOBALS['TCA'][$item->getType()]['ctrl']['transOrigPointerField'];
246 10
        }
247
248 11
        $languageField = $GLOBALS['TCA'][$item->getType()]['ctrl']['languageField'];
249 11
        if ($itemRecord[$translationOriginalPointerField] == 0
250 11
            && self::$sysLanguageOverlay[$overlayIdentifier] != 1
251 11
            && !empty($languageField)
252 11
            && $itemRecord[$languageField] != $language
253 11
            && $itemRecord[$languageField] != '-1'
254 11
        ) {
255
            $itemRecord = null;
256
        }
257
258 11
        if (!is_null($itemRecord)) {
259 11
            $itemRecord['__solr_index_language'] = $language;
260 11
        }
261
262 11
        return $itemRecord;
263
    }
264
265
    /**
266
     * Gets the configuration how to process an item's fields for indexing.
267
     *
268
     * @param Item $item An index queue item
269
     * @param int $language Language ID
270
     * @throws \RuntimeException
271
     * @return array Configuration array from TypoScript
272
     */
273 11
    protected function getItemTypeConfiguration(Item $item, $language = 0)
274
    {
275 11
        $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRecordPageId(), true, $language);
276 11
        $indexConfigurationName = $item->getIndexingConfigurationName();
277 11
        $fields = $solrConfiguration->getIndexQueueFieldsConfigurationByConfigurationName($indexConfigurationName, []);
278
279 11
        if (count($fields) === 0) {
280
            throw new \RuntimeException('The item indexing configuration "' . $item->getIndexingConfigurationName() .
281
                '" on root page uid ' . $item->getRootPageUid() . ' could not be found!', 1455530112);
282
        }
283
284 11
        return $fields;
285
    }
286
287
    /**
288
     * Converts an item array (record) to a Solr document by mapping the
289
     * record's fields onto Solr document fields as configured in TypoScript.
290
     *
291
     * @param Item $item An index queue item
292
     * @param int $language Language Id
293
     * @return Apache_Solr_Document The Solr document converted from the record
294
     */
295 11
    protected function itemToDocument(Item $item, $language = 0)
296
    {
297 11
        $document = null;
298
299 11
        $itemRecord = $this->getFullItemRecord($item, $language);
300 11
        if (!is_null($itemRecord)) {
301 11
            $itemIndexingConfiguration = $this->getItemTypeConfiguration($item, $language);
302 11
            $document = $this->getBaseDocument($item, $itemRecord);
303 11
            $document = $this->addDocumentFieldsFromTyposcript($document, $itemIndexingConfiguration, $itemRecord);
304 11
        }
305
306 11
        return $document;
307
    }
308
309
    /**
310
     * Creates a Solr document with the basic / core fields set already.
311
     *
312
     * @param Item $item The item to index
313
     * @param array $itemRecord The record to use to build the base document
314
     * @return Apache_Solr_Document A basic Solr document
315
     */
316 11
    protected function getBaseDocument(Item $item, array $itemRecord)
317
    {
318 11
        $siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
319 11
        $site = $siteRepository->getSiteByRootPageId($item->getRootPageUid());
320
321 11
        $document = GeneralUtility::makeInstance(Apache_Solr_Document::class);
322
        /* @var $document Apache_Solr_Document */
323
324
        // required fields
325 11
        $document->setField('id', Util::getDocumentId(
326 11
            $item->getType(),
327 11
            $itemRecord['pid'],
328 11
            $itemRecord['uid']
329 11
        ));
330 11
        $document->setField('type', $item->getType());
331 11
        $document->setField('appKey', 'EXT:solr');
332
333
        // site, siteHash
334 11
        $document->setField('site', $site->getDomain());
335 11
        $document->setField('siteHash', $site->getSiteHash());
336
337
        // uid, pid
338 11
        $document->setField('uid', $itemRecord['uid']);
339 11
        $document->setField('pid', $itemRecord['pid']);
340
341
        // variantId
342 11
        $variantId = $this->variantIdBuilder->buildFromTypeAndUid($item->getType(), $itemRecord['uid']);
343 11
        $document->setField('variantId', $variantId);
344
345
        // created, changed
346 11
        if (!empty($GLOBALS['TCA'][$item->getType()]['ctrl']['crdate'])) {
347 11
            $document->setField('created',
348 11
                $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['crdate']]);
349 11
        }
350 11
        if (!empty($GLOBALS['TCA'][$item->getType()]['ctrl']['tstamp'])) {
351 11
            $document->setField('changed',
352 11
                $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['tstamp']]);
353 11
        }
354
355
        // access, endtime
356 11
        $document->setField('access', $this->getAccessRootline($item));
357 11
        if (!empty($GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['endtime'])
358 11
            && $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['endtime']] != 0
359 11
        ) {
360
            $document->setField('endtime',
361
                $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['endtime']]);
362
        }
363
364 11
        return $document;
365
    }
366
367
    /**
368
     * Generates an Access Rootline for an item.
369
     *
370
     * @param Item $item Index Queue item to index.
371
     * @return string The Access Rootline for the item
372
     */
373 11
    protected function getAccessRootline(Item $item)
374
    {
375 11
        $accessRestriction = '0';
376 11
        $itemRecord = $item->getRecord();
377
378
        // TODO support access restrictions set on storage page
379
380 11
        if (isset($GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group'])) {
381 1
            $accessRestriction = $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group']];
382
383 1
            if (empty($accessRestriction)) {
384
                // public
385 1
                $accessRestriction = '0';
386 1
            }
387 1
        }
388
389 11
        return 'r:' . $accessRestriction;
390
    }
391
392
    /**
393
     * Sends the documents to the field processing service which takes care of
394
     * manipulating fields as defined in the field's configuration.
395
     *
396
     * @param Item $item An index queue item
397
     * @param array $documents An array of Apache_Solr_Document objects to manipulate.
398
     * @return array Array of manipulated Apache_Solr_Document objects.
399
     */
400 11
    protected function processDocuments(Item $item, array $documents)
401
    {
402
        // needs to respect the TS settings for the page the item is on, conditions may apply
403 11
        $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRootPageUid());
404 11
        $fieldProcessingInstructions = $solrConfiguration->getIndexFieldProcessingInstructionsConfiguration();
405
406
        // same as in the FE indexer
407 11
        if (is_array($fieldProcessingInstructions)) {
408 11
            $service = GeneralUtility::makeInstance(Service::class);
409 11
            $service->processDocuments(
410 11
                $documents,
411
                $fieldProcessingInstructions
412 11
            );
413 11
        }
414
415 11
        return $documents;
416
    }
417
418
    /**
419
     * Allows third party extensions to provide additional documents which
420
     * should be indexed for the current item.
421
     *
422
     * @param Item $item The item currently being indexed.
423
     * @param int $language The language uid currently being indexed.
424
     * @param Apache_Solr_Document $itemDocument The document representing the item for the given language.
425
     * @return array An array of additional Apache_Solr_Document objects to index.
426
     */
427 15
    protected function getAdditionalDocuments(
428
        Item $item,
429
        $language,
430
        Apache_Solr_Document $itemDocument
431
    ) {
432 15
        $documents = [];
433
434 15
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments'])) {
435 4
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['indexItemAddDocuments'] as $classReference) {
436 4
                if (!class_exists($classReference)) {
437 2
                    throw new \InvalidArgumentException('Class does not exits' . $classReference, 1490363487);
438
                }
439 2
                $additionalIndexer = GeneralUtility::makeInstance($classReference);
440 2
                if ($additionalIndexer instanceof AdditionalIndexQueueItemIndexer) {
441 1
                    $additionalDocuments = $additionalIndexer->getAdditionalItemDocuments($item,
442 1
                        $language, $itemDocument);
443
444 1
                    if (is_array($additionalDocuments)) {
445 1
                        $documents = array_merge($documents,
446 1
                            $additionalDocuments);
447 1
                    }
448 1
                } else {
449 1
                    throw new \UnexpectedValueException(
450 1
                        get_class($additionalIndexer) . ' must implement interface ' . AdditionalIndexQueueItemIndexer::class,
451
                        1326284551
452 1
                    );
453
                }
454 1
            }
455 1
        }
456 12
        return $documents;
457
    }
458
459
    /**
460
     * Provides a hook to manipulate documents right before they get added to
461
     * the Solr index.
462
     *
463
     * @param Item $item The item currently being indexed.
464
     * @param int $language The language uid of the documents
465
     * @param array $documents An array of documents to be indexed
466
     * @return array An array of modified documents
467
     */
468 11
    protected function preAddModifyDocuments(
469
        Item $item,
470
        $language,
471
        array $documents
472
    ) {
473 11
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'])) {
474
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['IndexQueueIndexer']['preAddModifyDocuments'] as $classReference) {
475
                $documentsModifier = GeneralUtility::getUserObj($classReference);
476
477
                if ($documentsModifier instanceof PageIndexerDocumentsModifier) {
478
                    $documents = $documentsModifier->modifyDocuments($item,
479
                        $language, $documents);
480
                } else {
481
                    throw new \RuntimeException(
482
                        'The class "' . get_class($documentsModifier)
483
                        . '" registered as document modifier in hook
484
							preAddModifyDocuments must implement interface
485
							ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerDocumentsModifier',
486
                        1309522677
487
                    );
488
                }
489
            }
490
        }
491
492 11
        return $documents;
493
    }
494
495
    // Initialization
496
497
    /**
498
     * Gets the Solr connections applicable for an item.
499
     *
500
     * The connections include the default connection and connections to be used
501
     * for translations of an item.
502
     *
503
     * @param Item $item An index queue item
504
     * @return array An array of ApacheSolrForTypo3\Solr\SolrService connections, the array's keys are the sys_language_uid of the language of the connection
505
     */
506 12
    protected function getSolrConnectionsByItem(Item $item)
507
    {
508 12
        $solrConnections = [];
509
510 12
        $pageId = $item->getRootPageUid();
511 12
        if ($item->getType() == 'pages') {
512 2
            $pageId = $item->getRecordUid();
513 2
        }
514
515
        // Solr configurations possible for this item
516 12
        $site = $item->getSite();
517 12
        $solrConfigurationsBySite = $this->connectionManager->getConfigurationsBySite($site);
518
519 12
        $siteLanguages = [];
520 12
        foreach ($solrConfigurationsBySite as $solrConfiguration) {
521 12
            $siteLanguages[] = $solrConfiguration['language'];
522 12
        }
523
524 12
        $translationOverlays = $this->getTranslationOverlaysForPage($pageId, $site->getSysLanguageMode());
525 12
        foreach ($translationOverlays as $key => $translationOverlay) {
526 1
            if (!in_array($translationOverlay['sys_language_uid'],
527 1
                $siteLanguages)
528 1
            ) {
529
                unset($translationOverlays[$key]);
530
            }
531 12
        }
532
533 12
        $defaultConnection = $this->connectionManager->getConnectionByPageId($pageId);
534 12
        $translationConnections = $this->getConnectionsForIndexableLanguages($translationOverlays);
535
536 12
        $solrConnections[0] = $defaultConnection;
537 12
        foreach ($translationConnections as $systemLanguageUid => $solrConnection) {
538 1
            $solrConnections[$systemLanguageUid] = $solrConnection;
539 12
        }
540
541 12
        return $solrConnections;
542
    }
543
544
    /**
545
     * Finds the alternative page language overlay records for a page based on
546
     * the sys_language_mode.
547
     *
548
     * Possible Language Modes:
549
     * 1) content_fallback --> all languages
550
     * 2) strict --> available languages with page overlay
551
     * 3) ignore --> available languages with page overlay
552
     * 4) unknown mode or blank --> all languages
553
     *
554
     * @param int $pageId Page ID.
555
     * @param string $languageMode
556
     * @return array An array of translation overlays (or fake overlays) found for the given page.
557
     */
558 12
    protected function getTranslationOverlaysForPage($pageId, $languageMode)
559
    {
560 12
        $translationOverlays = [];
561 12
        $pageId = intval($pageId);
562
563 12
        $languageModes = ['content_fallback', 'strict', 'ignore'];
564 12
        $hasOverlayMode = in_array($languageMode, $languageModes,
565 12
            true);
566 12
        $isContentFallbackMode = ($languageMode === 'content_fallback');
567
568 12
        if ($hasOverlayMode && !$isContentFallbackMode) {
569 1
            $translationOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
570 1
                'pid, sys_language_uid',
571 1
                'pages_language_overlay',
572
                'pid = ' . $pageId
573 1
                . BackendUtility::deleteClause('pages_language_overlay')
574 1
                . BackendUtility::BEenableFields('pages_language_overlay')
575 1
            );
576 1
        } else {
577
            // ! If no sys_language_mode is configured, all languages will be indexed !
578 11
            $languages = $this->getSystemLanguages();
579
580 11
            foreach ($languages as $language) {
581 11
                if ($language['uid'] <= 0) {
582 11
                    continue;
583
                }
584
                $translationOverlays[] = [
585
                    'pid' => $pageId,
586
                    'sys_language_uid' => $language['uid'],
587
                ];
588 11
            }
589
        }
590
591 12
        return $translationOverlays;
592
    }
593
594
    /**
595
     * Returns an array of system languages.
596
     *
597
     * @return array
598
     */
599 11
    protected function getSystemLanguages()
600
    {
601 11
        return GeneralUtility::makeInstance(TranslationConfigurationProvider::class)->getSystemLanguages();
602
    }
603
604
    /**
605
     * Checks for which languages connections have been configured and returns
606
     * these connections.
607
     *
608
     * @param array $translationOverlays An array of translation overlays to check for configured connections.
609
     * @return array An array of ApacheSolrForTypo3\Solr\SolrService connections.
610
     */
611 12
    protected function getConnectionsForIndexableLanguages(
612
        array $translationOverlays
613
    ) {
614 12
        $connections = [];
615
616 12
        foreach ($translationOverlays as $translationOverlay) {
617 1
            $pageId = $translationOverlay['pid'];
618 1
            $languageId = $translationOverlay['sys_language_uid'];
619
620
            try {
621 1
                $connection = $this->connectionManager->getConnectionByPageId($pageId,
622 1
                    $languageId);
623 1
                $connections[$languageId] = $connection;
624 1
            } catch (NoSolrConnectionFoundException $e) {
625
                // ignore the exception as we seek only those connections
626
                // actually available
627
            }
628 12
        }
629
630 12
        return $connections;
631
    }
632
633
    // Utility methods
634
635
    // FIXME extract log() and setLogging() to ApacheSolrForTypo3\Solr\IndexQueue\AbstractIndexer
636
    // FIXME extract an interface Tx_Solr_IndexQueue_ItemInterface
637
638
    /**
639
     * Enables logging dependent on the configuration of the item's site
640
     *
641
     * @param Item $item An item being indexed
642
     * @return    void
643
     */
644 12
    protected function setLogging(Item $item)
645
    {
646 12
        $solrConfiguration = Util::getSolrConfigurationFromPageId($item->getRootPageUid());
647 12
        $this->loggingEnabled = $solrConfiguration->getLoggingIndexingQueueOperationsByConfigurationNameWithFallBack(
648 12
            $item->getIndexingConfigurationName()
649 12
        );
650 12
    }
651
652
    /**
653
     * Logs the item and what document was created from it
654
     *
655
     * @param Item $item The item that is being indexed.
656
     * @param array $itemDocuments An array of Solr documents created from the item's data
657
     * @param Apache_Solr_Response $response The Solr response for the particular index document
658
     */
659 11
    protected function log(
660
        Item $item,
661
        array $itemDocuments,
662
        Apache_Solr_Response $response
663
    ) {
664 11
        if (!$this->loggingEnabled) {
665 11
            return;
666
        }
667
668
        $message = 'Index Queue indexing ' . $item->getType() . ':'
669
            . $item->getRecordUid() . ' - ';
670
671
        // preparing data
672
        $documents = [];
673
        foreach ($itemDocuments as $document) {
674
            $documents[] = (array)$document;
675
        }
676
677
        $logData = [
678
            'item' => (array)$item,
679
            'documents' => $documents,
680
            'response' => (array)$response
681
        ];
682
683
        if ($response->getHttpStatus() == 200) {
684
            $severity = SolrLogManager::NOTICE;
685
            $message .= 'Success';
686
        } else {
687
            $severity = SolrLogManager::ERROR;
688
            $message .= 'Failure';
689
690
            $logData['status'] = $response->getHttpStatus();
691
            $logData['status message'] = $response->getHttpStatusMessage();
692
        }
693
694
        $this->logger->log(
695
            $severity,
696
            $message,
697
            $logData
698
        );
699
    }
700
}
701