|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Site; |
|
4
|
|
|
|
|
5
|
|
|
/*************************************************************** |
|
6
|
|
|
* Copyright notice |
|
7
|
|
|
* |
|
8
|
|
|
* (c) 2017 - Thomas Hohn <[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\Domain\Index\Queue\RecordMonitor\Helper\RootPageResolver; |
|
29
|
|
|
use ApacheSolrForTypo3\Solr\System\Cache\TwoLevelCache; |
|
30
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\ExtensionConfiguration; |
|
31
|
|
|
use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository; |
|
32
|
|
|
use ApacheSolrForTypo3\Solr\System\Records\SystemLanguage\SystemLanguageRepository; |
|
33
|
|
|
use ApacheSolrForTypo3\Solr\System\Service\SiteService; |
|
34
|
|
|
use ApacheSolrForTypo3\Solr\System\Util\SiteUtility; |
|
35
|
|
|
use ApacheSolrForTypo3\Solr\Util; |
|
36
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
37
|
|
|
use TYPO3\CMS\Core\Registry; |
|
38
|
|
|
use TYPO3\CMS\Core\Site\SiteFinder; |
|
39
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
40
|
|
|
use TYPO3\CMS\Core\Utility\RootlineUtility; |
|
41
|
|
|
use TYPO3\CMS\Frontend\Compatibility\LegacyDomainResolver; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* SiteRepository |
|
45
|
|
|
* |
|
46
|
|
|
* Responsible to retrieve instances of Site objects |
|
47
|
|
|
* |
|
48
|
|
|
* @author Thomas Hohn <[email protected]> |
|
49
|
|
|
*/ |
|
50
|
|
|
class SiteRepository |
|
51
|
|
|
{ |
|
52
|
|
|
/** |
|
53
|
|
|
* Rootpage resolver |
|
54
|
|
|
* |
|
55
|
|
|
* @var RootPageResolver |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $rootPageResolver; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var TwoLevelCache |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $runtimeCache; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var Registry |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $registry; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var SiteFinder |
|
71
|
|
|
*/ |
|
72
|
169 |
|
protected $siteFinder; |
|
73
|
|
|
|
|
74
|
169 |
|
/** |
|
75
|
169 |
|
* @var ExtensionConfiguration |
|
76
|
169 |
|
*/ |
|
77
|
169 |
|
protected $extensionConfiguration; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* SiteRepository constructor. |
|
81
|
|
|
* |
|
82
|
|
|
* @param RootPageResolver|null $rootPageResolver |
|
83
|
|
|
* @param TwoLevelCache|null $twoLevelCache |
|
84
|
|
|
* @param Registry|null $registry |
|
85
|
|
|
* @param SiteFinder|null $siteFinder |
|
86
|
107 |
|
* @param ExtensionConfiguration| null |
|
|
|
|
|
|
87
|
|
|
*/ |
|
88
|
107 |
|
public function __construct(RootPageResolver $rootPageResolver = null, TwoLevelCache $twoLevelCache = null, Registry $registry = null, SiteFinder $siteFinder = null, ExtensionConfiguration $extensionConfiguration = null) |
|
89
|
107 |
|
{ |
|
90
|
|
|
$this->rootPageResolver = $rootPageResolver ?? GeneralUtility::makeInstance(RootPageResolver::class); |
|
91
|
|
|
$this->runtimeCache = $twoLevelCache ?? GeneralUtility::makeInstance(TwoLevelCache::class, /** @scrutinizer ignore-type */'cache_runtime'); |
|
92
|
|
|
$this->registry = $registry ?? GeneralUtility::makeInstance(Registry::class); |
|
93
|
|
|
$this->siteFinder = $siteFinder ?? GeneralUtility::makeInstance(SiteFinder::class); |
|
94
|
|
|
$this->extensionConfiguration = $extensionConfiguration ?? GeneralUtility::makeInstance(ExtensionConfiguration::class); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
123 |
|
* Gets the Site for a specific page Id. |
|
99
|
|
|
* |
|
100
|
123 |
|
* @param int $pageId The page Id to get a Site object for. |
|
101
|
|
|
* @param string $mountPointIdentifier |
|
102
|
123 |
|
* @return SiteInterface Site for the given page Id. |
|
103
|
123 |
|
*/ |
|
104
|
92 |
|
public function getSiteByPageId($pageId, $mountPointIdentifier = '') |
|
105
|
|
|
{ |
|
106
|
|
|
$rootPageId = $this->rootPageResolver->getRootPageId($pageId, false, $mountPointIdentifier); |
|
107
|
123 |
|
return $this->getSiteByRootPageId($rootPageId); |
|
108
|
118 |
|
} |
|
109
|
|
|
|
|
110
|
118 |
|
/** |
|
111
|
|
|
* Gets the Site for a specific root page Id. |
|
112
|
|
|
* |
|
113
|
|
|
* @param int $rootPageId Root page Id to get a Site object for. |
|
114
|
|
|
* @return SiteInterface Site for the given page Id. |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getSiteByRootPageId($rootPageId) |
|
117
|
|
|
{ |
|
118
|
|
|
$cacheId = 'SiteRepository' . '_' . 'getSiteByPageId' . '_' . $rootPageId; |
|
119
|
22 |
|
|
|
120
|
|
|
$methodResult = $this->runtimeCache->get($cacheId); |
|
121
|
22 |
|
if (!empty($methodResult)) { |
|
122
|
22 |
|
return $methodResult; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
$methodResult = $this->buildSite($rootPageId); |
|
126
|
|
|
$this->runtimeCache->set($cacheId, $methodResult); |
|
127
|
|
|
|
|
128
|
|
|
return $methodResult; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
67 |
|
/** |
|
132
|
|
|
* Returns the first available Site. |
|
133
|
67 |
|
* |
|
134
|
67 |
|
* @param bool $stopOnInvalidSite |
|
135
|
|
|
* @throws \Exception |
|
136
|
67 |
|
* @return Site |
|
137
|
67 |
|
*/ |
|
138
|
16 |
|
public function getFirstAvailableSite($stopOnInvalidSite = false) |
|
139
|
|
|
{ |
|
140
|
|
|
$sites = $this->getAvailableSites($stopOnInvalidSite); |
|
141
|
67 |
|
return array_shift($sites); |
|
142
|
67 |
|
} |
|
143
|
67 |
|
|
|
144
|
|
|
/** |
|
145
|
9 |
|
* Gets all available TYPO3 sites with Solr configured. |
|
146
|
|
|
* |
|
147
|
|
|
* @param bool $stopOnInvalidSite |
|
148
|
|
|
* @throws \Exception |
|
149
|
67 |
|
* @return Site[] An array of availablesites |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getAvailableSites($stopOnInvalidSite = false) |
|
152
|
67 |
|
{ |
|
153
|
|
|
$cacheId = 'SiteRepository' . '_' . 'getAvailableSites'; |
|
154
|
|
|
|
|
155
|
|
|
$methodResult = $this->runtimeCache->get($cacheId); |
|
156
|
|
|
if (!empty($methodResult)) { |
|
157
|
67 |
|
return $methodResult; |
|
158
|
67 |
|
} |
|
159
|
|
|
|
|
160
|
67 |
|
$legacySites = $this->extensionConfiguration->getIsAllowLegacySiteModeEnabled() ? $this->getAvailableLegacySites($stopOnInvalidSite) : []; |
|
|
|
|
|
|
161
|
|
|
$typo3ManagedSolrSites = $this->getAvailableTYPO3ManagedSites($stopOnInvalidSite); |
|
162
|
|
|
|
|
163
|
|
|
$methodResult = array_merge($legacySites, $typo3ManagedSolrSites); |
|
164
|
|
|
$this->runtimeCache->set($cacheId, $methodResult); |
|
165
|
|
|
|
|
166
|
|
|
return $methodResult; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
1 |
|
/** |
|
170
|
|
|
* @deprecated deprecated since EXT:solr 10 will be removed with EXT:solr 11 please use the site handling now |
|
171
|
1 |
|
* @param bool $stopOnInvalidSite |
|
172
|
1 |
|
* @return array |
|
173
|
|
|
*/ |
|
174
|
1 |
|
protected function getAvailableLegacySites(bool $stopOnInvalidSite): array |
|
175
|
1 |
|
{ |
|
176
|
|
|
$serversFromRegistry = $this->getSolrServersFromRegistry(); |
|
|
|
|
|
|
177
|
1 |
|
if(empty($serversFromRegistry)) { |
|
178
|
1 |
|
return []; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
trigger_error('solr:deprecation: Method getAvailableLegacySites is deprecated since EXT:solr 10 and will be removed in v11, please use the site handling to configure EXT:solr', E_USER_DEPRECATED); |
|
182
|
1 |
|
$legacySites = []; |
|
183
|
|
|
foreach ($serversFromRegistry as $server) { |
|
184
|
|
|
if (isset($legacySites[$server['rootPageUid']])) { |
|
185
|
|
|
//get each site only once |
|
186
|
|
|
continue; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
try { |
|
190
|
|
|
$legacySites[$server['rootPageUid']] = $this->buildSite($server['rootPageUid']); |
|
191
|
|
|
} catch (\InvalidArgumentException $e) { |
|
192
|
149 |
|
if ($stopOnInvalidSite) { |
|
193
|
|
|
throw $e; |
|
194
|
149 |
|
} |
|
195
|
|
|
} |
|
196
|
149 |
|
} |
|
197
|
144 |
|
return $legacySites; |
|
198
|
144 |
|
} |
|
199
|
144 |
|
|
|
200
|
|
|
|
|
201
|
144 |
|
/** |
|
202
|
144 |
|
* @param bool $stopOnInvalidSite |
|
203
|
144 |
|
* @return array |
|
204
|
144 |
|
* @throws \Exception |
|
205
|
144 |
|
*/ |
|
206
|
144 |
|
protected function getAvailableTYPO3ManagedSites(bool $stopOnInvalidSite): array |
|
207
|
|
|
{ |
|
208
|
|
|
$typo3ManagedSolrSites = []; |
|
209
|
|
|
$typo3Sites = $this->siteFinder->getAllSites(); |
|
210
|
|
|
foreach ($typo3Sites as $typo3Site) { |
|
211
|
|
|
try { |
|
212
|
|
|
$rootPageId = $typo3Site->getRootPageId(); |
|
213
|
|
|
if (isset($typo3ManagedSolrSites[$rootPageId])) { |
|
214
|
|
|
//get each site only once |
|
215
|
67 |
|
continue; |
|
216
|
|
|
} |
|
217
|
67 |
|
|
|
218
|
67 |
|
$typo3ManagedSolrSites[$rootPageId] = $this->buildSite($rootPageId); |
|
219
|
|
|
|
|
220
|
|
|
} catch (\Exception $e) { |
|
221
|
|
|
if ($stopOnInvalidSite) { |
|
222
|
|
|
throw $e; |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
144 |
|
} |
|
226
|
|
|
return $typo3ManagedSolrSites; |
|
227
|
|
|
} |
|
228
|
144 |
|
|
|
229
|
144 |
|
/** |
|
230
|
144 |
|
* Gets the system languages (IDs) for which Solr connections have been |
|
231
|
143 |
|
* configured. |
|
232
|
143 |
|
* |
|
233
|
143 |
|
* @param Site $site |
|
234
|
143 |
|
* @return array |
|
235
|
|
|
* @throws \ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException |
|
236
|
|
|
* @deprecated use $site->getConnectionConfig |
|
237
|
1 |
|
*/ |
|
238
|
|
|
public function getAllLanguages(Site $site) |
|
239
|
|
|
{ |
|
240
|
|
|
trigger_error('solr:deprecation: Method getAllLanguages is deprecated since EXT:solr 10 and will be removed in v11, use $site->getConnectionConfig instead', E_USER_DEPRECATED); |
|
241
|
|
|
|
|
242
|
|
|
$siteLanguages = []; |
|
243
|
|
|
foreach ($site->getAllSolrConnectionConfigurations() as $solrConnectionConfiguration) { |
|
244
|
144 |
|
$siteLanguages[] = $solrConnectionConfiguration['language']; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
144 |
|
return $siteLanguages; |
|
248
|
144 |
|
} |
|
249
|
144 |
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Creates an instance of the Site object. |
|
252
|
|
|
* |
|
253
|
|
|
* @param integer $rootPageId |
|
254
|
|
|
* @throws \InvalidArgumentException |
|
255
|
|
|
* @return SiteInterface |
|
256
|
|
|
*/ |
|
257
|
149 |
|
protected function buildSite($rootPageId) |
|
258
|
|
|
{ |
|
259
|
149 |
|
if (empty($rootPageId)) { |
|
260
|
4 |
|
throw new \InvalidArgumentException('Root page id can not be empty'); |
|
261
|
4 |
|
} |
|
262
|
4 |
|
$rootPageRecord = (array)BackendUtility::getRecord('pages', $rootPageId); |
|
263
|
|
|
|
|
264
|
|
|
$this->validateRootPageRecord($rootPageId, $rootPageRecord); |
|
265
|
|
|
|
|
266
|
145 |
|
//@todo The handling of the legacy site can be removed in EXT:solr 11 |
|
267
|
1 |
|
if (!SiteUtility::getIsSiteManagedSite($rootPageId) && $this->extensionConfiguration->getIsAllowLegacySiteModeEnabled()) { |
|
268
|
1 |
|
return $this->buildLegacySite($rootPageRecord); |
|
|
|
|
|
|
269
|
1 |
|
} |
|
270
|
|
|
|
|
271
|
|
|
return $this->buildTypo3ManagedSite($rootPageRecord); |
|
272
|
144 |
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* Retrieves the default language by the rootPageId of a site. |
|
276
|
|
|
* |
|
277
|
|
|
* @param int $rootPageId |
|
278
|
|
|
* @return int|mixed |
|
279
|
|
|
* @deprecated Use Site directly |
|
280
|
|
|
*/ |
|
281
|
|
|
protected function getDefaultLanguage($rootPageId) |
|
282
|
|
|
{ |
|
283
|
|
|
trigger_error('solr:deprecation: Method getDefaultLanguage is deprecated since EXT:solr 10 and will be removed in v11, use the site directly instead', E_USER_DEPRECATED); |
|
284
|
|
|
|
|
285
|
|
|
$siteDefaultLanguage = 0; |
|
286
|
|
|
|
|
287
|
|
|
$configuration = Util::getConfigurationFromPageId($rootPageId, 'config'); |
|
288
|
|
|
|
|
289
|
|
|
$siteDefaultLanguage = $configuration->getValueByPathOrDefaultValue('sys_language_uid', $siteDefaultLanguage); |
|
290
|
|
|
// default language is set through default L GET parameter -> overruling config.sys_language_uid |
|
291
|
|
|
$siteDefaultLanguage = $configuration->getValueByPathOrDefaultValue('defaultGetVars.L', $siteDefaultLanguage); |
|
292
|
|
|
|
|
293
|
|
|
return $siteDefaultLanguage; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Retrieves the configured solr servers from the registry. |
|
298
|
|
|
* |
|
299
|
|
|
* @deprecated This method is only required for old solr based sites. |
|
300
|
|
|
* @return array |
|
301
|
|
|
*/ |
|
302
|
|
|
protected function getSolrServersFromRegistry() |
|
303
|
|
|
{ |
|
304
|
|
|
trigger_error('solr:deprecation: Method getSolrServersFromRegistry is deprecated since EXT:solr 10 and will be removed in v11, use sitehanlding instead', E_USER_DEPRECATED); |
|
305
|
|
|
|
|
306
|
|
|
$servers = (array)$this->registry->get('tx_solr', 'servers', []); |
|
307
|
|
|
return $servers; |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
/** |
|
311
|
|
|
* @param $rootPageId |
|
312
|
|
|
* @deprecated This method is only required for old solr based sites. |
|
313
|
|
|
* @return NULL|string |
|
314
|
|
|
*/ |
|
315
|
|
|
protected function getDomainFromConfigurationOrFallbackToDomainRecord($rootPageId) |
|
316
|
|
|
{ |
|
317
|
|
|
trigger_error('solr:deprecation: Method getDomainFromConfigurationOrFallbackToDomainRecord is deprecated since EXT:solr 10 and will be removed in v11, use sitehanlding instead', E_USER_DEPRECATED); |
|
318
|
|
|
|
|
319
|
|
|
/** @var $siteService SiteService */ |
|
320
|
|
|
$siteService = GeneralUtility::makeInstance(SiteService::class); |
|
321
|
|
|
$domain = $siteService->getFirstDomainForRootPage($rootPageId); |
|
322
|
|
|
if ($domain === '') { |
|
323
|
|
|
$rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $rootPageId); |
|
324
|
|
|
try { |
|
325
|
|
|
$rootLine = $rootlineUtility->get(); |
|
326
|
|
|
} catch (\RuntimeException $e) { |
|
327
|
|
|
$rootLine = []; |
|
328
|
|
|
} |
|
329
|
|
|
$domain = $this->firstDomainRecordFromLegacyDomainResolver($rootLine); |
|
330
|
|
|
return (string)$domain; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
return $domain; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @param $rootLine |
|
338
|
|
|
* @return null|string |
|
339
|
|
|
*/ |
|
340
|
|
|
private function firstDomainRecordFromLegacyDomainResolver($rootLine) |
|
341
|
|
|
{ |
|
342
|
|
|
trigger_error('Method firstDomainRecordFromLegacyDomainResolver is deprecated since EXT:solr 10 and will be removed in v11, use sitehandling instead.', E_USER_DEPRECATED); |
|
343
|
|
|
$domainResolver = GeneralUtility::makeInstance(LegacyDomainResolver::class); |
|
344
|
|
|
foreach ($rootLine as $row) { |
|
345
|
|
|
$domain = $domainResolver->matchRootPageId($row['uid']); |
|
346
|
|
|
if (is_array($domain)) { |
|
347
|
|
|
return rtrim($domain['domainName'], '/'); |
|
348
|
|
|
} |
|
349
|
|
|
} |
|
350
|
|
|
return null; |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
/** |
|
354
|
|
|
* @param string $domain |
|
355
|
|
|
* @return string |
|
356
|
|
|
*/ |
|
357
|
|
|
protected function getSiteHashForDomain($domain) |
|
358
|
|
|
{ |
|
359
|
|
|
/** @var $siteHashService SiteHashService */ |
|
360
|
|
|
$siteHashService = GeneralUtility::makeInstance(SiteHashService::class); |
|
361
|
|
|
$siteHash = $siteHashService->getSiteHashForDomain($domain); |
|
362
|
|
|
return $siteHash; |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* @param int $rootPageId |
|
367
|
|
|
* @param array $rootPageRecord |
|
368
|
|
|
* @throws \InvalidArgumentException |
|
369
|
|
|
*/ |
|
370
|
|
|
protected function validateRootPageRecord($rootPageId, $rootPageRecord) |
|
371
|
|
|
{ |
|
372
|
|
|
if (empty($rootPageRecord)) { |
|
373
|
|
|
throw new \InvalidArgumentException( |
|
374
|
|
|
'The rootPageRecord for the given rootPageRecord ID \'' . $rootPageId . '\' could not be found in the database and can therefore not be used as site root rootPageRecord.', |
|
375
|
|
|
1487326416 |
|
376
|
|
|
); |
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
|
if (!Site::isRootPage($rootPageRecord)) { |
|
380
|
|
|
throw new \InvalidArgumentException( |
|
381
|
|
|
'The rootPageRecord for the given rootPageRecord ID \'' . $rootPageId . '\' is not marked as root rootPageRecord and can therefore not be used as site root rootPageRecord.', |
|
382
|
|
|
1309272922 |
|
383
|
|
|
); |
|
384
|
|
|
} |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* |
|
389
|
|
|
* @deprecated buildLegacySite is deprecated and will be removed in EXT:solr 11. Please configure your system with the TYPO3 sitehandling |
|
390
|
|
|
* @param array $rootPageRecord |
|
391
|
|
|
* @return LegacySite |
|
392
|
|
|
*/ |
|
393
|
|
|
protected function buildLegacySite($rootPageRecord): LegacySite |
|
394
|
|
|
{ |
|
395
|
|
|
trigger_error('solr:deprecation: You are using EXT:solr without sitehandling. This setup is deprecated and will be removed in EXT:solr 11', E_USER_DEPRECATED); |
|
396
|
|
|
|
|
397
|
|
|
$solrConfiguration = Util::getSolrConfigurationFromPageId($rootPageRecord['uid']); |
|
398
|
|
|
$domain = $this->getDomainFromConfigurationOrFallbackToDomainRecord($rootPageRecord['uid']); |
|
|
|
|
|
|
399
|
|
|
$siteHash = $this->getSiteHashForDomain($domain); |
|
400
|
|
|
$defaultLanguage = $this->getDefaultLanguage($rootPageRecord['uid']); |
|
|
|
|
|
|
401
|
|
|
$pageRepository = GeneralUtility::makeInstance(PagesRepository::class); |
|
402
|
|
|
$availableLanguageIds = GeneralUtility::makeInstance(SystemLanguageRepository::class)->findSystemLanguages(); |
|
403
|
|
|
|
|
404
|
|
|
return GeneralUtility::makeInstance( |
|
405
|
|
|
LegacySite::class, |
|
406
|
|
|
/** @scrutinizer ignore-type */ |
|
407
|
|
|
$solrConfiguration, |
|
408
|
|
|
/** @scrutinizer ignore-type */ |
|
409
|
|
|
$rootPageRecord, |
|
410
|
|
|
/** @scrutinizer ignore-type */ |
|
411
|
|
|
$domain, |
|
412
|
|
|
/** @scrutinizer ignore-type */ |
|
413
|
|
|
$siteHash, |
|
414
|
|
|
/** @scrutinizer ignore-type */ |
|
415
|
|
|
$pageRepository, |
|
416
|
|
|
/** @scrutinizer ignore-type */ |
|
417
|
|
|
$defaultLanguage, |
|
418
|
|
|
/** @scrutinizer ignore-type */ |
|
419
|
|
|
$availableLanguageIds |
|
420
|
|
|
); |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
|
|
/** |
|
424
|
|
|
* @param array $rootPageRecord |
|
425
|
|
|
* @return Typo3ManagedSite |
|
426
|
|
|
*/ |
|
427
|
|
|
protected function buildTypo3ManagedSite(array $rootPageRecord): Typo3ManagedSite |
|
428
|
|
|
{ |
|
429
|
|
|
$solrConfiguration = Util::getSolrConfigurationFromPageId($rootPageRecord['uid']); |
|
430
|
|
|
/** @var \TYPO3\CMS\Core\Site\Entity\Site $typo3Site */ |
|
431
|
|
|
$typo3Site = $this->siteFinder->getSiteByPageId($rootPageRecord['uid']); |
|
432
|
|
|
$domain = $typo3Site->getBase()->getHost(); |
|
433
|
|
|
|
|
434
|
|
|
$siteHash = $this->getSiteHashForDomain($domain); |
|
435
|
|
|
$defaultLanguage = $typo3Site->getDefaultLanguage()->getLanguageId(); |
|
436
|
|
|
$pageRepository = GeneralUtility::makeInstance(PagesRepository::class); |
|
437
|
|
|
$availableLanguageIds = array_map(function($language) { |
|
438
|
|
|
return $language->getLanguageId(); |
|
439
|
|
|
}, $typo3Site->getLanguages()); |
|
440
|
|
|
|
|
441
|
|
|
$solrConnectionConfigurations = []; |
|
442
|
|
|
|
|
443
|
|
|
foreach ($availableLanguageIds as $languageUid) { |
|
444
|
|
|
$solrEnabled = SiteUtility::getConnectionProperty($typo3Site, 'enabled', $languageUid, 'read', true); |
|
445
|
|
|
if ($solrEnabled) { |
|
446
|
|
|
$solrConnectionConfigurations[$languageUid] = [ |
|
447
|
|
|
'connectionKey' => $rootPageRecord['uid'] . '|' . $languageUid, |
|
448
|
|
|
'rootPageTitle' => $rootPageRecord['title'], |
|
449
|
|
|
'rootPageUid' => $rootPageRecord['uid'], |
|
450
|
|
|
'read' => [ |
|
451
|
|
|
'scheme' => SiteUtility::getConnectionProperty($typo3Site, 'scheme', $languageUid, 'read', 'http'), |
|
452
|
|
|
'host' => SiteUtility::getConnectionProperty($typo3Site, 'host', $languageUid, 'read', 'localhost'), |
|
453
|
|
|
'port' => (int)SiteUtility::getConnectionProperty($typo3Site, 'port', $languageUid, 'read', 8983), |
|
454
|
|
|
// @todo: transform core to path |
|
455
|
|
|
'path' => |
|
456
|
|
|
SiteUtility::getConnectionProperty($typo3Site, 'path', $languageUid, 'read', '/solr/') . |
|
457
|
|
|
SiteUtility::getConnectionProperty($typo3Site, 'core', $languageUid, 'read', 'core_en') . '/' , |
|
458
|
|
|
'username' => SiteUtility::getConnectionProperty($typo3Site, 'username', $languageUid, 'read', ''), |
|
459
|
|
|
'password' => SiteUtility::getConnectionProperty($typo3Site, 'password', $languageUid, 'read', ''), |
|
460
|
|
|
'timeout' => SiteUtility::getConnectionProperty($typo3Site, 'timeout', $languageUid, 'read', 0) |
|
461
|
|
|
], |
|
462
|
|
|
'write' => [ |
|
463
|
|
|
'scheme' => SiteUtility::getConnectionProperty($typo3Site, 'scheme', $languageUid, 'write', 'http'), |
|
464
|
|
|
'host' => SiteUtility::getConnectionProperty($typo3Site, 'host', $languageUid, 'write', 'localhost'), |
|
465
|
|
|
'port' => (int)SiteUtility::getConnectionProperty($typo3Site, 'port', $languageUid, 'write', 8983), |
|
466
|
|
|
// @todo: transform core to path |
|
467
|
|
|
'path' => |
|
468
|
|
|
SiteUtility::getConnectionProperty($typo3Site, 'path', $languageUid, 'read', '/solr/') . |
|
469
|
|
|
SiteUtility::getConnectionProperty($typo3Site, 'core', $languageUid, 'read', 'core_en') . '/' , |
|
470
|
|
|
'username' => SiteUtility::getConnectionProperty($typo3Site, 'username', $languageUid, 'write', ''), |
|
471
|
|
|
'password' => SiteUtility::getConnectionProperty($typo3Site, 'password', $languageUid, 'write', ''), |
|
472
|
|
|
'timeout' => SiteUtility::getConnectionProperty($typo3Site, 'timeout', $languageUid, 'write', 0) |
|
473
|
|
|
], |
|
474
|
|
|
|
|
475
|
|
|
'language' => $languageUid |
|
476
|
|
|
]; |
|
477
|
|
|
} |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
return GeneralUtility::makeInstance( |
|
481
|
|
|
Typo3ManagedSite::class, |
|
482
|
|
|
/** @scrutinizer ignore-type */ |
|
483
|
|
|
$solrConfiguration, |
|
484
|
|
|
/** @scrutinizer ignore-type */ |
|
485
|
|
|
$rootPageRecord, |
|
486
|
|
|
/** @scrutinizer ignore-type */ |
|
487
|
|
|
$domain, |
|
488
|
|
|
/** @scrutinizer ignore-type */ |
|
489
|
|
|
$siteHash, |
|
490
|
|
|
/** @scrutinizer ignore-type */ |
|
491
|
|
|
$pageRepository, |
|
492
|
|
|
/** @scrutinizer ignore-type */ |
|
493
|
|
|
$defaultLanguage, |
|
494
|
|
|
/** @scrutinizer ignore-type */ |
|
495
|
|
|
$availableLanguageIds, |
|
496
|
|
|
/** @scrutinizer ignore-type */ |
|
497
|
|
|
$solrConnectionConfigurations, |
|
498
|
|
|
/** @scrutinizer ignore-type */ |
|
499
|
|
|
$typo3Site |
|
500
|
|
|
); |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
} |
|
504
|
|
|
|