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