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\Utility\GeneralUtility; |
32
|
|
|
use TYPO3\CMS\Core\Site\Entity\Site as Typo3Site; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Class Typo3ManagedSite |
37
|
|
|
*/ |
38
|
|
|
class Typo3ManagedSite extends Site |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var Typo3Site |
43
|
|
|
*/ |
44
|
|
|
protected $typo3SiteObject; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
protected $solrConnectionConfigurations; |
50
|
|
|
|
51
|
|
|
|
52
|
151 |
|
public function __construct( |
53
|
|
|
TypoScriptConfiguration $configuration, |
54
|
|
|
array $page, $domain, $siteHash, PagesRepository $pagesRepository = null, $defaultLanguageId = 0, $availableLanguageIds = [], array $solrConnectionConfigurations = [], Typo3Site $typo3SiteObject = null) |
55
|
|
|
{ |
56
|
151 |
|
$this->configuration = $configuration; |
57
|
151 |
|
$this->rootPage = $page; |
58
|
151 |
|
$this->domain = $domain; |
59
|
151 |
|
$this->siteHash = $siteHash; |
60
|
151 |
|
$this->pagesRepository = $pagesRepository ?? GeneralUtility::makeInstance(PagesRepository::class); |
61
|
151 |
|
$this->defaultLanguageId = $defaultLanguageId; |
62
|
151 |
|
$this->availableLanguageIds = $availableLanguageIds; |
63
|
151 |
|
$this->solrConnectionConfigurations = $solrConnectionConfigurations; |
64
|
151 |
|
$this->typo3SiteObject = $typo3SiteObject; |
65
|
151 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param int $language |
69
|
|
|
* @return array |
70
|
|
|
* @throws NoSolrConnectionFoundException |
71
|
|
|
*/ |
72
|
140 |
|
public function getSolrConnectionConfiguration(int $language = 0): array |
73
|
|
|
{ |
74
|
140 |
|
if (!is_array($this->solrConnectionConfigurations[$language])) { |
75
|
|
|
/* @var $noSolrConnectionException NoSolrConnectionFoundException */ |
76
|
2 |
|
$noSolrConnectionException = GeneralUtility::makeInstance( |
77
|
|
|
NoSolrConnectionFoundException::class, |
78
|
2 |
|
/** @scrutinizer ignore-type */ 'Could not find a Solr connection for root page [' . $this->getRootPageId() . '] and language [' . $language . '].', |
79
|
2 |
|
/** @scrutinizer ignore-type */ 1552491117 |
80
|
|
|
); |
81
|
2 |
|
$noSolrConnectionException->setRootPageId($this->getRootPageId()); |
82
|
2 |
|
$noSolrConnectionException->setLanguageId($language); |
83
|
|
|
|
84
|
2 |
|
throw $noSolrConnectionException; |
85
|
|
|
} |
86
|
|
|
|
87
|
140 |
|
return $this->solrConnectionConfigurations[$language]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns \TYPO3\CMS\Core\Site\Entity\Site |
92
|
|
|
* |
93
|
|
|
* @return Typo3Site |
94
|
|
|
*/ |
95
|
4 |
|
public function getTypo3SiteObject(): Typo3Site |
96
|
|
|
{ |
97
|
4 |
|
return $this->typo3SiteObject; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|