1 | <?php |
||
41 | class SiteRepository |
||
42 | { |
||
43 | /** |
||
44 | * Rootpage resolver |
||
45 | * |
||
46 | * @var RootPageResolver |
||
47 | */ |
||
48 | protected $rootPageResolver; |
||
49 | |||
50 | /** |
||
51 | * @var TwoLevelCache |
||
52 | */ |
||
53 | protected $runtimeCache; |
||
54 | |||
55 | /** |
||
56 | * @var Registry |
||
57 | */ |
||
58 | protected $registry; |
||
59 | |||
60 | /** |
||
61 | * SiteRepository constructor. |
||
62 | * |
||
63 | * @param RootPageResolver|null $rootPageResolver |
||
64 | * @param TwoLevelCache|null $twoLevelCache |
||
65 | * @param Registry|null $registry |
||
66 | */ |
||
67 | 135 | public function __construct(RootPageResolver $rootPageResolver = null, TwoLevelCache $twoLevelCache = null, Registry $registry = null) |
|
73 | |||
74 | /** |
||
75 | * Gets the Site for a specific page Id. |
||
76 | * |
||
77 | * @param int $pageId The page Id to get a Site object for. |
||
78 | * @param string $mountPointIdentifier |
||
79 | * @return Site Site for the given page Id. |
||
80 | */ |
||
81 | 73 | public function getSiteByPageId($pageId, $mountPointIdentifier = '') |
|
86 | |||
87 | /** |
||
88 | * Gets the Site for a specific root page Id. |
||
89 | * |
||
90 | * @param int $rootPageId Root page Id to get a Site object for. |
||
91 | * @return Site Site for the given page Id. |
||
92 | */ |
||
93 | 81 | public function getSiteByRootPageId($rootPageId) |
|
107 | |||
108 | /** |
||
109 | * Returns the first available Site. |
||
110 | * |
||
111 | * @param bool $stopOnInvalidSite |
||
112 | * @return Site |
||
113 | */ |
||
114 | 20 | public function getFirstAvailableSite($stopOnInvalidSite = false) |
|
119 | |||
120 | /** |
||
121 | * Gets all available TYPO3 sites with Solr configured. |
||
122 | * |
||
123 | * @param bool $stopOnInvalidSite |
||
124 | * @return Site[] An array of available sites |
||
125 | */ |
||
126 | 70 | public function getAvailableSites($stopOnInvalidSite = false) |
|
127 | { |
||
128 | 70 | $sites = []; |
|
129 | 70 | $cacheId = 'SiteRepository' . '_' . 'getAvailableSites'; |
|
130 | |||
131 | 70 | $methodResult = $this->runtimeCache->get($cacheId); |
|
132 | 70 | if (!empty($methodResult)) { |
|
133 | 15 | return $methodResult; |
|
134 | } |
||
135 | |||
136 | 70 | $servers = $this->getSolrServersFromRegistry(); |
|
137 | 70 | foreach ($servers as $server) { |
|
138 | 70 | if (isset($sites[$server['rootPageUid']])) { |
|
139 | //get each site only once |
||
140 | 4 | continue; |
|
141 | } |
||
142 | |||
143 | try { |
||
144 | 70 | $sites[$server['rootPageUid']] = $this->buildSite($server['rootPageUid']); |
|
145 | 4 | } catch (\InvalidArgumentException $e) { |
|
146 | 4 | if ($stopOnInvalidSite) { |
|
147 | 70 | throw $e; |
|
148 | } |
||
149 | } |
||
150 | } |
||
151 | |||
152 | 70 | $methodResult = $sites; |
|
153 | 70 | $this->runtimeCache->set($cacheId, $methodResult); |
|
154 | |||
155 | 70 | return $methodResult; |
|
156 | } |
||
157 | |||
158 | /** |
||
159 | * Gets the system languages (IDs) for which Solr connections have been |
||
160 | * configured. |
||
161 | * |
||
162 | * @return array Array of system language IDs for which connections have been configured on this site. |
||
163 | */ |
||
164 | 1 | public function getAllLanguages(Site $site) |
|
179 | |||
180 | /** |
||
181 | * Creates an instance of the Site object. |
||
182 | * |
||
183 | * @param integer $rootPageId |
||
184 | * @return Site |
||
185 | */ |
||
186 | 116 | protected function buildSite($rootPageId) |
|
190 | |||
191 | /** |
||
192 | * Retrieves the configured solr servers from the registry. |
||
193 | * |
||
194 | * @return array |
||
195 | */ |
||
196 | 70 | protected function getSolrServersFromRegistry() |
|
201 | } |
||
202 |