1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\DataProvider; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TYPO3 CMS project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
10
|
|
|
* of the License, or any later version. |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please read the |
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* The TYPO3 project - inspiring people to share! |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\ExternalDataProviderInterface; |
20
|
|
|
use ApacheSolrForTypo3\Solr\Util; |
21
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* This class is in use to retrieve the configured data provider. |
26
|
|
|
* |
27
|
|
|
* @author Lars Tode <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class ExternalDataProviderUtility implements SingletonInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var ExternalDataProviderUtility |
33
|
|
|
*/ |
34
|
|
|
protected static $instance = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Only create one instance of this class |
38
|
|
|
* |
39
|
|
|
* @return ExternalDataProviderUtility |
40
|
|
|
*/ |
41
|
|
|
public static function getInstance(): ExternalDataProviderUtility |
42
|
|
|
{ |
43
|
|
|
if (self::$instance === null) { |
44
|
|
|
self::$instance = new self(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return self::$instance; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns the data provider configured for a given table within the indexer or null |
52
|
|
|
* |
53
|
|
|
* @param string $tableName |
54
|
|
|
* @param int $rootPageId |
55
|
|
|
* @return ExternalDataProviderInterface|null |
56
|
|
|
*/ |
57
|
|
|
public function getProviderForIndexQueueByTableName( |
58
|
|
|
string $tableName, |
59
|
|
|
int $rootPageId |
60
|
|
|
): ?ExternalDataProviderInterface { |
61
|
|
|
$configuration = Util::getSolrConfigurationFromPageId($rootPageId); |
62
|
|
|
$className = null; |
63
|
|
|
try { |
64
|
|
|
$result = $configuration->getObjectByPath('plugin.tx_solr.index.externalDataProvider.' . $tableName); |
65
|
|
|
if (isset($result[$tableName])) { |
66
|
|
|
$className = $result[$tableName]; |
67
|
|
|
} |
68
|
|
|
} catch (\Exception $exception) { |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if (empty($className)) { |
72
|
|
|
return null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if (!class_exists($className)) { |
76
|
|
|
return null; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return GeneralUtility::makeInstance($className); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|