|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Site; |
|
4
|
|
|
|
|
5
|
|
|
/*************************************************************** |
|
6
|
|
|
* Copyright notice |
|
7
|
|
|
* |
|
8
|
|
|
* (c) 2019 Frans Saris <[email protected]> & Timo Hund <[email protected]> |
|
9
|
|
|
* All rights reserved |
|
10
|
|
|
* |
|
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
12
|
|
|
* free software; you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU General Public License as published by |
|
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
15
|
|
|
* (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* The GNU General Public License can be found at |
|
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
19
|
|
|
* |
|
20
|
|
|
* This script is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
26
|
|
|
***************************************************************/ |
|
27
|
|
|
|
|
28
|
|
|
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException; |
|
29
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
|
30
|
|
|
use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository; |
|
31
|
|
|
use ApacheSolrForTypo3\Solr\Util; |
|
32
|
|
|
use TYPO3\CMS\Core\Context\LanguageAspectFactory; |
|
33
|
|
|
use TYPO3\CMS\Core\Registry; |
|
34
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Class LegacySite |
|
38
|
|
|
* |
|
39
|
|
|
* @deprecated This class is used for the old solr setup based on TypoScript and sys_registry records. |
|
40
|
|
|
* @package ApacheSolrForTypo3\Solr\Domain\Site |
|
41
|
|
|
*/ |
|
42
|
|
|
class LegacySite extends Site |
|
43
|
|
|
{ |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var array |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $typoScriptConfig = null; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Constructor. |
|
52
|
|
|
* |
|
53
|
|
|
* @param TypoScriptConfiguration $configuration |
|
54
|
|
|
* @param array $page Site root page ID (uid). The page must be marked as site root ("Use as Root Page" flag). |
|
55
|
|
|
* @param string $domain The domain record used by this Site |
|
56
|
|
|
* @param string $siteHash The site hash used by this site |
|
57
|
|
|
* @param PagesRepository $pagesRepository |
|
58
|
|
|
* @param int $defaultLanguageId |
|
59
|
|
|
* @param int[] $availableLanguageIds |
|
60
|
|
|
*/ |
|
61
|
|
|
public function __construct(TypoScriptConfiguration $configuration, array $page, $domain, $siteHash, PagesRepository $pagesRepository = null, $defaultLanguageId = 0, $availableLanguageIds = []) |
|
62
|
|
|
{ |
|
63
|
|
|
trigger_error('solr:deprecation: Using legacy sites is deprecated since EXT:solr 10 and will be removed in v11, use sitehandling instead', E_USER_DEPRECATED); |
|
64
|
|
|
|
|
65
|
|
|
$this->configuration = $configuration; |
|
66
|
|
|
$this->rootPage = $page; |
|
67
|
|
|
$this->domain = $domain; |
|
68
|
|
|
$this->siteHash = $siteHash; |
|
69
|
|
|
$this->pagesRepository = $pagesRepository ?? GeneralUtility::makeInstance(PagesRepository::class); |
|
70
|
|
|
$this->defaultLanguageId = $defaultLanguageId; |
|
71
|
|
|
$this->availableLanguageIds = $availableLanguageIds; |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param int $languageUid |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getFallbackOrder(int $languageUid): array |
|
80
|
|
|
{ |
|
81
|
|
|
if ($this->typoScriptConfig === null) { |
|
82
|
|
|
try { |
|
83
|
|
|
Util::initializeTsfe($this->getRootPageId(), $languageUid); |
|
84
|
|
|
$this->typoScriptConfig = $GLOBALS['TSFE']->config['config'] ?? []; |
|
85
|
|
|
|
|
86
|
|
|
} catch (\TYPO3\CMS\Core\Error\Http\ServiceUnavailableException $e) { |
|
87
|
|
|
// when there is an error during initialization we return the default sysLanguageMode |
|
88
|
|
|
$this->typoScriptConfig = []; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
$languageAspect = LanguageAspectFactory::createFromTypoScript($this->typoScriptConfig); |
|
92
|
|
|
return $languageAspect->getFallbackChain(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param int $language |
|
98
|
|
|
* @return array |
|
99
|
|
|
* @throws NoSolrConnectionFoundException |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getSolrConnectionConfiguration(int $language = 0): array { |
|
102
|
|
|
$connectionKey = $this->getRootPageId() . '|' . $language; |
|
103
|
|
|
$solrConfiguration = $this->getSolrConnectionConfigFromRegistry($connectionKey); |
|
104
|
|
|
|
|
105
|
|
|
if (!is_array($solrConfiguration)) { |
|
|
|
|
|
|
106
|
|
|
/* @var $noSolrConnectionException NoSolrConnectionFoundException */ |
|
107
|
|
|
$noSolrConnectionException = GeneralUtility::makeInstance( |
|
108
|
|
|
NoSolrConnectionFoundException::class, |
|
109
|
|
|
/** @scrutinizer ignore-type */ 'Could not find a Solr connection for root page [' . $this->getRootPageId() . '] and language [' . $language . '].', |
|
110
|
|
|
/** @scrutinizer ignore-type */ 1275396474 |
|
111
|
|
|
); |
|
112
|
|
|
$noSolrConnectionException->setRootPageId($this->getRootPageId()); |
|
113
|
|
|
$noSolrConnectionException->setLanguageId($language); |
|
114
|
|
|
|
|
115
|
|
|
throw $noSolrConnectionException; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
return $solrConfiguration; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Gets all connection configurations found. |
|
123
|
|
|
* |
|
124
|
|
|
* @return array An array of connection configurations. |
|
125
|
|
|
*/ |
|
126
|
|
|
protected function getSolrConnectionConfigFromRegistry(string $connectionKey) |
|
127
|
|
|
{ |
|
128
|
|
|
/** @var $registry Registry */ |
|
129
|
|
|
$registry = GeneralUtility::makeInstance(Registry::class); |
|
130
|
|
|
$solrConfigurations = $registry->get('tx_solr', 'servers', []); |
|
131
|
|
|
|
|
132
|
|
|
return $solrConfigurations[$connectionKey] ?? null; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
|