Completed
Push — master ( c7f02f...d53d83 )
by Timo
14:49
created

Indexer::getSystemLanguages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.125

Importance

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