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 TYPO3\CMS\Core\Context\Context; |
||
32 | use TYPO3\CMS\Core\Registry; |
||
33 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||
34 | |||
35 | /** |
||
36 | * Class LegacySite |
||
37 | * |
||
38 | * @deprecated This class is used for the old solr setup based on TypoScript and sys_registry records. |
||
39 | */ |
||
40 | class LegacySite extends Site |
||
41 | { |
||
42 | |||
43 | /** |
||
44 | * Constructor. |
||
45 | * |
||
46 | * @param TypoScriptConfiguration $configuration |
||
47 | * @param array $page Site root page ID (uid). The page must be marked as site root ("Use as Root Page" flag). |
||
48 | * @param string $domain The domain record used by this Site |
||
49 | * @param string $siteHash The site hash used by this site |
||
50 | * @param PagesRepository $pagesRepository |
||
51 | * @param int $defaultLanguageId |
||
52 | * @param int[] $availableLanguageIds |
||
53 | */ |
||
54 | public function __construct(TypoScriptConfiguration $configuration, array $page, $domain, $siteHash, PagesRepository $pagesRepository = null, $defaultLanguageId = 0, $availableLanguageIds = []) |
||
55 | { |
||
56 | 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); |
||
57 | |||
58 | $this->configuration = $configuration; |
||
59 | $this->rootPage = $page; |
||
60 | $this->domain = $domain; |
||
61 | $this->siteHash = $siteHash; |
||
62 | $this->pagesRepository = $pagesRepository ?? GeneralUtility::makeInstance(PagesRepository::class); |
||
63 | $this->defaultLanguageId = $defaultLanguageId; |
||
64 | $this->availableLanguageIds = $availableLanguageIds; |
||
65 | |||
66 | } |
||
67 | |||
68 | |||
69 | /** |
||
70 | * @param int $language |
||
71 | * @return array |
||
72 | * @throws NoSolrConnectionFoundException |
||
73 | */ |
||
74 | public function getSolrConnectionConfiguration(int $language = 0): array { |
||
75 | $connectionKey = $this->getRootPageId() . '|' . $language; |
||
76 | $solrConfiguration = $this->getSolrConnectionConfigFromRegistry($connectionKey); |
||
77 | |||
78 | if (!is_array($solrConfiguration)) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
79 | /* @var $noSolrConnectionException NoSolrConnectionFoundException */ |
||
80 | $noSolrConnectionException = GeneralUtility::makeInstance( |
||
81 | NoSolrConnectionFoundException::class, |
||
82 | /** @scrutinizer ignore-type */ 'Could not find a Solr connection for root page [' . $this->getRootPageId() . '] and language [' . $language . '].', |
||
83 | /** @scrutinizer ignore-type */ 1275396474 |
||
84 | ); |
||
85 | $noSolrConnectionException->setRootPageId($this->getRootPageId()); |
||
86 | $noSolrConnectionException->setLanguageId($language); |
||
87 | |||
88 | throw $noSolrConnectionException; |
||
89 | } |
||
90 | |||
91 | return $solrConfiguration; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Gets all connection configurations found. |
||
96 | * |
||
97 | * @return array An array of connection configurations. |
||
98 | */ |
||
99 | protected function getSolrConnectionConfigFromRegistry(string $connectionKey) |
||
100 | { |
||
101 | /** @var $registry Registry */ |
||
102 | $registry = GeneralUtility::makeInstance(Registry::class); |
||
103 | $solrConfigurations = $registry->get('tx_solr', 'servers', []); |
||
104 | |||
105 | return $solrConfigurations[$connectionKey] ?? null; |
||
106 | } |
||
107 | |||
108 | } |
||
109 |