1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2010-2015 Ingo Renner <[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
|
|
|
* |
19
|
|
|
* This script is distributed in the hope that it will be useful, |
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
|
|
|
* GNU General Public License for more details. |
23
|
|
|
* |
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
25
|
|
|
***************************************************************/ |
26
|
|
|
|
27
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Site\Site; |
28
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Site\SiteRepository; |
29
|
|
|
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; |
30
|
|
|
use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository as PagesRepositoryAtExtSolr; |
31
|
|
|
use ApacheSolrForTypo3\Solr\System\Records\SystemLanguage\SystemLanguageRepository; |
32
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\Node; |
33
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection; |
34
|
|
|
use TYPO3\CMS\Core\Registry; |
35
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
36
|
|
|
use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService; |
37
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
38
|
|
|
use TYPO3\CMS\Frontend\Page\PageRepository; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* ConnectionManager is responsible to create SolrConnection objects. |
42
|
|
|
* |
43
|
|
|
* @author Ingo Renner <[email protected]> |
44
|
|
|
*/ |
45
|
|
|
class ConnectionManager implements SingletonInterface |
46
|
|
|
{ |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
protected static $connections = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var \ApacheSolrForTypo3\Solr\System\Records\SystemLanguage\SystemLanguageRepository |
55
|
|
|
*/ |
56
|
|
|
protected $systemLanguageRepository; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var PagesRepositoryAtExtSolr |
60
|
|
|
*/ |
61
|
|
|
protected $pagesRepositoryAtExtSolr; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var SiteRepository |
65
|
|
|
*/ |
66
|
|
|
protected $siteRepository; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param SystemLanguageRepository $systemLanguageRepository |
70
|
|
|
* @param PagesRepositoryAtExtSolr|null $pagesRepositoryAtExtSolr |
71
|
|
|
* @param SiteRepository $siteRepository |
72
|
|
|
*/ |
73
|
119 |
|
public function __construct(SystemLanguageRepository $systemLanguageRepository = null, PagesRepositoryAtExtSolr $pagesRepositoryAtExtSolr = null, SiteRepository $siteRepository = null) |
74
|
|
|
{ |
75
|
119 |
|
$this->systemLanguageRepository = $systemLanguageRepository ?? GeneralUtility::makeInstance(SystemLanguageRepository::class); |
76
|
119 |
|
$this->siteRepository = $siteRepository ?? GeneralUtility::makeInstance(SiteRepository::class); |
77
|
119 |
|
$this->pagesRepositoryAtExtSolr = $pagesRepositoryAtExtSolr ?? GeneralUtility::makeInstance(PagesRepositoryAtExtSolr::class); |
78
|
119 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Creates a solr connection for read and write endpoints |
82
|
|
|
* |
83
|
|
|
* @param array $readNodeConfiguration |
84
|
|
|
* @param array $writeNodeConfiguration |
85
|
|
|
* @return SolrConnection|object |
86
|
|
|
*/ |
87
|
106 |
|
public function getSolrConnectionForNodes(array $readNodeConfiguration, array $writeNodeConfiguration) |
88
|
|
|
{ |
89
|
106 |
|
$connectionHash = md5(\json_encode($readNodeConfiguration) . \json_encode($writeNodeConfiguration)); |
90
|
106 |
|
if (!isset(self::$connections[$connectionHash])) { |
91
|
106 |
|
$readNode = Node::fromArray($readNodeConfiguration); |
92
|
106 |
|
$writeNode = Node::fromArray($writeNodeConfiguration); |
93
|
106 |
|
self::$connections[$connectionHash] = GeneralUtility::makeInstance(SolrConnection::class, $readNode, $writeNode); |
94
|
|
|
} |
95
|
106 |
|
return self::$connections[$connectionHash]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Creates a solr configuration from the configuration array and returns it. |
100
|
|
|
* |
101
|
|
|
* @param array $config The solr configuration array |
102
|
|
|
* @return SolrConnection |
103
|
|
|
*/ |
104
|
108 |
|
public function getConnectionFromConfiguration(array $config) |
105
|
|
|
{ |
106
|
108 |
|
if(empty($config['read']) && !empty($config['solrHost'])) { |
107
|
|
|
throw new \InvalidArgumentException('Invalid registry data please re-initialize your solr connections'); |
108
|
|
|
} |
109
|
|
|
|
110
|
108 |
|
return $this->getSolrConnectionForNodes($config['read'], $config['write']); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Gets a Solr configuration for a page ID. |
115
|
|
|
* |
116
|
|
|
* @param int $pageId A page ID. |
117
|
|
|
* @param int $language The language ID to get the connection for as the path may differ. Optional, defaults to 0. |
118
|
|
|
* @param string $mount Comma list of MountPoint parameters |
119
|
|
|
* @deprecated will be removed in v11, use Site object/SiteRepository directly |
120
|
|
|
* @return array A solr configuration. |
121
|
|
|
* @throws NoSolrConnectionFoundException |
122
|
|
|
*/ |
123
|
|
|
public function getConfigurationByPageId($pageId, $language = 0, $mount = '') |
124
|
|
|
{ |
125
|
|
|
try { |
126
|
|
|
$site = $this->siteRepository->getSiteByPageId($pageId, $mount); |
127
|
|
|
return $site->getSolrConnectionConfiguration($language); |
128
|
|
|
} catch(\InvalidArgumentException $e) { |
129
|
|
|
$noSolrConnectionException = GeneralUtility::makeInstance( |
130
|
|
|
NoSolrConnectionFoundException::class, |
131
|
|
|
/** @scrutinizer ignore-type */ 'Could not find a Solr connection for page [' . $pageId. '] and language [' . $language . '].', |
132
|
|
|
/** @scrutinizer ignore-type */ 1575396474 |
133
|
|
|
); |
134
|
|
|
$noSolrConnectionException->setLanguageId($language); |
135
|
|
|
throw $noSolrConnectionException; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Gets a Solr connection for a page ID. |
141
|
|
|
* |
142
|
|
|
* @param int $pageId A page ID. |
143
|
|
|
* @param int $language The language ID to get the connection for as the path may differ. Optional, defaults to 0. |
144
|
|
|
* @param string $mount Comma list of MountPoint parameters |
145
|
|
|
* @return SolrConnection A solr connection. |
146
|
|
|
* @throws NoSolrConnectionFoundException |
147
|
|
|
*/ |
148
|
98 |
|
public function getConnectionByPageId($pageId, $language = 0, $mount = '') |
149
|
|
|
{ |
150
|
|
|
try { |
151
|
98 |
|
$site = $this->siteRepository->getSiteByPageId($pageId, $mount); |
152
|
97 |
|
$config = $site->getSolrConnectionConfiguration($language); |
153
|
97 |
|
$solrConnection = $this->getConnectionFromConfiguration($config); |
154
|
|
|
|
155
|
97 |
|
return $solrConnection; |
156
|
2 |
|
} catch(\InvalidArgumentException $e) { |
157
|
1 |
|
$noSolrConnectionException = GeneralUtility::makeInstance( |
158
|
1 |
|
NoSolrConnectionFoundException::class, |
159
|
1 |
|
/** @scrutinizer ignore-type */ 'Could not find a Solr connection for page [' . $pageId. '] and language [' . $language . '].', |
160
|
1 |
|
/** @scrutinizer ignore-type */ 1575396474 |
161
|
|
|
); |
162
|
1 |
|
$noSolrConnectionException->setLanguageId($language); |
163
|
1 |
|
throw $noSolrConnectionException; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Gets a Solr configuration for a root page ID. |
169
|
|
|
* |
170
|
|
|
* @param int $pageId A root page ID. |
171
|
|
|
* @param int $language The language ID to get the configuration for as the path may differ. Optional, defaults to 0. |
172
|
|
|
* @return array A solr configuration. |
173
|
|
|
* @throws NoSolrConnectionFoundException |
174
|
|
|
* @deprecated will be removed in v11, use Site object/SiteRepository directly |
175
|
|
|
*/ |
176
|
1 |
|
public function getConfigurationByRootPageId($pageId, $language = 0) |
177
|
|
|
{ |
178
|
|
|
try { |
179
|
1 |
|
$site = $this->siteRepository->getSiteByRootPageId($pageId); |
180
|
|
|
return $site->getSolrConnectionConfiguration($language); |
181
|
1 |
|
} catch(\InvalidArgumentException $e) { |
182
|
1 |
|
$noSolrConnectionException = GeneralUtility::makeInstance( |
183
|
1 |
|
NoSolrConnectionFoundException::class, |
184
|
1 |
|
/** @scrutinizer ignore-type */ 'Could not find a Solr connection for page [' . $pageId. '] and language [' . $language . '].', |
185
|
1 |
|
/** @scrutinizer ignore-type */ 1575396474 |
186
|
|
|
); |
187
|
1 |
|
$noSolrConnectionException->setLanguageId($language); |
188
|
1 |
|
throw $noSolrConnectionException; |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Gets a Solr connection for a root page ID. |
194
|
|
|
* |
195
|
|
|
* @param int $pageId A root page ID. |
196
|
|
|
* @param int $language The language ID to get the connection for as the path may differ. Optional, defaults to 0. |
197
|
|
|
* @return SolrConnection A solr connection. |
198
|
|
|
* @throws NoSolrConnectionFoundException |
199
|
|
|
*/ |
200
|
10 |
|
public function getConnectionByRootPageId($pageId, $language = 0) |
201
|
|
|
{ |
202
|
|
|
try { |
203
|
10 |
|
$site = $this->siteRepository->getSiteByRootPageId($pageId); |
204
|
10 |
|
$config = $site->getSolrConnectionConfiguration($language); |
205
|
10 |
|
$solrConnection = $this->getConnectionFromConfiguration($config); |
206
|
10 |
|
return $solrConnection; |
207
|
|
|
} catch (\InvalidArgumentException $e) { |
208
|
|
|
$noSolrConnectionException = GeneralUtility::makeInstance( |
209
|
|
|
NoSolrConnectionFoundException::class, |
210
|
|
|
/** @scrutinizer ignore-type */ 'Could not find a Solr connection for page [' . $pageId. '] and language [' . $language . '].', |
211
|
|
|
/** @scrutinizer ignore-type */ 1875396474 |
212
|
|
|
); |
213
|
|
|
$noSolrConnectionException->setLanguageId($language); |
214
|
|
|
throw $noSolrConnectionException; |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Gets all connection configurations found. |
220
|
|
|
* |
221
|
|
|
* @return array An array of connection configurations. |
222
|
|
|
* @deprecated will be removed in v11, use SiteRepository |
223
|
|
|
*/ |
224
|
1 |
|
public function getAllConfigurations() |
225
|
|
|
{ |
226
|
1 |
|
$solrConfigurations = []; |
227
|
1 |
|
foreach ($this->siteRepository->getAvailableSites() as $site) { |
228
|
|
|
foreach ($site->getAllSolrConnectionConfigurations() as $solrConfiguration) { |
229
|
|
|
$solrConfigurations[] = $solrConfiguration; |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
233
|
1 |
|
return $solrConfigurations; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Stores the connections in the registry. |
238
|
|
|
* |
239
|
|
|
* @param array $solrConfigurations |
240
|
|
|
* @deprecated will be removed in v11, use SiteRepository |
241
|
|
|
*/ |
242
|
3 |
|
protected function setAllConfigurations(array $solrConfigurations) |
243
|
|
|
{ |
244
|
|
|
/** @var $registry Registry */ |
245
|
3 |
|
$registry = GeneralUtility::makeInstance(Registry::class); |
246
|
3 |
|
$registry->set('tx_solr', 'servers', $solrConfigurations); |
247
|
3 |
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Gets all connections found. |
251
|
|
|
* |
252
|
|
|
* @return SolrConnection[] An array of initialized ApacheSolrForTypo3\Solr\System\Solr\SolrConnection connections |
253
|
|
|
*/ |
254
|
7 |
|
public function getAllConnections() |
255
|
|
|
{ |
256
|
7 |
|
$solrConnections = []; |
257
|
7 |
|
foreach ($this->siteRepository->getAvailableSites() as $site) { |
258
|
3 |
|
foreach ($site->getAllSolrConnectionConfigurations() as $solrConfiguration) { |
259
|
3 |
|
$solrConnections[] = $this->getConnectionFromConfiguration($solrConfiguration); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
7 |
|
return $solrConnections; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Gets all connection configurations for a given site. |
268
|
|
|
* |
269
|
|
|
* @param Site $site A TYPO3 site |
270
|
|
|
* @return array An array of Solr connection configurations for a site |
271
|
|
|
* @deprecated will be removed in v11, use $site->getAllSolrConnectionConfigurations() |
272
|
|
|
*/ |
273
|
22 |
|
public function getConfigurationsBySite(Site $site) |
274
|
|
|
{ |
275
|
22 |
|
return $site->getAllSolrConnectionConfigurations(); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Gets all connections configured for a given site. |
280
|
|
|
* |
281
|
|
|
* @param Site $site A TYPO3 site |
282
|
|
|
* @return SolrConnection[] An array of Solr connection objects (ApacheSolrForTypo3\Solr\System\Solr\SolrConnection) |
283
|
|
|
*/ |
284
|
18 |
|
public function getConnectionsBySite(Site $site) |
285
|
|
|
{ |
286
|
18 |
|
$connections = []; |
287
|
|
|
|
288
|
18 |
|
foreach ($site->getAllSolrConnectionConfigurations() as $solrConnectionConfiguration) { |
289
|
18 |
|
$connections[] = $this->getConnectionFromConfiguration($solrConnectionConfiguration); |
290
|
|
|
} |
291
|
|
|
|
292
|
18 |
|
return $connections; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
// updates |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Updates the connections in the registry. |
299
|
|
|
* |
300
|
|
|
* @deprecated will be removed in v11, use SiteRepository |
301
|
|
|
*/ |
302
|
2 |
|
public function updateConnections() |
303
|
|
|
{ |
304
|
|
|
|
305
|
2 |
|
$solrConnections = $this->getConfiguredSolrConnections(); |
|
|
|
|
306
|
2 |
|
$solrConnections = $this->filterDuplicateConnections($solrConnections); |
|
|
|
|
307
|
|
|
|
308
|
2 |
|
if (!empty($solrConnections)) { |
309
|
2 |
|
$this->setAllConfigurations($solrConnections); |
|
|
|
|
310
|
|
|
} |
311
|
2 |
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Updates the Solr connections for a specific root page ID / site. |
315
|
|
|
* |
316
|
|
|
* @param int $rootPageId A site root page id |
317
|
|
|
* @deprecated Use TYPO3 site config to configure site/connection info |
318
|
|
|
*/ |
319
|
1 |
|
public function updateConnectionByRootPageId($rootPageId) |
320
|
|
|
{ |
321
|
1 |
|
$systemLanguages = $this->systemLanguageRepository->findSystemLanguages(); |
322
|
1 |
|
$siteRepository = GeneralUtility::makeInstance(SiteRepository::class); |
323
|
1 |
|
$site = $siteRepository->getSiteByRootPageId($rootPageId); |
324
|
1 |
|
$rootPage = $site->getRootPage(); |
325
|
|
|
|
326
|
1 |
|
$updatedSolrConnections = []; |
327
|
1 |
|
foreach ($systemLanguages as $languageId) { |
328
|
1 |
|
$connection = $this->getConfiguredSolrConnectionByRootPage($rootPage, $languageId); |
|
|
|
|
329
|
|
|
|
330
|
1 |
|
if (!empty($connection)) { |
331
|
1 |
|
$updatedSolrConnections[$connection['connectionKey']] = $connection; |
332
|
|
|
} |
333
|
|
|
} |
334
|
|
|
|
335
|
1 |
|
$solrConnections = $this->getAllConfigurations(); |
|
|
|
|
336
|
1 |
|
$solrConnections = array_merge($solrConnections, $updatedSolrConnections); |
337
|
1 |
|
$solrConnections = $this->filterDuplicateConnections($solrConnections); |
|
|
|
|
338
|
1 |
|
$this->setAllConfigurations($solrConnections); |
|
|
|
|
339
|
1 |
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* Finds the configured Solr connections. Also respects multi-site |
343
|
|
|
* environments. |
344
|
|
|
* |
345
|
|
|
* @return array An array with connections, each connection with keys rootPageTitle, rootPageUid, solrHost, solrPort, solrPath |
346
|
|
|
* @deprecated will be removed in v11, use SiteRepository |
347
|
|
|
*/ |
348
|
2 |
|
protected function getConfiguredSolrConnections() |
349
|
|
|
{ |
350
|
2 |
|
$configuredSolrConnections = []; |
351
|
|
|
// find website roots and languages for this installation |
352
|
2 |
|
$rootPages = $this->pagesRepositoryAtExtSolr->findAllRootPages(); |
353
|
2 |
|
$languages = $this->systemLanguageRepository->findSystemLanguages(); |
354
|
|
|
|
355
|
|
|
// find solr configurations and add them as function menu entries |
356
|
2 |
|
foreach ($rootPages as $rootPage) { |
357
|
2 |
|
foreach ($languages as $languageId) { |
358
|
2 |
|
$connection = $this->getConfiguredSolrConnectionByRootPage($rootPage, $languageId); |
|
|
|
|
359
|
|
|
|
360
|
2 |
|
if (!empty($connection)) { |
361
|
2 |
|
$configuredSolrConnections[$connection['connectionKey']] = $connection; |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
} |
365
|
|
|
|
366
|
2 |
|
return $configuredSolrConnections; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Gets the configured Solr connection for a specific root page and language ID. |
371
|
|
|
* |
372
|
|
|
* @param array $rootPage A root page record with at least title and uid |
373
|
|
|
* @param int $languageId ID of a system language |
374
|
|
|
* @return array A solr connection configuration. |
375
|
|
|
* @deprecated will be removed in v11, use SiteRepository |
376
|
|
|
*/ |
377
|
3 |
|
protected function getConfiguredSolrConnectionByRootPage(array $rootPage, $languageId) |
378
|
|
|
{ |
379
|
3 |
|
$connection = []; |
380
|
|
|
|
381
|
3 |
|
$languageId = (int)$languageId; |
382
|
3 |
|
GeneralUtility::_GETset($languageId, 'L'); |
|
|
|
|
383
|
3 |
|
$connectionKey = $rootPage['uid'] . '|' . $languageId; |
384
|
|
|
|
385
|
3 |
|
$pageSelect = GeneralUtility::makeInstance(PageRepository::class); |
386
|
3 |
|
$rootLine = $pageSelect->getRootLine($rootPage['uid']); |
387
|
|
|
|
388
|
3 |
|
$tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class); |
389
|
3 |
|
$tmpl->tt_track = false; // Do not log time-performance information |
390
|
3 |
|
$tmpl->init(); |
391
|
3 |
|
$tmpl->runThroughTemplates($rootLine); // This generates the constants/config + hierarchy info for the template. |
392
|
|
|
|
393
|
|
|
// fake micro TSFE to get correct condition parsing |
394
|
3 |
|
$GLOBALS['TSFE'] = new \stdClass(); |
395
|
3 |
|
$GLOBALS['TSFE']->tmpl = new \stdClass(); |
396
|
3 |
|
$GLOBALS['TSFE']->cObjectDepthCounter = 50; |
397
|
3 |
|
$GLOBALS['TSFE']->tmpl->rootLine = $rootLine; |
398
|
3 |
|
$GLOBALS['TSFE']->sys_page = $pageSelect; |
399
|
3 |
|
$GLOBALS['TSFE']->id = $rootPage['uid']; |
400
|
3 |
|
$GLOBALS['TSFE']->page = $rootPage; |
401
|
|
|
|
402
|
3 |
|
$tmpl->generateConfig(); |
403
|
3 |
|
$GLOBALS['TSFE']->tmpl->setup = $tmpl->setup; |
404
|
|
|
|
405
|
3 |
|
$configuration = Util::getSolrConfigurationFromPageId($rootPage['uid'], false, $languageId); |
406
|
|
|
|
407
|
3 |
|
$solrIsEnabledAndConfigured = $configuration->getEnabled() && $configuration->getSolrHasConnectionConfiguration(); |
408
|
3 |
|
if (!$solrIsEnabledAndConfigured) { |
409
|
|
|
return $connection; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
$connection = [ |
413
|
3 |
|
'connectionKey' => $connectionKey, |
414
|
3 |
|
'rootPageTitle' => $rootPage['title'], |
415
|
3 |
|
'rootPageUid' => $rootPage['uid'], |
416
|
|
|
'read' => [ |
417
|
3 |
|
'scheme' => $configuration->getSolrScheme(), |
418
|
3 |
|
'host' => $configuration->getSolrHost(), |
419
|
3 |
|
'port' => $configuration->getSolrPort(), |
420
|
3 |
|
'path' => $configuration->getSolrPath(), |
421
|
3 |
|
'username' => $configuration->getSolrUsername(), |
422
|
3 |
|
'password' => $configuration->getSolrPassword(), |
423
|
3 |
|
'timeout' => $configuration->getSolrTimeout() |
424
|
|
|
], |
425
|
|
|
'write' => [ |
426
|
3 |
|
'scheme' => $configuration->getSolrScheme('http', 'write'), |
427
|
3 |
|
'host' => $configuration->getSolrHost('localhost', 'write'), |
428
|
3 |
|
'port' => $configuration->getSolrPort(8983, 'write'), |
429
|
3 |
|
'path' => $configuration->getSolrPath('/solr/core_en/', 'write'), |
430
|
3 |
|
'username' => $configuration->getSolrUsername('', 'write'), |
431
|
3 |
|
'password' => $configuration->getSolrPassword('', 'write'), |
432
|
3 |
|
'timeout' => $configuration->getSolrTimeout(0, 'write') |
433
|
|
|
], |
434
|
|
|
|
435
|
3 |
|
'language' => $languageId |
436
|
|
|
]; |
437
|
|
|
|
438
|
3 |
|
$connection['label'] = $this->buildConnectionLabel($connection); |
439
|
3 |
|
return $connection; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* Creates a human readable label from the connections' configuration. |
444
|
|
|
* |
445
|
|
|
* @param array $connection Connection configuration |
446
|
|
|
* @return string Connection label |
447
|
|
|
*/ |
448
|
3 |
|
protected function buildConnectionLabel(array $connection) |
449
|
|
|
{ |
450
|
3 |
|
return $connection['rootPageTitle'] |
451
|
3 |
|
. ' (pid: ' . $connection['rootPageUid'] |
452
|
3 |
|
. ', language: ' . $this->systemLanguageRepository->findOneLanguageTitleByLanguageId($connection['language']) |
453
|
3 |
|
. ') - Read node: ' |
454
|
3 |
|
. $connection['read']['host'] . ':' |
455
|
3 |
|
. $connection['read']['port'] |
456
|
3 |
|
. $connection['read']['path'] |
457
|
3 |
|
.' - Write node: ' |
458
|
3 |
|
. $connection['write']['host'] . ':' |
459
|
3 |
|
. $connection['write']['port'] |
460
|
3 |
|
. $connection['write']['path']; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Filters duplicate connections. When detecting the configured connections |
465
|
|
|
* this is done with a little brute force by simply combining all root pages |
466
|
|
|
* with all languages, this method filters out the duplicates. |
467
|
|
|
* |
468
|
|
|
* @param array $connections An array of unfiltered connections, containing duplicates |
469
|
|
|
* @return array An array with connections, no duplicates. |
470
|
|
|
* @deprecated will be removed in v11, use SiteRepository |
471
|
|
|
*/ |
472
|
3 |
|
protected function filterDuplicateConnections(array $connections) |
473
|
|
|
{ |
474
|
3 |
|
$hashedConnections = []; |
475
|
3 |
|
$filteredConnections = []; |
476
|
|
|
|
477
|
|
|
// array_unique() doesn't work on multi dimensional arrays, so we need to flatten it first |
478
|
3 |
|
foreach ($connections as $key => $connection) { |
479
|
3 |
|
unset($connection['language']); |
480
|
3 |
|
$connectionHash = md5(implode('|', $connection)); |
481
|
3 |
|
$hashedConnections[$key] = $connectionHash; |
482
|
|
|
} |
483
|
|
|
|
484
|
3 |
|
$hashedConnections = array_unique($hashedConnections); |
485
|
|
|
|
486
|
3 |
|
foreach ($hashedConnections as $key => $hash) { |
487
|
3 |
|
$filteredConnections[$key] = $connections[$key]; |
488
|
|
|
} |
489
|
|
|
|
490
|
3 |
|
return $filteredConnections; |
491
|
|
|
} |
492
|
|
|
} |
493
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.