Completed
Push — master ( 7da5f6...0e708e )
by Timo
44:47 queued 41:16
created

getIndexQueueInitializerClassByConfigurationName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
namespace ApacheSolrForTypo3\Solr\System\Configuration;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2016 Timo Schmidt <[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 3 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
 *  A copy is found in the textfile GPL.txt and important notices to the license
19
 *  from the author is found in LICENSE.txt distributed with these scripts.
20
 *
21
 *
22
 *  This script is distributed in the hope that it will be useful,
23
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 *  GNU General Public License for more details.
26
 *
27
 *  This copyright notice MUST APPEAR in all copies of the script!
28
 ***************************************************************/
29
30
use ApacheSolrForTypo3\Solr\IndexQueue\Indexer;
31
use ApacheSolrForTypo3\Solr\IndexQueue\Initializer\Record;
32
use ApacheSolrForTypo3\Solr\System\ContentObject\ContentObjectService;
33
use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor;
34
use InvalidArgumentException;
35
use TYPO3\CMS\Core\Utility\ArrayUtility;
36
use TYPO3\CMS\Core\Utility\GeneralUtility;
37
38
/**
39
 * TypoScript configuration object, used to read all TypoScript configuration.
40
 *
41
 * The TypoScriptConfiguration was introduced in order to be able to replace the old,
42
 * array based configuration with one configuration object.
43
 *
44
 * To read the configuration, you should use
45
 *
46
 * $configuration->getValueByPath
47
 *
48
 * or
49
 *
50
 * $configuration->isValidPath
51
 *
52
 * to check if an configuration path exists.
53
 *
54
 * To ensure Backwards compatibility the TypoScriptConfiguration object implements the
55
 * ArrayAccess interface (offsetGet,offsetExists,offsetUnset and offsetSet)
56
 *
57
 * This was only introduced to be backwards compatible in logTerm only "getValueByPath", "isValidPath" or
58
 * speaking methods for configuration settings should be used!
59
 *
60
 * @author Marc Bastian Heinrichs <[email protected]>
61
 * @author Timo Schmidt <[email protected]>
62
 */
63
class TypoScriptConfiguration
64
{
65
    /**
66
     * @var \ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor|null
67
     */
68
    protected $configurationAccess = null;
69
70
    /**
71
     * Holds the pageId in which context the configuration was parsed
72
     * (normally $GLOBALS['TSFE']->id)
73
     */
74
    protected $contextPageId = 0;
75
76
    /**
77
     * @var ContentObjectService
78
     */
79
    protected $contentObjectService;
80
81
    /**
82
     * @param array $configuration
83
     * @param int $contextPageId
84
     * @param ContentObjectService $contentObjectService
85
     */
86 327
    public function __construct(array $configuration, $contextPageId = 0, ContentObjectService $contentObjectService = null)
87
    {
88 327
        $this->configurationAccess = new ArrayAccessor($configuration, '.', true);
89 327
        $this->contextPageId = $contextPageId;
90 327
        $this->contentObjectService = $contentObjectService ?? GeneralUtility::makeInstance(ContentObjectService::class);
91 327
    }
92
93
    /**
94
     * Checks if a value is 1, '1', 'true'
95
     * @param mixed $value
96
     * @return bool
97
     */
98 269
    protected function getBool($value)
99
    {
100 269
        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
101
    }
102
103
    /**
104
     * This method can be used to only retrieve array keys where the value is not an array.
105
     *
106
     * This can be very handy in the configuration when only keys should ne taken into account
107
     * where the value is not a subconfiguration (typically an typoscript object path).
108
     *
109
     * @param $inputArray
110
     * @return array
111
     */
112 50
    protected function getOnlyArrayKeysWhereValueIsNotAnArray($inputArray)
113
    {
114 50
        $keysWithNonArrayValue = [];
115
116 50
        foreach ($inputArray as $key => $value) {
117 50
            if (is_array($value)) {
118
                // configuration for a content object, skipping
119 44
                continue;
120
            }
121
122 50
            $keysWithNonArrayValue[] = $key;
123
        }
124
125 50
        return $keysWithNonArrayValue;
126
    }
127
128
    /**
129
     * Gets the value from a given TypoScript path.
130
     *
131
     * In the context of an frontend content element the path plugin.tx_solr is
132
     * merged recursive with overrule with the content element specific typoscript
133
     * settings, like plugin.tx_solr_PiResults_Results, and possible flex form settings
134
     * (depends on the solr plugin).
135
     *
136
     * Example: plugin.tx_solr.search.targetPage
137
     * returns $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['targetPage']
138
     *
139
     * @param string $path TypoScript path
140
     * @return mixed The TypoScript object defined by the given path
141
     * @throws InvalidArgumentException
142
     */
143 306
    public function getValueByPath($path)
144
    {
145 306
        if (!is_string($path)) {
0 ignored issues
show
introduced by
The condition is_string($path) is always true.
Loading history...
146
            throw new InvalidArgumentException('Parameter $path is not a string',
147
                1325623321);
148
        }
149 306
        return $this->configurationAccess->get($path);
0 ignored issues
show
Bug introduced by
The method get() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

149
        return $this->configurationAccess->/** @scrutinizer ignore-call */ get($path);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
150
    }
151
152
    /**
153
     * This method can be used to get  a configuration value by path if it exists or return a
154
     * default value when it does not exist.
155
     *
156
     * @param string $path
157
     * @param mixed $defaultValue
158
     * @return mixed
159
     */
160 303
    public function getValueByPathOrDefaultValue($path, $defaultValue)
161
    {
162 303
        $value = $this->getValueByPath($path);
163 303
        if (is_null($value)) {
164 292
            return $defaultValue;
165
        }
166
167 183
        return $value;
168
    }
169
170
    /**
171
     * Gets the parent TypoScript Object from a given TypoScript path.
172
     *
173
     * In the context of an frontend content element the path plugin.tx_solr is
174
     * merged recursive with overrule with the content element specific typoscript
175
     * settings, like plugin.tx_solr_PiResults_Results, and possible flex form settings
176
     * (depends on the solr plugin).
177
     *
178
     * Example: plugin.tx_solr.index.queue.tt_news.fields.content
179
     * returns $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['index.']['queue.']['tt_news.']['fields.']['content.']
180
     * which is a SOLR_CONTENT cObj.
181
     *
182
     * @param string $path TypoScript path
183
     * @return array The TypoScript object defined by the given path
184
     * @throws InvalidArgumentException
185
     */
186 288
    public function getObjectByPath($path)
187
    {
188 288
        if (substr($path, -1) !== '.') {
189 1
            $path = rtrim($path, '.');
190 1
            $path = substr($path, 0, strrpos($path, '.') + 1);
191
        }
192
193 288
        if (!is_string($path)) {
0 ignored issues
show
introduced by
The condition is_string($path) is always true.
Loading history...
194
            throw new InvalidArgumentException('Parameter $path is not a string', 1325627243);
195
        }
196
197 288
        return $this->configurationAccess->get($path);
198
    }
199
200
    /**
201
     * Gets the parent TypoScript Object from a given TypoScript path and if not present return
202
     * the default value
203
     *
204
     * @see getObjectByPath
205
     * @param string $path
206
     * @param array $defaultValue
207
     * @return array
208
     */
209 287
    public function getObjectByPathOrDefault($path, array $defaultValue)
210
    {
211
        try {
212 287
            $object = $this->getObjectByPath($path);
213
        } catch (\InvalidArgumentException $e) {
214
            return $defaultValue;
215
        }
216
217 287
        if (!is_array($object)) {
0 ignored issues
show
introduced by
The condition is_array($object) is always true.
Loading history...
218 140
            return $defaultValue;
219
        }
220
221 206
        return $object;
222
    }
223
224
    /**
225
     * Checks whether a given TypoScript path is valid.
226
     *
227
     * @param string $path TypoScript path
228
     * @return bool TRUE if the path resolves, FALSE otherwise
229
     */
230
    public function isValidPath($path)
231
    {
232
        $isValidPath = false;
233
234
        $pathValue = $this->getValueByPath($path);
235
        if (!is_null($pathValue)) {
236
            $isValidPath = true;
237
        }
238
239
        return $isValidPath;
240
    }
241
242
    /**
243
     * Merges a configuration with another configuration a
244
     *
245
     * @param array $configurationToMerge
246
     * @param bool $addKeys If set to FALSE, keys that are NOT found in $original will not be set. Thus only existing value can/will be overruled from overrule array.
247
     * @param bool $includeEmptyValues If set, values from $overrule will overrule if they are empty or zero.
248
     * @param bool $enableUnsetFeature If set, special values "__UNSET" can be used in the overrule array in order to unset array keys in the original array.
249
     * @return TypoScriptConfiguration
250
     */
251 22
    public function mergeSolrConfiguration(array $configurationToMerge, $addKeys = true, $includeEmptyValues = true, $enableUnsetFeature = true)
252
    {
253 22
        $data = $this->configurationAccess->getData();
254 22
        ArrayUtility::mergeRecursiveWithOverrule(
255 22
            $data['plugin.']['tx_solr.'],
256 22
            $configurationToMerge,
257 22
            $addKeys,
258 22
            $includeEmptyValues,
259 22
            $enableUnsetFeature
260
        );
261
262 22
        $this->configurationAccess->setData($data);
263
264 22
        return $this;
265
    }
266
267
    /**
268
     * Returns true when ext_solr is enabled
269
     *
270
     * @param boolean $defaultIfEmpty
271
     * @return boolean
272
     */
273
    public function getEnabled($defaultIfEmpty = false)
274
    {
275
        $path = 'plugin.tx_solr.enabled';
276
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
277
        return $this->getBool($result);
278
    }
279
280
    /**
281
     * Returns the configured additionalFields configured for the indexing.
282
     *
283
     * plugin.tx_solr.index.additionalFields.
284
     *
285
     * @param array $defaultIfEmpty
286
     * @return array
287
     */
288 3
    public function getIndexAdditionalFieldsConfiguration($defaultIfEmpty = [])
289
    {
290 3
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.index.additionalFields.', $defaultIfEmpty);
291 3
        return $result;
292
    }
293
294
    /**
295
     * Returns all solr fields names where a mapping is configured in index.additionalFields
296
     *
297
     * Returns all keys from
298
     * plugin.tx_solr.index.additionalFields.
299
     *
300
     * @param array $defaultIfEmpty
301
     * @return array
302
     */
303 2
    public function getIndexMappedAdditionalFieldNames($defaultIfEmpty = [])
304
    {
305 2
        $mappingConfiguration = $this->getIndexAdditionalFieldsConfiguration();
306 2
        $mappedFieldNames = $this->getOnlyArrayKeysWhereValueIsNotAnArray($mappingConfiguration);
307 2
        return count($mappedFieldNames) == 0 ? $defaultIfEmpty : $mappedFieldNames;
308
    }
309
310
    /**
311
     * Returns the fieldProcessingInstructions configuration array
312
     *
313
     * plugin.tx_solr.index.fieldProcessingInstructions.
314
     *
315
     * @param array $defaultIfEmpty
316
     * @return array
317
     */
318 86
    public function getIndexFieldProcessingInstructionsConfiguration(array $defaultIfEmpty = [])
319
    {
320 86
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.index.fieldProcessingInstructions.', $defaultIfEmpty);
321 86
        return $result;
322
    }
323
324
    /**
325
     * Retrieves the indexing configuration array for an indexing queue by configuration name.
326
     *
327
     * plugin.tx_solr.index.queue.<configurationName>.
328
     *
329
     * @param string $configurationName
330
     * @param array $defaultIfEmpty
331
     * @return array
332
     */
333 7
    public function getIndexQueueConfigurationByName($configurationName, array $defaultIfEmpty = [])
334
    {
335 7
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.';
336 7
        $result = $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
337 7
        return $result;
338
    }
339
340
    /**
341
     * Returns an array of all additionalPageIds by index configuration name.
342
     *
343
     * plugin.tx_solr.index.queue.pages.additionalPageIds
344
     *
345
     * @param string $configurationName
346
     * @param array $defaultIfEmpty
347
     * @return array
348
     */
349 42
    public function getIndexQueueAdditionalPageIdsByConfigurationName($configurationName = 'pages', $defaultIfEmpty = [])
350
    {
351 42
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.additionalPageIds';
352 42
        $result = $this->getValueByPathOrDefaultValue($path, '');
353 42
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

353
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
354 38
            return $defaultIfEmpty;
355
        }
356
357 5
        return GeneralUtility::trimExplode(',', $result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

357
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
358
    }
359
360
    /**
361
     * Returns an array of all allowedPageTypes.
362
     *
363
     * plugin.tx_solr.index.queue.pages.allowedPageTypes
364
     *
365
     * @param string $configurationName The configuration name of the queue to use.
366
     * @param array $defaultIfEmpty
367
     * @return array
368
     */
369 31
    public function getIndexQueueAllowedPageTypesArrayByConfigurationName($configurationName = 'pages', $defaultIfEmpty = [])
370
    {
371 31
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.allowedPageTypes';
372 31
        $result = $this->getValueByPathOrDefaultValue($path, '');
373 31
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

373
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
374
            return $defaultIfEmpty;
375
        }
376
377 31
        return GeneralUtility::trimExplode(',', $result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

377
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
378
    }
379
380
    /**
381
     * Returns the configured excludeContentByClass patterns as array.
382
     *
383
     * plugin.tx_solr.index.queue.pages.excludeContentByClass
384
     *
385
     * @param array $defaultIfEmpty
386
     * @return array
387
     */
388 52
    public function getIndexQueuePagesExcludeContentByClassArray($defaultIfEmpty = [])
389
    {
390 52
        $path = 'plugin.tx_solr.index.queue.pages.excludeContentByClass';
391 52
        $result = $this->getValueByPathOrDefaultValue($path, '');
392
393 52
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

393
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
394 7
            return $defaultIfEmpty;
395
        }
396
397 45
        return GeneralUtility::trimExplode(',', $result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

397
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
398
    }
399
400
    /**
401
     * Returns the configured database table for an indexing queue configuration or
402
     * the configurationName itself that is used by convention as tableName when no
403
     * other tablename is present.
404
     *
405
     * plugin.tx_solr.index.queue.<configurationName>.table or configurationName
406
     *
407
     * @param string $configurationName
408
     * @return string
409
     */
410 73
    public function getIndexQueueTableNameOrFallbackToConfigurationName($configurationName = '')
411
    {
412 73
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.table';
413 73
        $result = $this->getValueByPathOrDefaultValue($path, $configurationName);
414 73
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result also could return the type array which is incompatible with the documented return type string.
Loading history...
415
    }
416
417
    /**
418
     * Returns the field configuration for a specific index queue.
419
     *
420
     * plugin.tx_solr.index.queue.<configurationName>.fields.
421
     *
422
     * @param string $configurationName
423
     * @param array $defaultIfEmpty
424
     * @return array
425
     */
426 68
    public function getIndexQueueFieldsConfigurationByConfigurationName($configurationName = '', $defaultIfEmpty = [])
427
    {
428 68
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.fields.';
429 68
        $result = $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
430 68
        return $result;
431
    }
432
433
    /**
434
     * Gets an array of tables configured for indexing by the Index Queue. Since the
435
     * record monitor must watch these tables for manipulation.
436
     *
437
     * @return array Array of table names to be watched by the record monitor.
438
     */
439 36
    public function getIndexQueueMonitoredTables()
440
    {
441 36
        $monitoredTables = [];
442
443 36
        $indexingConfigurations = $this->getEnabledIndexQueueConfigurationNames();
444 36
        foreach ($indexingConfigurations as $indexingConfigurationName) {
445 36
            $monitoredTable = $this->getIndexQueueTableNameOrFallbackToConfigurationName($indexingConfigurationName);
446 36
            $monitoredTables[] = $monitoredTable;
447 36
            if ($monitoredTable === 'pages') {
448
                // when monitoring pages, also monitor creation of translations
449 32
                $monitoredTables[] = 'pages_language_overlay';
450
            }
451
        }
452
453 36
        return array_values(array_unique($monitoredTables));
454
    }
455
456
    /**
457
     * This method can be used to check if a table is configured to be monitored by the record monitor.
458
     *
459
     * @param string $tableName
460
     * @return bool
461
     */
462 35
    public function getIndexQueueIsMonitoredTable($tableName)
463
    {
464 35
        return in_array($tableName, $this->getIndexQueueMonitoredTables(), true);
465
    }
466
467
    /**
468
     * Returns the configured indexer class that should be used for a certain indexingConfiguration.
469
     * By default "ApacheSolrForTypo3\Solr\IndexQueue\Indexer" will be returned.
470
     *
471
     * plugin.tx_solr.index.queue.<configurationName>.indexer
472
     *
473
     * @param string $configurationName
474
     * @param string $defaultIfEmpty
475
     * @return string
476
     */
477 2
    public function getIndexQueueIndexerByConfigurationName($configurationName, $defaultIfEmpty = Indexer::class)
478
    {
479 2
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexer';
480 2
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
481 2
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result also could return the type array which is incompatible with the documented return type string.
Loading history...
482
    }
483
484
    /**
485
     * Returns the configuration of an indexer for a special indexingConfiguration. By default an empty
486
     * array is returned.
487
     *
488
     * plugin.tx_solr.index.queue.<configurationName>.indexer.
489
     *
490
     * @param string $configurationName
491
     * @param array $defaultIfEmpty
492
     * @return array
493
     */
494 2
    public function getIndexQueueIndexerConfigurationByConfigurationName($configurationName, $defaultIfEmpty = [])
495
    {
496 2
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.indexer.';
497 2
        $result = $this->getObjectByPathOrDefault($path, $defaultIfEmpty);
498 2
        return $result;
499
    }
500
501
    /**
502
     * Returns all solr fields names where a mapping configuration is set for a certain index configuration
503
     *
504
     * Returns all keys from
505
     * plugin.tx_solr.index.queue.<configurationName>.fields.
506
     *
507
     * @param string $configurationName
508
     * @param array $defaultIfEmpty
509
     * @return array
510
     */
511 49
    public function getIndexQueueMappedFieldsByConfigurationName($configurationName = '', $defaultIfEmpty = [])
512
    {
513 49
        $mappingConfiguration = $this->getIndexQueueFieldsConfigurationByConfigurationName($configurationName);
514 49
        $mappedFieldNames = $this->getOnlyArrayKeysWhereValueIsNotAnArray($mappingConfiguration);
515 49
        return count($mappedFieldNames) == 0 ? $defaultIfEmpty : $mappedFieldNames;
516
    }
517
518
    /**
519
     * This method is used to check if an index queue configuration is enabled or not
520
     *
521
     * plugin.tx_solr.index.queue.<configurationName> = 1
522
     *
523
     * @param string $configurationName
524
     * @param bool $defaultIfEmpty
525
     * @return bool
526
     */
527 67
    public function getIndexQueueConfigurationIsEnabled($configurationName, $defaultIfEmpty = false)
528
    {
529 67
        $path = 'plugin.tx_solr.index.queue.' . $configurationName;
530 67
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
531 67
        return $this->getBool($result);
532
    }
533
534
    /**
535
     * Retrieves an array of enabled index queue configurations.
536
     *
537
     * plugin.tx_solr.index.queue.<configurationName>
538
     *
539
     * @param array $defaultIfEmpty
540
     * @return array
541
     */
542 75
    public function getEnabledIndexQueueConfigurationNames($defaultIfEmpty = [])
543
    {
544 75
        $tablesToIndex = [];
545 75
        $path = 'plugin.tx_solr.index.queue.';
546 75
        $indexQueueConfiguration = $this->getObjectByPathOrDefault($path, []);
547 75
        foreach ($indexQueueConfiguration as $configurationName => $indexingEnabled) {
548 73
            if (substr($configurationName, -1) != '.' && $indexingEnabled) {
549 73
                $tablesToIndex[] = $configurationName;
550
            }
551
        }
552
553 75
        return count($tablesToIndex) == 0 ? $defaultIfEmpty : $tablesToIndex;
554
    }
555
556
    /**
557
     * Retrieves an array of additional fields that will trigger an recursive update of pages
558
     * when some of the fields on that page are modified.
559
     *
560
     * plugin.tx_solr.index.queue.recursiveUpdateFields
561
     *
562
     * @param string $configurationName
563
     * @param array $defaultIfEmpty
564
     * @return array
565
     */
566 27
    public function getIndexQueueConfigurationRecursiveUpdateFields($configurationName, $defaultIfEmpty = [])
567
    {
568 27
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.recursiveUpdateFields';
569 27
        $recursiveUpdateFieldsString = $this->getValueByPathOrDefaultValue($path, '');
570 27
        if (trim($recursiveUpdateFieldsString) === '') {
0 ignored issues
show
Bug introduced by
It seems like $recursiveUpdateFieldsString can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

570
        if (trim(/** @scrutinizer ignore-type */ $recursiveUpdateFieldsString) === '') {
Loading history...
571 21
            return $defaultIfEmpty;
572
        }
573 7
        $recursiveUpdateFields = GeneralUtility::trimExplode(',', $recursiveUpdateFieldsString);
0 ignored issues
show
Bug introduced by
It seems like $recursiveUpdateFieldsString can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

573
        $recursiveUpdateFields = GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $recursiveUpdateFieldsString);
Loading history...
574
        // For easier check later on we return an array by combining $recursiveUpdateFields
575 7
        return array_combine($recursiveUpdateFields, $recursiveUpdateFields);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_combine($re...$recursiveUpdateFields) could also return false which is incompatible with the documented return type array. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
576
    }
577
578
579
    /**
580
     * Retrieves and initialPagesAdditionalWhereClause where clause when configured or an empty string.
581
     *
582
     * plugin.tx_solr.index.queue.<configurationName>.initialPagesAdditionalWhereClause
583
     *
584
     * @param string $configurationName
585
     * @return string
586
     */
587 13
    public function getInitialPagesAdditionalWhereClause($configurationName)
588
    {
589 13
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.initialPagesAdditionalWhereClause';
590 13
        $initialPagesAdditionalWhereClause = $this->getValueByPathOrDefaultValue($path, '');
591
592 13
        if (trim($initialPagesAdditionalWhereClause) === '') {
0 ignored issues
show
Bug introduced by
It seems like $initialPagesAdditionalWhereClause can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

592
        if (trim(/** @scrutinizer ignore-type */ $initialPagesAdditionalWhereClause) === '') {
Loading history...
593 13
            return '';
594
        }
595
596 1
        return trim($initialPagesAdditionalWhereClause);
597
    }
598
599
    /**
600
     * Retrieves and additional where clause when configured or an empty string.
601
     *
602
     * plugin.tx_solr.index.queue.<configurationName>.additionalWhereClause
603
     *
604
     * @param string $configurationName
605
     * @return string
606
     */
607 70
    public function getIndexQueueAdditionalWhereClauseByConfigurationName($configurationName)
608
    {
609 70
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.additionalWhereClause';
610 70
        $additionalWhere = $this->getValueByPathOrDefaultValue($path, '');
611
612 70
        if (trim($additionalWhere) === '') {
0 ignored issues
show
Bug introduced by
It seems like $additionalWhere can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

612
        if (trim(/** @scrutinizer ignore-type */ $additionalWhere) === '') {
Loading history...
613 23
            return '';
614
        }
615
616 48
        return ' AND ' . $additionalWhere;
0 ignored issues
show
Bug introduced by
Are you sure $additionalWhere of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

616
        return ' AND ' . /** @scrutinizer ignore-type */ $additionalWhere;
Loading history...
617
    }
618
619
    /**
620
     * This method can be used to retrieve all index queue configuration names, where
621
     * a certain table is used. It can be configured with the property "table" or is using the configuration
622
     * key a fallback for the table name.
623
     *
624
     * plugin.tx_solr.index.queue.<configurationName>.
625
     *
626
     * @param string $tableName
627
     * @param array $defaultIfEmpty
628
     * @return array
629
     */
630 1
    public function getIndexQueueConfigurationNamesByTableName($tableName, $defaultIfEmpty = [])
631
    {
632 1
        $path = 'plugin.tx_solr.index.queue.';
633 1
        $configuration = $this->getObjectByPathOrDefault($path, []);
634 1
        $possibleConfigurations = [];
635
636 1
        foreach ($configuration as $configurationName => $indexingEnabled) {
637 1
            $isObject = substr($configurationName, -1) === '.';
638 1
            if ($isObject || !$indexingEnabled) {
639 1
                continue;
640
            }
641
642
            // when the configuration name equals the tableName we have a fallback
643 1
            $hasTableNameAsConfigurationName = $configurationName == $tableName;
644 1
            $hasTableAssignedInQueueConfiguration = isset($configuration[$configurationName . '.']['table']) &&
645 1
                                                    $configuration[$configurationName . '.']['table'] == $tableName;
646 1
            if ($hasTableNameAsConfigurationName || $hasTableAssignedInQueueConfiguration) {
647 1
                $possibleConfigurations[] = $configurationName;
648
            }
649
        }
650
651 1
        return count($possibleConfigurations) > 0 ? $possibleConfigurations : $defaultIfEmpty;
652
    }
653
654
    /**
655
     * This method is used to retrieve the className of a queue initializer for a certain indexing configuration
656
     * of returns the default initializer class, when noting is configured.
657
     *
658
     * plugin.tx_solr.index.queue.<configurationName>.initialization
659
     *
660
     * @param string $configurationName
661
     * @param string $defaultIfEmpty
662
     * @return string
663
     */
664 7
    public function getIndexQueueInitializerClassByConfigurationName($configurationName, $defaultIfEmpty = Record::class)
665
    {
666 7
        $path = 'plugin.tx_solr.index.queue.' . $configurationName . '.initialization';
667 7
        $className = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
668
669 7
        return $className;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $className also could return the type array which is incompatible with the documented return type string.
Loading history...
670
    }
671
672
    /**
673
     * Returns the _LOCAL_LANG configuration from the TypoScript.
674
     *
675
     * plugin.tx_solr._LOCAL_LANG.
676
     *
677
     * @param array $defaultIfEmpty
678
     * @return array
679
     */
680
    public function getLocalLangConfiguration(array $defaultIfEmpty = [])
681
    {
682
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr._LOCAL_LANG.', $defaultIfEmpty);
683
        return $result;
684
    }
685
686
    /**
687
     * When this is enabled the output of the devlog, will be printed as debug output.
688
     *
689
     * @param bool $defaultIfEmpty
690
     * @return bool
691
     */
692
    public function getLoggingDebugOutput($defaultIfEmpty = false)
693
    {
694
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.debugOutput', $defaultIfEmpty);
695
        return $this->getBool($result);
696
    }
697
698
    /**
699
     * Returns if query filters should be written to the log.
700
     *
701
     * plugin.tx_solr.logging.query.filters
702
     *
703
     * @param bool $defaultIfEmpty
704
     * @return bool
705
     */
706
    public function getLoggingQueryFilters($defaultIfEmpty = false)
707
    {
708
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.filters', $defaultIfEmpty);
709
        return $this->getBool($result);
710
    }
711
712
    /**
713
     * Returns if the querystring should be logged or not.
714
     *
715
     * plugin.tx_solr.logging.query.queryString
716
     *
717
     * @param bool $defaultIfEmpty
718
     * @return bool
719
     */
720 50
    public function getLoggingQueryQueryString($defaultIfEmpty = false)
721
    {
722 50
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.queryString', $defaultIfEmpty);
723 50
        return $this->getBool($result);
724
    }
725
726
    /**
727
     * Returns if the searchWords should be logged or not.
728
     *
729
     * plugin.tx_solr.logging.query.searchWords
730
     *
731
     * @param bool $defaultIfEmpty
732
     * @return bool
733
     */
734 124
    public function getLoggingQuerySearchWords($defaultIfEmpty = false)
735
    {
736 124
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.searchWords', $defaultIfEmpty);
737 124
        return $this->getBool($result);
738
    }
739
740
    /**
741
     * Returns if the rawGet requests should be logged or not.
742
     *
743
     * plugin.tx_solr.logging.query.rawGet
744
     *
745
     * @param bool $defaultIfEmpty
746
     * @return bool
747
     */
748
    public function getLoggingQueryRawGet($defaultIfEmpty = false)
749
    {
750
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawGet', $defaultIfEmpty);
751
        return $this->getBool($result);
752
    }
753
754
    /**
755
     * Returns if the rawPost requests should be logged or not.
756
     *
757
     * plugin.tx_solr.logging.query.rawPost
758
     *
759
     * @param bool $defaultIfEmpty
760
     * @return bool
761
     */
762 13
    public function getLoggingQueryRawPost($defaultIfEmpty = false)
763
    {
764 13
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawPost', $defaultIfEmpty);
765 13
        return $this->getBool($result);
766
    }
767
768
    /**
769
     * Returns if the rawDelete requests should be logged or not.
770
     *
771
     * plugin.tx_solr.logging.query.rawDelete
772
     *
773
     * @param bool $defaultIfEmpty
774
     * @return bool
775
     */
776
    public function getLoggingQueryRawDelete($defaultIfEmpty = false)
777
    {
778
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.query.rawDelete', $defaultIfEmpty);
779
        return $this->getBool($result);
780
    }
781
782
    /**
783
     * Returns if exceptions should be logged or not.
784
     *
785
     * plugin.tx_solr.logging.exceptions
786
     *
787
     * @param bool $defaultIfEmpty
788
     * @return bool
789
     */
790 2
    public function getLoggingExceptions($defaultIfEmpty = true)
791
    {
792 2
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.exceptions', $defaultIfEmpty);
793 2
        return $this->getBool($result);
794
    }
795
796
    /**
797
     * Returns if indexing operations should be logged or not.
798
     *
799
     * plugin.tx_solr.logging.indexing
800
     *
801
     * @param bool $defaultIfEmpty
802
     * @return bool
803
     */
804 21
    public function getLoggingIndexing($defaultIfEmpty = false)
805
    {
806 21
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing', $defaultIfEmpty);
807 21
        return $this->getBool($result);
808
    }
809
810
    /**
811
     * Returns if indexing queue operations should be logged or not.
812
     *
813
     * plugin.tx_solr.logging.indexing.queue
814
     *
815
     * @param bool $defaultIfEmpty
816
     * @return bool
817
     */
818 20
    public function getLoggingIndexingQueue($defaultIfEmpty = false)
819
    {
820 20
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.queue', $defaultIfEmpty);
821 20
        return $this->getBool($result);
822
    }
823
824
    /**
825
     * This method can be used to check if the logging during indexing should be done.
826
     * It takes the specific configuration by indexQueueConfiguration into account or is using the
827
     * fallback when the logging is enabled on queue or indexing level.
828
     *
829
     * plugin.tx_solr.logging.indexing.queue.<indexQueueConfiguration>
830
     *
831
     * @param string $indexQueueConfiguration
832
     * @param bool $defaultIfEmpty
833
     * @return bool
834
     */
835 21
    public function getLoggingIndexingQueueOperationsByConfigurationNameWithFallBack($indexQueueConfiguration, $defaultIfEmpty = false)
836
    {
837
        // when logging is globally enabled we do not need to check the specific configuration
838 21
        if ($this->getLoggingIndexing()) {
839 1
            return true;
840
        }
841
842
        // when the logging for indexing is enabled on queue level we also do not need to check the specific configuration
843 20
        if ($this->getLoggingIndexingQueue()) {
844
            return true;
845
        }
846
847 20
        $path = 'plugin.tx_solr.logging.indexing.queue.' . $indexQueueConfiguration;
848 20
        $result = $this->getValueByPathOrDefaultValue($path, $defaultIfEmpty);
849 20
        return $this->getBool($result);
850
    }
851
852
    /**
853
     * Returns if a log message should be written when a page was indexed.
854
     *
855
     * plugin.tx_solr.logging.indexing.pageIndexed
856
     *
857
     * @param bool $defaultIfEmpty
858
     * @return bool
859
     */
860 10
    public function getLoggingIndexingPageIndexed($defaultIfEmpty = false)
861
    {
862 10
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.pageIndexed', $defaultIfEmpty);
863 10
        return $this->getBool($result);
864
    }
865
866
    /**
867
     * Returns if a log message should be written when the TYPO3 search markers are missing in the page.
868
     *
869
     * plugin.tx_solr.logging.indexing.missingTypo3SearchMarkers
870
     *
871
     * @param bool $defaultIfEmpty
872
     * @return bool
873
     */
874 17
    public function getLoggingIndexingMissingTypo3SearchMarkers($defaultIfEmpty = true)
875
    {
876 17
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.missingTypo3SearchMarkers', $defaultIfEmpty);
877 17
        return $this->getBool($result);
878
    }
879
880
    /**
881
     * Returns if the initialization of an indexqueue should be logged.
882
     *
883
     * plugin.tx_solr.logging.indexing.indexQueueInitialization
884
     *
885
     * @param bool $defaultIfEmpty
886
     * @return bool
887
     */
888 12
    public function getLoggingIndexingIndexQueueInitialization($defaultIfEmpty = false)
889
    {
890 12
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.logging.indexing.indexQueueInitialization', $defaultIfEmpty);
891 12
        return $this->getBool($result);
892
    }
893
894
    /**
895
     * Indicates if the debug mode is enabled or not.
896
     *
897
     * plugin.tx_solr.enableDebugMode
898
     *
899
     * @param bool $defaultIfEmpty
900
     * @return bool
901
     */
902 39
    public function getEnabledDebugMode($defaultIfEmpty = false)
903
    {
904 39
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.enableDebugMode', $defaultIfEmpty);
905 39
        return $this->getBool($result);
906
    }
907
908
    /**
909
     * Returns true or false if something is configured below plugin.tx_solr.solr.
910
     *
911
     * plugin.tx_solr.solr.
912
     *
913
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
914
     * @param boolean $defaultIfEmpty
915
     * @return boolean
916
     */
917
    public function getSolrHasConnectionConfiguration($defaultIfEmpty = false)
918
    {
919
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
920
921
        $configuration = $this->getObjectByPathOrDefault('plugin.tx_solr.solr.', []);
922
        return $configuration !== [] ? true : $defaultIfEmpty;
923
    }
924
925
    /**
926
     * Returns the defaultTimeout used for requests to the Solr server
927
     *
928
     * plugin.tx_solr.solr.timeout
929
     *
930
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
931
     * @param int $defaultIfEmpty
932
     * @return int
933
     */
934
    public function getSolrTimeout($defaultIfEmpty = 0, $scope = 'read')
935
    {
936
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
937
938
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.timeout';
939
        $fallbackPath = 'plugin.tx_solr.solr.timeout';
940
        $result = (int)$this->getValueByPathOrDefaultValue($scopePath, -1);
941
        if($result !== -1) {
942
            return $result;
943
        }
944
945
        return (int)$this->getValueByPathOrDefaultValue($fallbackPath, $defaultIfEmpty);
946
    }
947
948
    /**
949
     * Returns the scheme used for requests to the Solr server
950
     *
951
     * plugin.tx_solr.solr.scheme
952
     *
953
     * Applies stdWrap on the configured setting
954
     *
955
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
956
     * @param string $defaultIfEmpty
957
     * @param string $scope read or write, read by default
958
     * @return string
959
     */
960
    public function getSolrScheme($defaultIfEmpty = 'http', $scope = 'read')
961
    {
962
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
963
964
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.scheme';
965
        $fallbackPath = 'plugin.tx_solr.solr.scheme';
966
967
        return $this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
968
    }
969
970
    /**
971
     * Returns the hostname used for requests to the Solr server
972
     *
973
     * plugin.tx_solr.solr.host
974
     *
975
     * Applies stdWrap on the configured setting
976
     *
977
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
978
     * @param string $defaultIfEmpty
979
     * @param string $scope read or write, read by default
980
     * @return string
981
     */
982
    public function getSolrHost($defaultIfEmpty = 'localhost', $scope = 'read')
983
    {
984
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
985
986
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.host';
987
        $fallbackPath = 'plugin.tx_solr.solr.host';
988
989
        return $this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
990
    }
991
992
    /**
993
     * Returns the port used for requests to the Solr server
994
     *
995
     * plugin.tx_solr.solr.port
996
     *
997
     * Applies stdWrap on the configured setting
998
     *
999
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
1000
     * @param int $defaultIfEmpty
1001
     * @param string $scope read or write, read by default
1002
     * @return int
1003
     */
1004
    public function getSolrPort($defaultIfEmpty = 8983, $scope = 'read')
1005
    {
1006
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
1007
1008
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.port';
1009
        $fallbackPath = 'plugin.tx_solr.solr.port';
1010
1011
        return (int)$this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
1012
    }
1013
1014
    /**
1015
     * Returns the path used for requests to the Solr server
1016
     *
1017
     * plugin.tx_solr.solr.path
1018
     *
1019
     * Applies stdWrap on the configured setting
1020
     *
1021
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
1022
     * @param string $defaultIfEmpty
1023
     * @param string $scope read or write, read by default
1024
     * @return string
1025
     */
1026
    public function getSolrPath($defaultIfEmpty = '/solr/core_en/', $scope = 'read')
1027
    {
1028
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
1029
1030
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.path';
1031
        $fallbackPath = 'plugin.tx_solr.solr.path';
1032
1033
        $solrPath =  $this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
1034
1035
        $solrPath = trim($solrPath, '/');
1036
        $solrPath = '/' . $solrPath . '/';
1037
1038
        return $solrPath;
1039
    }
1040
1041
    /**
1042
     * Returns the username used for requests to the Solr server
1043
     *
1044
     * plugin.tx_solr.solr.username
1045
     *
1046
     * Applies stdWrap on the configured setting
1047
     *
1048
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
1049
     * @param string $defaultIfEmpty
1050
     * @param string $scope read or write, read by default
1051
     * @return string
1052
     */
1053
    public function getSolrUsername($defaultIfEmpty = '', $scope = 'read')
1054
    {
1055
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
1056
1057
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.username';
1058
        $fallbackPath = 'plugin.tx_solr.solr.username';
1059
1060
        return $this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
1061
    }
1062
1063
    /**
1064
     * Returns the password used for requests to the Solr server
1065
     *
1066
     * plugin.tx_solr.solr.password
1067
     *
1068
     * Applies stdWrap on the configured setting
1069
     *
1070
     * @deprecated Configuring solr connections with TypoScript is deprecated please use the site handling. Will be dropped with EXT:solr 11
1071
     * @param string $defaultIfEmpty
1072
     * @param string $scope read or write, read by default
1073
     * @return string
1074
     */
1075
    public function getSolrPassword($defaultIfEmpty = '', $scope = 'read')
1076
    {
1077
        trigger_error('solr:deprecation: Configuring solr connections with TypoScript is deprecated please use the site handling', E_USER_DEPRECATED);
1078
1079
        $scopePath = 'plugin.tx_solr.solr.' . $scope . '.password';
1080
        $fallbackPath = 'plugin.tx_solr.solr.password';
1081
1082
        return $this->getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($scopePath, $fallbackPath, $defaultIfEmpty);
1083
    }
1084
1085
    /**
1086
     * @param $path
1087
     * @param $fallbackPath
1088
     * @param $defaultIfBothIsEmpty
1089
     * @return mixed
1090
     */
1091
    public function getValueByPathWithFallbackOrDefaultValueAndApplyStdWrap($path, $fallbackPath, $defaultIfBothIsEmpty)
1092
    {
1093
        $result = (string)$this->getValueByPathOrDefaultValue($path, '');
1094
        if($result !== '') {
1095
            return $this->renderContentElementOfConfigured($path, $result);
1096
        }
1097
1098
        $result = (string)$this->getValueByPathOrDefaultValue($fallbackPath, $defaultIfBothIsEmpty);
1099
        return $this->renderContentElementOfConfigured($fallbackPath, $result);
1100
    }
1101
1102
    /**
1103
     * Retrieves the complete search configuration
1104
     *
1105
     * plugin.tx_solr.search.
1106
     *
1107
     * @param array $defaultIfEmpty
1108
     * @return array
1109
     */
1110 52
    public function getSearchConfiguration(array $defaultIfEmpty = [])
1111
    {
1112 52
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.', $defaultIfEmpty);
1113 52
        return $result;
1114
    }
1115
1116
    /**
1117
     * Indicates if elevation should be used or not
1118
     *
1119
     * plugin.tx_solr.search.elevation
1120
     *
1121
     * @param bool $defaultIfEmpty
1122
     * @return bool
1123
     */
1124 39
    public function getSearchElevation($defaultIfEmpty = false)
1125
    {
1126 39
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation', $defaultIfEmpty);
1127 39
        return $this->getBool($result);
1128
    }
1129
1130
    /**
1131
     * Indicates if elevated results should be marked
1132
     *
1133
     * plugin.tx_solr.search.elevation.markElevatedResults
1134
     *
1135
     * @param bool $defaultIfEmpty
1136
     * @return bool
1137
     */
1138 34
    public function getSearchElevationMarkElevatedResults($defaultIfEmpty = true)
1139
    {
1140 34
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation.markElevatedResults', $defaultIfEmpty);
1141 34
        return $this->getBool($result);
1142
    }
1143
1144
    /**
1145
     * Indicates if elevation should be forced
1146
     *
1147
     *plugin.tx_solr.search.elevation.forceElevation
1148
     *
1149
     * @param bool $defaultIfEmpty
1150
     * @return bool
1151
     */
1152 34
    public function getSearchElevationForceElevation($defaultIfEmpty = true)
1153
    {
1154 34
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.elevation.forceElevation', $defaultIfEmpty);
1155 34
        return $this->getBool($result);
1156
    }
1157
1158
    /**
1159
     * Indicates if collapsing on a certain field should be used to build variants or not.
1160
     *
1161
     * plugin.tx_solr.search.variants
1162
     *
1163
     * @param bool $defaultIfEmpty
1164
     * @return bool
1165
     */
1166 124
    public function getSearchVariants($defaultIfEmpty = false)
1167
    {
1168 124
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants', $defaultIfEmpty);
1169 124
        return $this->getBool($result);
1170
    }
1171
1172
    /**
1173
     * Indicates if collapsing on a certain field should be used or not
1174
     *
1175
     * plugin.tx_solr.search.variants.variantField
1176
     *
1177
     * @param string $defaultIfEmpty
1178
     * @return string
1179
     */
1180 5
    public function getSearchVariantsField($defaultIfEmpty = 'variantId')
1181
    {
1182 5
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.variantField', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...ield', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1183
    }
1184
1185
    /**
1186
     * Indicates if expanding of collapsed items it activated.
1187
     *
1188
     * plugin.tx_solr.search.variants.expand
1189
     *
1190
     * @param bool $defaultIfEmpty
1191
     * @return bool
1192
     */
1193 5
    public function getSearchVariantsExpand($defaultIfEmpty = false)
1194
    {
1195 5
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.expand', $defaultIfEmpty);
1196 5
        return $this->getBool($result);
1197
    }
1198
1199
    /**
1200
     * Retrieves the number of elements that should be expanded.
1201
     *
1202
     * plugin.tx_solr.search.variants.limit
1203
     *
1204
     * @param int $defaultIfEmpty
1205
     * @return int
1206
     */
1207 5
    public function getSearchVariantsLimit($defaultIfEmpty = 10)
1208
    {
1209 5
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.variants.limit', $defaultIfEmpty);
1210 5
        return (int)$result;
1211
    }
1212
1213
    /**
1214
     * Indicates if frequent searches should be show or not.
1215
     *
1216
     * plugin.tx_solr.search.frequentSearches
1217
     *
1218
     * @param bool $defaultIfEmpty
1219
     * @return bool
1220
     */
1221 31
    public function getSearchFrequentSearches($defaultIfEmpty = false)
1222
    {
1223 31
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches', $defaultIfEmpty);
1224 31
        return $this->getBool($result);
1225
    }
1226
1227
    /**
1228
     * Returns the sub configuration of the frequentSearches
1229
     *
1230
     * plugin.tx_solr.search.frequentSearches.
1231
     *
1232
     * @param array $defaultIfEmpty
1233
     * @return array
1234
     */
1235 34
    public function getSearchFrequentSearchesConfiguration($defaultIfEmpty = [])
1236
    {
1237 34
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.frequentSearches.', $defaultIfEmpty);
1238 34
        return $result;
1239
    }
1240
1241
    /**
1242
     * Retrieves the minimum font size that should be used for the frequentSearches.
1243
     *
1244
     * plugin.tx_solr.search.frequentSearches.minSize
1245
     *
1246
     * @param int $defaultIfEmpty
1247
     * @return int
1248
     */
1249 34
    public function getSearchFrequentSearchesMinSize($defaultIfEmpty = 14)
1250
    {
1251 34
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.minSize', $defaultIfEmpty);
1252 34
        return (int)$result;
1253
    }
1254
1255
    /**
1256
     * Retrieves the maximum font size that should be used for the frequentSearches.
1257
     *
1258
     * plugin.tx_solr.search.frequentSearches.minSize
1259
     *
1260
     * @param int $defaultIfEmpty
1261
     * @return int
1262
     */
1263 34
    public function getSearchFrequentSearchesMaxSize($defaultIfEmpty = 32)
1264
    {
1265 34
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.maxSize', $defaultIfEmpty);
1266 34
        return (int)$result;
1267
    }
1268
1269
    /**
1270
     * Indicates if frequent searches should be show or not.
1271
     *
1272
     * plugin.tx_solr.search.frequentSearches.useLowercaseKeywords
1273
     *
1274
     * @param bool $defaultIfEmpty
1275
     * @return bool
1276
     */
1277 33
    public function getSearchFrequentSearchesUseLowercaseKeywords($defaultIfEmpty = false)
1278
    {
1279 33
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.frequentSearches.useLowercaseKeywords', $defaultIfEmpty);
1280 33
        return $this->getBool($result);
1281
    }
1282
1283
    /**
1284
     * Returns the configuration if the search should be initialized with an empty query.
1285
     *
1286
     * plugin.tx_solr.search.initializeWithEmptyQuery
1287
     *
1288
     * @param bool $defaultIfEmpty
1289
     * @return bool
1290
     */
1291 126
    public function getSearchInitializeWithEmptyQuery($defaultIfEmpty = false)
1292
    {
1293 126
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.initializeWithEmptyQuery', $defaultIfEmpty);
1294 126
        return $this->getBool($result);
1295
    }
1296
1297
    /**
1298
     * Returns the configured initial query
1299
     *
1300
     * plugin.tx_solr.search.initializeWithQuery
1301
     *
1302
     * @param string $defaultIfEmpty
1303
     * @return string
1304
     */
1305 126
    public function getSearchInitializeWithQuery($defaultIfEmpty = '')
1306
    {
1307 126
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.initializeWithQuery', $defaultIfEmpty);
1308 126
        return (string)$result;
1309
    }
1310
1311
    /**
1312
     * Returns if the last searches should be displayed or not.
1313
     *
1314
     * plugin.tx_solr.search.lastSearches
1315
     *
1316
     * @param bool $defaultIfEmpty
1317
     * @return bool
1318
     */
1319 31
    public function getSearchLastSearches($defaultIfEmpty = false)
1320
    {
1321 31
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches', $defaultIfEmpty);
1322 31
        return $this->getBool($result);
1323
    }
1324
1325
    /**
1326
     * Returns the lastSearch mode. "user" for user specific
1327
     *
1328
     * plugin.tx_solr.search.lastSearches.mode
1329
     *
1330
     * @param string $defaultIfEmpty
1331
     * @return string
1332
     */
1333 35
    public function getSearchLastSearchesMode($defaultIfEmpty = 'user')
1334
    {
1335 35
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches.mode', $defaultIfEmpty);
1336 35
        return (string)$result;
1337
    }
1338
1339
    /**
1340
     * Returns the lastSearch limit
1341
     *
1342
     * plugin.tx_solr.search.lastSearches.limit
1343
     *
1344
     * @param int $defaultIfEmpty
1345
     * @return int
1346
     */
1347 35
    public function getSearchLastSearchesLimit($defaultIfEmpty = 10)
1348
    {
1349 35
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.lastSearches.limit', $defaultIfEmpty);
1350 35
        return (int)$result;
1351
    }
1352
1353
    /**
1354
     * Indicates if the results of an initial empty query should be shown or not.
1355
     *
1356
     * plugin.tx_solr.search.showResultsOfInitialEmptyQuery
1357
     *
1358
     * @param bool $defaultIfEmpty
1359
     * @return bool
1360
     */
1361 7
    public function getSearchShowResultsOfInitialEmptyQuery($defaultIfEmpty = false)
1362
    {
1363 7
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.showResultsOfInitialEmptyQuery', $defaultIfEmpty);
1364 7
        return $this->getBool($result);
1365
    }
1366
1367
    /**
1368
     * Indicates if the results of an initial search query should be shown.
1369
     *
1370
     * plugin.tx_solr.search.showResultsOfInitialQuery
1371
     *
1372
     * @param bool $defaultIfEmpty
1373
     * @return bool
1374
     */
1375 5
    public function getSearchShowResultsOfInitialQuery($defaultIfEmpty = false)
1376
    {
1377 5
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.showResultsOfInitialQuery', $defaultIfEmpty);
1378 5
        return $this->getBool($result);
1379
    }
1380
1381
    /**
1382
     * Indicates if sorting was enabled or not.
1383
     *
1384
     * plugin.tx_solr.search.sorting
1385
     *
1386
     * @param bool $defaultIfEmpty
1387
     * @return bool
1388
     */
1389 67
    public function getSearchSorting($defaultIfEmpty = false)
1390
    {
1391 67
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.sorting', $defaultIfEmpty);
1392 67
        return $this->getBool($result);
1393
    }
1394
1395
    /**
1396
     * Returns the sorting options configurations.
1397
     *
1398
     * plugin.tx_solr.search.sorting.options.
1399
     *
1400
     * @param array $defaultIfEmpty
1401
     * @return array
1402
     */
1403 35
    public function getSearchSortingOptionsConfiguration($defaultIfEmpty = [])
1404
    {
1405 35
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.sorting.options.', $defaultIfEmpty);
1406 35
        return $result;
1407
    }
1408
1409
    /**
1410
     * Retrieves the sorting default order for a sort option.
1411
     *
1412
     * plugin.tx_solr.search.sorting.options.<sortOptionName>.defaultOrder
1413
     *
1414
     * or
1415
     *
1416
     * plugin.tx_solr.search.sorting.defaultOrder
1417
     *
1418
     *
1419
     * @param string $sortOptionName
1420
     * @param string $defaultIfEmpty
1421
     * @return string
1422
     */
1423 38
    public function getSearchSortingDefaultOrderBySortOptionName($sortOptionName = '', $defaultIfEmpty = 'asc')
1424
    {
1425 38
        $sortOrderSpecificPath = 'plugin.tx_solr.search.sorting.options.' . $sortOptionName . '.defaultOrder';
1426 38
        $specificSortOrder = $this->getValueByPathOrDefaultValue($sortOrderSpecificPath, null);
1427
1428
        // if we have a concrete setting, use it
1429 38
        if ($specificSortOrder !== null) {
1430 2
            return mb_strtolower($specificSortOrder);
0 ignored issues
show
Bug introduced by
$specificSortOrder of type array is incompatible with the type string expected by parameter $str of mb_strtolower(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1430
            return mb_strtolower(/** @scrutinizer ignore-type */ $specificSortOrder);
Loading history...
1431
        }
1432
1433
        // no specific setting, check common setting
1434 36
        $commonPath = 'plugin.tx_solr.search.sorting.defaultOrder';
1435 36
        $commonATagParamOrDefaultValue = $this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty);
1436 36
        return mb_strtolower($commonATagParamOrDefaultValue);
1437
    }
1438
1439
    /**
1440
     * Returns the trusted fields configured for the search that do not need to be escaped.
1441
     *
1442
     * @param array $defaultIfEmpty
1443
     * @return array
1444
     */
1445 42
    public function getSearchTrustedFieldsArray($defaultIfEmpty = ['url'])
1446
    {
1447 42
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.trustedFields', '');
1448
1449 42
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1449
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
1450 3
            return $defaultIfEmpty;
1451
        }
1452
1453 39
        return GeneralUtility::trimExplode(',', $result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1453
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $result);
Loading history...
1454
    }
1455
1456
    /**
1457
     * Indicates if the plugin arguments should be kept in the search form for a second submission.
1458
     *
1459
     * plugin.tx_solr.search.keepExistingParametersForNewSearches
1460
     *
1461
     * @param bool $defaultIfEmpty
1462
     * @return bool
1463
     */
1464 36
    public function getSearchKeepExistingParametersForNewSearches($defaultIfEmpty = false)
1465
    {
1466 36
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.keepExistingParametersForNewSearches', $defaultIfEmpty);
1467 36
        return $this->getBool($result);
1468
    }
1469
1470
    /**
1471
     * Returns if an empty query is allowed on the query level.
1472
     *
1473
     * plugin.tx_solr.search.query.allowEmptyQuery
1474
     *
1475
     * @param string $defaultIfEmpty
1476
     * @return bool
1477
     */
1478 121
    public function getSearchQueryAllowEmptyQuery($defaultIfEmpty = '')
1479
    {
1480 121
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.allowEmptyQuery', $defaultIfEmpty);
1481 121
        return $this->getBool($result);
1482
    }
1483
1484
    /**
1485
     * Returns the filter configuration array
1486
     *
1487
     * plugin.tx_solr.search.query.filter.
1488
     *
1489
     * @param array $defaultIfEmpty
1490
     * @return array
1491
     */
1492 129
    public function getSearchQueryFilterConfiguration(array $defaultIfEmpty = [])
1493
    {
1494 129
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.query.filter.', $defaultIfEmpty);
1495 129
        return $result;
1496
    }
1497
1498
    /**
1499
     * Can be used to overwrite the filterConfiguration.
1500
     *
1501
     * plugin.tx_solr.search.query.filter.
1502
     *
1503
     * @param array $configuration
1504
     */
1505 1
    public function setSearchQueryFilterConfiguration(array $configuration)
1506
    {
1507 1
        $this->configurationAccess->set('plugin.tx_solr.search.query.filter.', $configuration);
1508 1
    }
1509
1510
    /**
1511
     * Removes the pageSections filter setting.
1512
     *
1513
     * @return void
1514
     */
1515 3
    public function removeSearchQueryFilterForPageSections()
1516
    {
1517 3
        $this->configurationAccess->reset('plugin.tx_solr.search.query.filter.__pageSections');
1518 3
    }
1519
1520
    /**
1521
     * Returns the configured queryFields from TypoScript
1522
     *
1523
     * plugin.tx_solr.search.query.queryFields
1524
     *
1525
     * @param string $defaultIfEmpty
1526
     * @return string
1527
     */
1528 124
    public function getSearchQueryQueryFields($defaultIfEmpty = '')
1529
    {
1530 124
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.queryFields', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...elds', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1531
    }
1532
1533
    /**
1534
     * This method is used to check if a phrase search is enabled or not
1535
     *
1536
     * plugin.tx_solr.search.query.phrase = 1
1537
     *
1538
     * @param bool $defaultIfEmpty
1539
     * @return bool
1540
     */
1541 124
    public function getPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1542
    {
1543 124
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.phrase', $defaultIfEmpty);
1544 124
        return $this->getBool($result);
1545
    }
1546
1547
    /**
1548
     * Returns the configured phrase fields from TypoScript
1549
     *
1550
     * plugin.tx_solr.search.query.phrase.fields
1551
     *
1552
     * @param string $defaultIfEmpty
1553
     * @return string
1554
     */
1555 2
    public function getSearchQueryPhraseFields(string $defaultIfEmpty = '')
1556
    {
1557 2
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.phrase.fields', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...elds', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1558
    }
1559
1560
    /**
1561
     * This method is used to check if a bigram phrase search is enabled or not
1562
     *
1563
     * plugin.tx_solr.search.query.bigramPhrase = 1
1564
     *
1565
     * @param bool $defaultIfEmpty
1566
     * @return bool
1567
     */
1568 124
    public function getBigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1569
    {
1570 124
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.bigramPhrase', $defaultIfEmpty);
1571 124
        return $this->getBool($result);
1572
    }
1573
1574
    /**
1575
     * Returns the configured phrase fields from TypoScript
1576
     *
1577
     * plugin.tx_solr.search.query.bigramPhrase.fields
1578
     *
1579
     * @param string $defaultIfEmpty
1580
     * @return string
1581
     */
1582 2
    public function getSearchQueryBigramPhraseFields(string $defaultIfEmpty = '')
1583
    {
1584 2
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.bigramPhrase.fields', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...elds', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1585
    }
1586
1587
    /**
1588
     * This method is used to check if a trigram phrase search is enabled or not
1589
     *
1590
     * plugin.tx_solr.search.query.trigramPhrase = 1
1591
     *
1592
     * @param bool $defaultIfEmpty
1593
     * @return bool
1594
     */
1595 124
    public function getTrigramPhraseSearchIsEnabled(bool $defaultIfEmpty = false)
1596
    {
1597 124
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.trigramPhrase', $defaultIfEmpty);
1598 124
        return $this->getBool($result);
1599
    }
1600
1601
    /**
1602
     * Returns the configured trigram phrase fields from TypoScript
1603
     *
1604
     * plugin.tx_solr.search.query.trigramPhrase.fields
1605
     *
1606
     * @param string $defaultIfEmpty
1607
     * @return string
1608
     */
1609 2
    public function getSearchQueryTrigramPhraseFields(string $defaultIfEmpty = '')
1610
    {
1611 2
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.query.trigramPhrase.fields', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...elds', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1612
    }
1613
1614
    /**
1615
     * Returns the configured returnFields as array.
1616
     *
1617
     * plugin.tx_solr.search.query.returnFields
1618
     *
1619
     * @param array $defaultIfEmpty
1620
     * @return array
1621
     */
1622 126
    public function getSearchQueryReturnFieldsAsArray($defaultIfEmpty = [])
1623
    {
1624 126
        $returnFields = $this->getValueByPath('plugin.tx_solr.search.query.returnFields');
1625 126
        if (is_null($returnFields)) {
1626 86
            return $defaultIfEmpty;
1627
        }
1628
1629 40
        return GeneralUtility::trimExplode(',', $returnFields);
0 ignored issues
show
Bug introduced by
$returnFields of type array is incompatible with the type string expected by parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1629
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $returnFields);
Loading history...
1630
    }
1631
1632
    /**
1633
     * Returns the configured target page for the search.
1634
     * By default the contextPageId will be used
1635
     *
1636
     * plugin.tx_solr.search.targetPage
1637
     *
1638
     * @return int
1639
     */
1640 37
    public function getSearchTargetPage()
1641
    {
1642 37
        $targetPage = (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.targetPage', 0);
1643 37
        if ($targetPage === 0) {
1644
            // when no specific page was configured we use the contextPageId (which is usual $GLOBALS['TSFE']->id)
1645 37
            $targetPage = $this->contextPageId;
1646
        }
1647
1648 37
        return $targetPage;
1649
    }
1650
1651
    /**
1652
     * Retrieves the targetPage configuration.
1653
     *
1654
     * plugin.tx_solr.search.targetPage.
1655
     *
1656
     * @param array $defaultIfEmpty
1657
     * @return array
1658
     */
1659
    public function getSearchTargetPageConfiguration(array $defaultIfEmpty = [])
1660
    {
1661
        $result = $this->getObjectByPathOrDefault('plugin.tx_solr.search.targetPage.', $defaultIfEmpty);
1662
        return $result;
1663
    }
1664
1665
    /**
1666
     * Method to check if the site highlighting is enabled. When the siteHighlighting is enabled the
1667
     * sword_list parameter is added to the results link.
1668
     *
1669
     * plugin.tx_solr.searcb.results.siteHighlighting
1670
     *
1671
     * @param bool $defaultIfEmpty
1672
     * @return bool
1673
     */
1674 27
    public function getSearchResultsSiteHighlighting($defaultIfEmpty = true)
1675
    {
1676 27
        $isSiteHightlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.siteHighlighting', $defaultIfEmpty);
1677 27
        return $this->getBool($isSiteHightlightingEnabled);
1678
    }
1679
1680
1681
    /**
1682
     * Can be used to check if the highlighting is enabled
1683
     *
1684
     * plugin.tx_solr.search.results.resultsHighlighting
1685
     *
1686
     * @param boolean $defaultIfEmpty
1687
     * @return boolean
1688
     */
1689 124
    public function getSearchResultsHighlighting($defaultIfEmpty = false)
1690
    {
1691 124
        $isHighlightingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting', $defaultIfEmpty);
1692 124
        return $this->getBool($isHighlightingEnabled);
1693
    }
1694
1695
    /**
1696
     * Returns the result highlighting fields.
1697
     *
1698
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1699
     *
1700
     * @param string $defaultIfEmpty
1701
     * @return string
1702
     */
1703 42
    public function getSearchResultsHighlightingFields($defaultIfEmpty = '')
1704
    {
1705 42
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.highlightFields', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...elds', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1706
    }
1707
1708
    /**
1709
     * Returns the result highlighting fields as array.
1710
     *
1711
     * plugin.tx_solr.search.results.resultsHighlighting.highlightFields
1712
     *
1713
     * @param array $defaultIfEmpty
1714
     * @return array
1715
     */
1716
    public function getSearchResultsHighlightingFieldsAsArray($defaultIfEmpty = [])
1717
    {
1718
        $highlightingFields = $this->getSearchResultsHighlightingFields('');
1719
1720
        if ($highlightingFields === '') {
1721
            return $defaultIfEmpty;
1722
        }
1723
1724
        return GeneralUtility::trimExplode(',', $highlightingFields, true);
1725
    }
1726
1727
    /**
1728
     * Returns the fragmentSize for highlighted segments.
1729
     *
1730
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSize
1731
     *
1732
     * @param int $defaultIfEmpty
1733
     * @return int
1734
     */
1735 42
    public function getSearchResultsHighlightingFragmentSize($defaultIfEmpty = 200)
1736
    {
1737 42
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.fragmentSize', $defaultIfEmpty);
1738
    }
1739
1740
    /**
1741
     * Returns the fragmentSeparator for highlighted segments.
1742
     *
1743
     * plugin.tx_solr.search.results.resultsHighlighting.fragmentSeparator
1744
     *
1745
     * @param string $defaultIfEmpty
1746
     * @return string
1747
     */
1748 27
    public function getSearchResultsHighlightingFragmentSeparator($defaultIfEmpty = '[...]')
1749
    {
1750 27
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.fragmentSeparator', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...ator', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1751
    }
1752
1753
    /**
1754
     * Returns the number of results that should be shown per page.
1755
     *
1756
     * plugin.tx_solr.search.results.resultsPerPage
1757
     *
1758
     * @param int $defaultIfEmpty
1759
     * @return int
1760
     */
1761 36
    public function getSearchResultsPerPage($defaultIfEmpty = 10)
1762
    {
1763 36
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPage', $defaultIfEmpty);
1764
    }
1765
1766
    /**
1767
     * Returns the available options for the per page switch.
1768
     *
1769
     * plugin.tx_solr.search.results.resultsPerPageSwitchOptions
1770
     *
1771
     * @param array $defaultIfEmpty
1772
     * @return array
1773
     */
1774 36
    public function getSearchResultsPerPageSwitchOptionsAsArray($defaultIfEmpty = [])
1775
    {
1776 36
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsPerPageSwitchOptions', '');
1777
1778 36
        if (trim($result) === '') {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1778
        if (trim(/** @scrutinizer ignore-type */ $result) === '') {
Loading history...
1779
            return $defaultIfEmpty;
1780
        }
1781
1782 36
        return GeneralUtility::intExplode(',', $result, true);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...alUtility::intExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1782
        return GeneralUtility::intExplode(',', /** @scrutinizer ignore-type */ $result, true);
Loading history...
1783
    }
1784
1785
    /**
1786
     * Returns the configured wrap for the resultHighlighting.
1787
     *
1788
     * plugin.tx_solr.search.results.resultsHighlighting.wrap
1789
     *
1790
     * @param string $defaultIfEmpty
1791
     * @return string
1792
     */
1793 42
    public function getSearchResultsHighlightingWrap($defaultIfEmpty = '')
1794
    {
1795 42
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.results.resultsHighlighting.wrap', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...wrap', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1796
    }
1797
1798
    /**
1799
     * Indicates if spellchecking is enabled or not.
1800
     *
1801
     * plugin.tx_solr.search.spellchecking
1802
     *
1803
     * @param bool $defaultIfEmpty
1804
     * @return bool
1805
     */
1806 35
    public function getSearchSpellchecking($defaultIfEmpty = false)
1807
    {
1808 35
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking', $defaultIfEmpty);
1809 35
        return $this->getBool($isFacetingEnabled);
1810
    }
1811
1812
    /**
1813
     * Returns the numberOfSuggestionsToTry that should be used for the spellchecking.
1814
     *
1815
     * plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry
1816
     *
1817
     * @param int $defaultIfEmpty
1818
     * @return int
1819
     */
1820 35
    public function getSearchSpellcheckingNumberOfSuggestionsToTry($defaultIfEmpty = 1)
1821
    {
1822 35
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.numberOfSuggestionsToTry', $defaultIfEmpty);
1823
    }
1824
1825
    /**
1826
     * Indicates if a second search should be fired from the spellchecking suggestion if no results could be found.
1827
     *
1828
     * plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion
1829
     *
1830
     * @param bool $defaultIfEmpty
1831
     * @return bool
1832
     */
1833 38
    public function getSearchSpellcheckingSearchUsingSpellCheckerSuggestion($defaultIfEmpty = false)
1834
    {
1835 38
        $result = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.spellchecking.searchUsingSpellCheckerSuggestion', $defaultIfEmpty);
1836 38
        return $this->getBool($result);
1837
    }
1838
1839
    /**
1840
     * Indicates if faceting is enabled or not.
1841
     *
1842
     * plugin.tx_solr.search.faceting
1843
     *
1844
     * @param bool $defaultIfEmpty
1845
     * @return bool
1846
     */
1847 124
    public function getSearchFaceting($defaultIfEmpty = false)
1848
    {
1849 124
        $isFacetingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting', $defaultIfEmpty);
1850 124
        return $this->getBool($isFacetingEnabled);
1851
    }
1852
1853
    /**
1854
     * Retrieves the showEvenWhenEmpty for a facet by facet name. If nothing specific is configured
1855
     * the global showEmptyFacets with be returned.
1856
     *
1857
     * plugin.tx_solr.search.faceting.facets.<facetName>.showEvenWhenEmpty
1858
     *
1859
     * or
1860
     *
1861
     * plugin.tx_solr.search.faceting.showEmptyFacets
1862
     *
1863
     *
1864
     * @param string $facetName
1865
     * @param bool $defaultIfEmpty
1866
     * @return bool
1867
     */
1868 71
    public function getSearchFacetingShowEmptyFacetsByName($facetName = '', $defaultIfEmpty = false)
1869
    {
1870 71
        $facetSpecificPath = 'plugin.tx_solr.search.faceting.facets.' . $facetName . '.showEvenWhenEmpty';
1871 71
        $specificShowWhenEmpty = $this->getValueByPathOrDefaultValue($facetSpecificPath, null);
1872
1873
        // if we have a concrete setting, use it
1874 71
        if ($specificShowWhenEmpty !== null) {
1875 2
            return $specificShowWhenEmpty;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $specificShowWhenEmpty returns the type array which is incompatible with the documented return type boolean.
Loading history...
1876
        }
1877
1878
        // no specific setting, check common setting
1879 71
        $commonPath = 'plugin.tx_solr.search.faceting.showEmptyFacets';
1880 71
        $commonIfEmptyOrDefaultValue = $this->getValueByPathOrDefaultValue($commonPath, $defaultIfEmpty);
1881 71
        return $commonIfEmptyOrDefaultValue;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $commonIfEmptyOrDefaultValue also could return the type array which is incompatible with the documented return type boolean.
Loading history...
1882
    }
1883
1884
    /**
1885
     * Returns the wrap for the faceting show all link
1886
     *
1887
     * plugin.tx_solr.search.faceting.showAllLink.wrap
1888
     *
1889
     * @param string $defaultIfEmpty
1890
     * @return string
1891
     */
1892
    public function getSearchFacetingShowAllLinkWrap($defaultIfEmpty = '')
1893
    {
1894
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.showAllLink.wrap', $defaultIfEmpty);
1895
    }
1896
1897
    /**
1898
     * Returns the link url parameters that should be added to a facet.
1899
     *
1900
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1901
     *
1902
     * @param string $defaultIfEmpty
1903
     * @return string
1904
     */
1905 30
    public function getSearchFacetingFacetLinkUrlParameters($defaultIfEmpty = '')
1906
    {
1907 30
        $linkUrlParameters = trim($this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters', $defaultIfEmpty));
0 ignored issues
show
Bug introduced by
It seems like $this->getValueByPathOrD...ters', $defaultIfEmpty) can also be of type array; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1907
        $linkUrlParameters = trim(/** @scrutinizer ignore-type */ $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters', $defaultIfEmpty));
Loading history...
1908
1909 30
        return $linkUrlParameters;
1910
    }
1911
1912
    /**
1913
     * Returns if the facetLinkUrlsParameters should be included in the reset link.
1914
     *
1915
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl
1916
     *
1917
     * @param bool $defaultIfEmpty
1918
     * @return bool
1919
     */
1920 4
    public function getSearchFacetingFacetLinkUrlParametersUseForFacetResetLinkUrl($defaultIfEmpty = true)
1921
    {
1922 4
        $useForFacetResetLinkUrl = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLinkUrlParameters.useForFacetResetLinkUrl', $defaultIfEmpty);
1923 4
        return $this->getBool($useForFacetResetLinkUrl);
1924
    }
1925
1926
    /**
1927
     * Returns the link url parameters that should be added to a facet as array.
1928
     *
1929
     * plugin.tx_solr.search.faceting.facetLinkUrlParameters
1930
     *
1931
     * @param array $defaultIfEmpty
1932
     * @return array
1933
     */
1934 30
    public function getSearchFacetingFacetLinkUrlParametersAsArray($defaultIfEmpty = [])
1935
    {
1936 30
        $linkUrlParameters = $this->getSearchFacetingFacetLinkUrlParameters();
1937 30
        if ($linkUrlParameters === '') {
1938
            return $defaultIfEmpty;
1939
        }
1940
1941 30
        return GeneralUtility::explodeUrl2Array($linkUrlParameters);
1942
    }
1943
1944
    /**
1945
     * Return the configured minimumCount value for facets.
1946
     *
1947
     * plugin.tx_solr.search.faceting.minimumCount
1948
     *
1949
     * @param int $defaultIfEmpty
1950
     * @return int
1951
     */
1952 49
    public function getSearchFacetingMinimumCount($defaultIfEmpty = 1)
1953
    {
1954 49
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.minimumCount', $defaultIfEmpty);
1955
    }
1956
1957
    /**
1958
     * Return the configured limit value for facets, used for displaying.
1959
     *
1960
     * plugin.tx_solr.search.faceting.limit
1961
     *
1962
     * @param int $defaultIfEmpty
1963
     * @return int
1964
     */
1965
    public function getSearchFacetingLimit($defaultIfEmpty = 10)
1966
    {
1967
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.limit', $defaultIfEmpty);
1968
    }
1969
1970
    /**
1971
     * Return the configured limit value for facets, used for the response.
1972
     *
1973
     * plugin.tx_solr.search.faceting.facetLimit
1974
     *
1975
     * @param int $defaultIfEmpty
1976
     * @return int
1977
     */
1978 49
    public function getSearchFacetingFacetLimit($defaultIfEmpty = 100)
1979
    {
1980 49
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.facetLimit', $defaultIfEmpty);
1981
    }
1982
1983
    /**
1984
     * Return the configured faceting sortBy value.
1985
     *
1986
     * plugin.tx_solr.search.faceting.sortBy
1987
     *
1988
     * @param string $defaultIfEmpty
1989
     * @return string
1990
     */
1991 49
    public function getSearchFacetingSortBy($defaultIfEmpty = '')
1992
    {
1993 49
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.sortBy', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...rtBy', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
1994
    }
1995
1996
    /**
1997
     * Returns if a facets should be kept on selection. Global faceting setting
1998
     * can also be configured on facet level by using
1999
     * (plugin.tx_solr.search.faceting.facets.<fieldName>.keepAllOptionsOnSelection)
2000
     *
2001
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection
2002
     *
2003
     * @param bool $defaultIfEmpty
2004
     * @return bool
2005
     */
2006 49
    public function getSearchFacetingKeepAllFacetsOnSelection($defaultIfEmpty = false)
2007
    {
2008 49
        $keepAllOptionsOnSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.keepAllFacetsOnSelection', $defaultIfEmpty);
2009 49
        return $this->getBool($keepAllOptionsOnSelection);
2010
    }
2011
2012
    /**
2013
     * Returns if the facet count should be calculated based on the facet selection when
2014
     * plugin.tx_solr.search.faceting.keepAllFacetsOnSelection has been enabled
2015
     *
2016
     * plugin.tx_solr.search.faceting.countAllFacetsForSelection
2017
     *
2018
     * @param bool $defaultIfEmpty
2019
     * @return bool
2020
     */
2021 4
    public function getSearchFacetingCountAllFacetsForSelection($defaultIfEmpty = false)
2022
    {
2023 4
        $countAllFacetsForSelection = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.faceting.countAllFacetsForSelection', $defaultIfEmpty);
2024 4
        return $this->getBool($countAllFacetsForSelection);
2025
    }
2026
2027
    /**
2028
     * Returns the configured faceting configuration.
2029
     *
2030
     * plugin.tx_solr.search.faceting.facets
2031
     *
2032
     * @param array $defaultIfEmpty
2033
     * @return array
2034
     */
2035 76
    public function getSearchFacetingFacets(array $defaultIfEmpty = [])
2036
    {
2037 76
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.', $defaultIfEmpty);
2038
    }
2039
2040
    /**
2041
     * Returns the configuration of a single facet by facet name.
2042
     *
2043
     * plugin.tx_solr.search.faceting.facets.<facetName>
2044
     *
2045
     * @param string $facetName
2046
     * @param array $defaultIfEmpty
2047
     * @return array
2048
     */
2049 49
    public function getSearchFacetingFacetByName($facetName, $defaultIfEmpty = [])
2050
    {
2051 49
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.faceting.facets.' . $facetName . '.', $defaultIfEmpty);
2052
    }
2053
2054
    /**
2055
     * Indicates if statistics is enabled or not.
2056
     *
2057
     * plugin.tx_solr.statistics
2058
     *
2059
     * @param bool $defaultIfEmpty
2060
     * @return bool
2061
     */
2062 40
    public function getStatistics($defaultIfEmpty = false)
2063
    {
2064 40
        $isStatisticsEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics', $defaultIfEmpty);
2065 40
        return $this->getBool($isStatisticsEnabled);
2066
    }
2067
2068
    /**
2069
     * Indicates to which length an ip should be anonymized in the statistics
2070
     *
2071
     * plugin.tx_solr.statistics.anonymizeIP
2072
     *
2073
     * @param int $defaultIfEmpty
2074
     * @return int
2075
     */
2076 29
    public function getStatisticsAnonymizeIP($defaultIfEmpty = 0)
2077
    {
2078 29
        $anonymizeToLength = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.anonymizeIP', $defaultIfEmpty);
2079 29
        return (int)$anonymizeToLength;
2080
    }
2081
2082
    /**
2083
     * Indicates if additional debug Data should be added to the statistics
2084
     *
2085
     * plugin.tx_solr.statistics.addDebugData
2086
     *
2087
     * @param bool $defaultIfEmpty
2088
     * @return bool
2089
     */
2090 35
    public function getStatisticsAddDebugData($defaultIfEmpty = false)
2091
    {
2092 35
        $statisticsAddDebugDataEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.statistics.addDebugData', $defaultIfEmpty);
2093 35
        return $this->getBool($statisticsAddDebugDataEnabled);
2094
    }
2095
2096
    /**
2097
     * Indicates if suggestion is enabled or not.
2098
     *
2099
     * plugin.tx_solr.suggest
2100
     *
2101
     * @param bool $defaultIfEmpty
2102
     * @return bool
2103
     */
2104
    public function getSuggest($defaultIfEmpty = false)
2105
    {
2106
        $isSuggestionEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest', $defaultIfEmpty);
2107
        return $this->getBool($isSuggestionEnabled);
2108
    }
2109
2110
    /**
2111
     * Indicates if https should be used for the suggest form.
2112
     *
2113
     * plugin.tx_solr.suggest.forceHttps
2114
     *
2115
     * @param bool $defaultIfEmpty
2116
     * @return bool
2117
     */
2118
    public function getSuggestForceHttps($defaultIfEmpty = false)
2119
    {
2120
        $isHttpsForced = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.forceHttps', $defaultIfEmpty);
2121
        return $this->getBool($isHttpsForced);
2122
    }
2123
2124
    /**
2125
     * Returns the allowed number of suggestions.
2126
     *
2127
     * plugin.tx_solr.suggest.numberOfSuggestions
2128
     *
2129
     * @param int $defaultIfEmpty
2130
     * @return int
2131
     */
2132 1
    public function getSuggestNumberOfSuggestions($defaultIfEmpty = 10)
2133
    {
2134 1
        $numberOfSuggestions = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfSuggestions', $defaultIfEmpty);
2135 1
        return (int)$numberOfSuggestions;
2136
    }
2137
2138
    /**
2139
     * Indicates if the topResults should be shown or not
2140
     *
2141
     * plugin.tx_solr.suggest.showTopResults
2142
     *
2143
     * @param bool $defaultIfEmpty
2144
     * @return bool
2145
     */
2146 1
    public function getSuggestShowTopResults($defaultIfEmpty = true)
2147
    {
2148 1
        $showTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.showTopResults', $defaultIfEmpty);
2149 1
        return $this->getBool($showTopResults);
2150
    }
2151
2152
    /**
2153
     * Returns the configured number of top results to show
2154
     *
2155
     * plugin.tx_solr.suggest.numberOfTopResults
2156
     *
2157
     * @param int $defaultIfEmpty
2158
     * @return int
2159
     */
2160 1
    public function getSuggestNumberOfTopResults($defaultIfEmpty = 5)
2161
    {
2162 1
        $numberOfTopResults = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.numberOfTopResults', $defaultIfEmpty);
2163 1
        return (int)$numberOfTopResults;
2164
    }
2165
2166
    /**
2167
     * Returns additional fields for the top results
2168
     *
2169
     * plugin.tx_solr.suggest.additionalTopResultsFields
2170
     *
2171
     * @param array $defaultIfEmpty
2172
     * @return array
2173
     */
2174 1
    public function getSuggestAdditionalTopResultsFields($defaultIfEmpty = [])
2175
    {
2176 1
        $additionalTopResultsFields = $this->getValueByPathOrDefaultValue('plugin.tx_solr.suggest.additionalTopResultsFields', '');
2177 1
        if ($additionalTopResultsFields === '') {
2178 1
            return $defaultIfEmpty;
2179
        }
2180
2181
        return GeneralUtility::trimExplode(',', $additionalTopResultsFields, true);
0 ignored issues
show
Bug introduced by
It seems like $additionalTopResultsFields can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2181
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $additionalTopResultsFields, true);
Loading history...
2182
    }
2183
2184
    /**
2185
     * Returns the configured template for a specific template fileKey.
2186
     *
2187
     * plugin.tx_solr.view.templateFiles.<fileKey>
2188
     *
2189
     * @param string $fileKey
2190
     * @param string $defaultIfEmpty
2191
     * @return string
2192
     */
2193 42
    public function getViewTemplateByFileKey($fileKey, $defaultIfEmpty = '')
2194
    {
2195 42
        $templateFileName = $this->getValueByPathOrDefaultValue('plugin.tx_solr.view.templateFiles.' . $fileKey, $defaultIfEmpty);
2196 42
        return (string)$templateFileName;
2197
    }
2198
2199
    /**
2200
     * Returns the configured available template files for the flexform.
2201
     *
2202
     * plugin.tx_solr.view.templateFiles.[fileKey].availableTemplates.
2203
     *
2204
     * @param string $fileKey
2205
     * @return array
2206
     */
2207
    public function getAvailableTemplatesByFileKey($fileKey)
2208
    {
2209
        $path = 'plugin.tx_solr.view.templateFiles.' . $fileKey . '.availableTemplates.';
2210
        return (array)$this->getObjectByPathOrDefault($path, []);
2211
    }
2212
2213
    /**
2214
     * Returns the configuration of the crop view helper.
2215
     *
2216
     * plugin.tx_solr.viewHelpers.crop.
2217
     *
2218
     * @param array $defaultIfEmpty
2219
     * @return array
2220
     */
2221
    public function getViewHelpersCropConfiguration(array $defaultIfEmpty = [])
2222
    {
2223
        $cropViewHelperConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.crop.', $defaultIfEmpty);
2224
        return $cropViewHelperConfiguration;
2225
    }
2226
2227
    /**
2228
     * Returns the configuration of the sorting view helper.
2229
     *
2230
     * plugin.tx_solr.viewHelpers.sortIndicator.
2231
     *
2232
     * @param array $defaultIfEmpty
2233
     * @return array
2234
     */
2235
    public function getViewHelpersSortIndicatorConfiguration(array $defaultIfEmpty = [])
2236
    {
2237
        $sortingViewHelperConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.viewHelpers.sortIndicator.', $defaultIfEmpty);
2238
        return $sortingViewHelperConfiguration;
2239
    }
2240
2241
    /**
2242
     * Controls whether ext-solr will send commits to solr.
2243
     * Beware: If you disable this, you need to ensure
2244
     * that some other mechanism will commit your changes
2245
     * otherwise they will never be searchable.
2246
     * A good way to achieve this is enabling the solr
2247
     * daemons autoCommit feature.
2248
     *
2249
     * plugin.tx_solr.index.enableCommits
2250
     *
2251
     * @param bool $defaultIfEmpty
2252
     * @return bool
2253
     */
2254 13
    public function getEnableCommits($defaultIfEmpty = true)
2255
    {
2256 13
        $enableCommits = $this->getValueByPathOrDefaultValue('plugin.tx_solr.index.enableCommits', $defaultIfEmpty);
2257 13
        return $this->getBool($enableCommits);
2258
    }
2259
2260
    /**
2261
     * Returns the url namespace that is used for the arguments.
2262
     *
2263
     * plugin.tx_solr.view.pluginNamespace
2264
     *
2265
     * @param string $defaultIfEmpty
2266
     * @return string
2267
     */
2268 44
    public function getSearchPluginNamespace($defaultIfEmpty = 'tx_solr')
2269
    {
2270 44
        return $this->getValueByPathOrDefaultValue('plugin.tx_solr.view.pluginNamespace', $defaultIfEmpty);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueBy...pace', $defaultIfEmpty) also could return the type array which is incompatible with the documented return type string.
Loading history...
2271
    }
2272
2273
    /**
2274
     * Returns true if the global url parameter q, that indicates the query should be used.
2275
     *
2276
     * Should be set to false, when multiple instance on the same page should have their querystring.
2277
     *
2278
     * plugin.tx_solr.search.ignoreGlobalQParameter
2279
     *
2280
     * @param bool $defaultIfEmpty
2281
     * @return bool
2282
     */
2283 30
    public function getSearchIgnoreGlobalQParameter($defaultIfEmpty = false)
2284
    {
2285 30
        $enableQParameter = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.ignoreGlobalQParameter', $defaultIfEmpty);
2286 30
        return $this->getBool($enableQParameter);
2287
2288
    }
2289
2290
    /**
2291
     * Returns the argument names, that should be added to the persistent arguments, as array.
2292
     *
2293
     * plugin.tx_solr.search.additionalPersistentArgumentNames
2294
     *
2295
     * @param array $defaultIfEmpty
2296
     * @return array
2297
     */
2298 44
    public function getSearchAdditionalPersistentArgumentNames($defaultIfEmpty = [])
2299
    {
2300 44
        $additionalPersistentArgumentNames = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.additionalPersistentArgumentNames', '');
2301
2302 44
        if ($additionalPersistentArgumentNames === '') {
2303 43
            return $defaultIfEmpty;
2304
        }
2305
2306 1
        return GeneralUtility::trimExplode(',', $additionalPersistentArgumentNames, true);
0 ignored issues
show
Bug introduced by
It seems like $additionalPersistentArgumentNames can also be of type array; however, parameter $string of TYPO3\CMS\Core\Utility\G...lUtility::trimExplode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2306
        return GeneralUtility::trimExplode(',', /** @scrutinizer ignore-type */ $additionalPersistentArgumentNames, true);
Loading history...
2307
2308
    }
2309
2310
    /**
2311
     * Method to check if grouping was enabled with typoscript.
2312
     *
2313
     * plugin.tx_solr.search.grouping
2314
     *
2315
     * @param bool $defaultIfEmpty
2316
     * @return bool
2317
     */
2318 126
    public function getSearchGrouping($defaultIfEmpty = false)
2319
    {
2320 126
        $groupingEnabled = $this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping', $defaultIfEmpty);
2321 126
        return $this->getBool($groupingEnabled);
2322
    }
2323
2324
    /**
2325
     * Returns the configured numberOfGroups.
2326
     *
2327
     * plugin.tx_solr.search.grouping.numberOfGroups
2328
     *
2329
     * @param int $defaultIfEmpty
2330
     * @return int
2331
     */
2332 1
    public function getSearchGroupingNumberOfGroups($defaultIfEmpty = 5)
2333
    {
2334 1
        return (int)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping.numberOfGroups', $defaultIfEmpty);
2335
    }
2336
2337
    /**
2338
     * Returns the sortBy configuration for the grouping.
2339
     *
2340
     * plugin.tx_solr.search.grouping.sortBy
2341
     *
2342
     * @param string $defaultIfEmpty
2343
     * @return string
2344
     */
2345 1
    public function getSearchGroupingSortBy($defaultIfEmpty = '')
2346
    {
2347 1
        return (string)$this->getValueByPathOrDefaultValue('plugin.tx_solr.search.grouping.sortBy', $defaultIfEmpty);
2348
    }
2349
2350
    /**
2351
     * Returns the highestValue of the numberOfResultsPerGroup configuration that is globally configured and
2352
     * for each group.
2353
     *
2354
     * plugin.tx_solr.search.grouping.
2355
     *
2356
     * @param int $defaultIfEmpty
2357
     * @return int
2358
     */
2359 3
    public function getSearchGroupingHighestGroupResultsLimit($defaultIfEmpty = 1)
2360
    {
2361 3
        $groupingConfiguration = $this->getObjectByPathOrDefault('plugin.tx_solr.search.grouping.', []);
2362 3
        $highestLimit = $defaultIfEmpty;
2363 3
        if (!empty($groupingConfiguration['numberOfResultsPerGroup'])) {
2364 2
            $highestLimit = $groupingConfiguration['numberOfResultsPerGroup'];
2365
        }
2366
2367 3
        $configuredGroups = $groupingConfiguration['groups.'];
2368 3
        if (!is_array($configuredGroups)) {
2369 1
            return $highestLimit;
2370
        }
2371
2372 2
        foreach ($configuredGroups as $groupName => $groupConfiguration) {
2373 2
            if (!empty($groupConfiguration['numberOfResultsPerGroup']) && $groupConfiguration['numberOfResultsPerGroup'] > $highestLimit) {
2374 1
                $highestLimit = $groupConfiguration['numberOfResultsPerGroup'];
2375
            }
2376
        }
2377
2378 2
        return $highestLimit;
2379
    }
2380
2381
    /**
2382
     * Returns the valid numberOfResultsPerGroup value for a group.
2383
     *
2384
     * Returns:
2385
     *
2386
     * plugin.tx_solr.search.grouping.groups.<groupName>.numberOfResultsPerGroup if it is set otherwise
2387
     * plugin.tx_solr.search.grouping.numberOfResultsPerGroup
2388
     *
2389
     * @param string $groupName
2390
     * @param int $defaultIfEmpty
2391
     * @return int
2392
     */
2393
    public function getSearchGroupingResultLimit($groupName, $defaultIfEmpty = 1)
2394
    {
2395
        $specificPath = 'plugin.tx_solr.search.grouping.groups.' . $groupName . 'numberOfResultsPerGroup';
2396
        $specificResultsPerGroup = $this->getValueByPathOrDefaultValue($specificPath, null);
2397
2398
        if ($specificResultsPerGroup !== null) {
2399
            return (int) $specificResultsPerGroup;
2400
        }
2401
2402
        $commonPath = 'plugin.tx_solr.search.grouping.numberOfResultsPerGroup';
2403
        $commonValue = $this->getValueByPathOrDefaultValue($commonPath, null);
2404
        if ($commonValue !== null) {
2405
            return (int) $commonValue;
2406
        }
2407
2408
        return $defaultIfEmpty;
2409
    }
2410
2411
    /**
2412
     * Returns everything that is configured for the groups (plugin.tx_solr.search.grouping.groups.)
2413
     *
2414
     * plugin.tx_solr.search.grouping.groups.
2415
     *
2416
     * @param array $defaultIfEmpty
2417
     * @return array
2418
     */
2419 1
    public function getSearchGroupingGroupsConfiguration($defaultIfEmpty = [])
2420
    {
2421 1
        return $this->getObjectByPathOrDefault('plugin.tx_solr.search.grouping.groups.', $defaultIfEmpty);
2422
    }
2423
2424
    /*
2425
     * Applies the stdWrap if it is configured for the path, otherwise the unprocessed value will be returned.
2426
     *
2427
     * @param string $valuePath
2428
     * @param mixed $value
2429
     * @return mixed
2430
     */
2431
    protected function renderContentElementOfConfigured($valuePath, $value)
2432
    {
2433
        $configurationPath = $valuePath . '.';
2434
        $configuration = $this->getObjectByPath($configurationPath);
2435
2436
        if ($configuration == null) {
2437
            return $value;
2438
        }
2439
2440
        return $this->contentObjectService->renderSingleContentObject($value, $configuration);
2441
    }
2442
}
2443