|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Site; |
|
4
|
|
|
|
|
5
|
|
|
/*************************************************************** |
|
6
|
|
|
* Copyright notice |
|
7
|
|
|
* |
|
8
|
|
|
* (c) 2011-2015 Ingo Renner <[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\ConfigurationAwareRecordService; |
|
29
|
|
|
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException; |
|
30
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
|
31
|
|
|
use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository; |
|
32
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
33
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Base Clas for Typo3ManagedSite and LegacySite |
|
37
|
|
|
* |
|
38
|
|
|
* @package ApacheSolrForTypo3\Solr\Domain\Site |
|
39
|
|
|
*/ |
|
40
|
|
|
abstract class Site implements SiteInterface |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @var TypoScriptConfiguration |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $configuration; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Root page record. |
|
49
|
|
|
* |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $rootPage = []; |
|
53
|
|
|
/** |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $domain; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var string |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $siteHash; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @var PagesRepository |
|
65
|
|
|
*/ |
|
66
|
|
|
protected $pagesRepository; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @var int |
|
70
|
|
|
*/ |
|
71
|
|
|
protected $defaultLanguageId = 0; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @var int[] Available language ids |
|
75
|
|
|
*/ |
|
76
|
|
|
protected $availableLanguageIds = []; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Takes an pagerecord and checks whether the page is marked as root page. |
|
80
|
|
|
* |
|
81
|
|
|
* @param array $page pagerecord |
|
82
|
|
|
* @return bool true if the page is marked as root page, false otherwise |
|
83
|
|
|
* @todo: move to SiteUtility? |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function isRootPage($page) |
|
86
|
|
|
{ |
|
87
|
|
|
if ($page['is_siteroot']) { |
|
88
|
|
|
return true; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return false; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Gets the site's root page ID (uid). |
|
96
|
|
|
* |
|
97
|
|
|
* @return int The site's root page ID. |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getRootPageId() |
|
100
|
|
|
{ |
|
101
|
|
|
return (int)$this->rootPage['uid']; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Gets available language id's for this site |
|
106
|
|
|
* |
|
107
|
|
|
* @return int[] array or language id's |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getAvailableLanguageIds(): array { |
|
110
|
|
|
return $this->availableLanguageIds; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Gets the site's root page language IDs (uids). |
|
115
|
|
|
* |
|
116
|
|
|
* @return array |
|
117
|
|
|
* @deprecated use getAvailableLanguageIds() |
|
118
|
|
|
* @todo check if this method is still needed (only used in tests currently) |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getRootPageLanguageIds() : array |
|
121
|
|
|
{ |
|
122
|
|
|
trigger_error('solr:deprecation: Method getRootPageLanguageIds is deprecated since EXT:solr 10 and will be removed in v11, use getAvailableLanguageIds instead', E_USER_DEPRECATED); |
|
123
|
|
|
|
|
124
|
|
|
$rootPageLanguageIds = []; |
|
125
|
|
|
$rootPageId = $this->getRootPageId(); |
|
126
|
|
|
|
|
127
|
|
|
$rootPageOverlays = $this->pagesRepository->findTranslationOverlaysByPageId($rootPageId); |
|
128
|
|
|
if (count($rootPageOverlays)) { |
|
129
|
|
|
foreach ($rootPageOverlays as $rootPageOverlay) { |
|
130
|
|
|
$rootPageLanguageIds[] = $rootPageOverlay['sys_language_uid']; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
return $rootPageLanguageIds; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Gets the site's label. The label is build from the the site title and root |
|
138
|
|
|
* page ID (uid). |
|
139
|
|
|
* |
|
140
|
|
|
* @return string The site's label. |
|
141
|
|
|
*/ |
|
142
|
|
|
public function getLabel() |
|
143
|
|
|
{ |
|
144
|
|
|
$rootlineTitles = []; |
|
145
|
|
|
$rootLine = BackendUtility::BEgetRootLine($this->rootPage['uid']); |
|
146
|
|
|
// Remove last |
|
147
|
|
|
array_pop($rootLine); |
|
148
|
|
|
$rootLine = array_reverse($rootLine); |
|
149
|
|
|
foreach ($rootLine as $rootLineItem) { |
|
150
|
|
|
$rootlineTitles[] = $rootLineItem['title']; |
|
151
|
|
|
} |
|
152
|
|
|
return implode(' - ', $rootlineTitles) . ', Root Page ID: ' . $this->rootPage['uid']; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Gets the site's Solr TypoScript configuration (plugin.tx_solr.*) |
|
157
|
|
|
* |
|
158
|
|
|
* @return \ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration The Solr TypoScript configuration |
|
159
|
|
|
*/ |
|
160
|
|
|
public function getSolrConfiguration() |
|
161
|
|
|
{ |
|
162
|
|
|
return $this->configuration; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Gets the site's default language as configured in |
|
167
|
|
|
* config.sys_language_uid. If sys_language_uid is not set, 0 is assumed to |
|
168
|
|
|
* be the default. |
|
169
|
|
|
* |
|
170
|
|
|
* @return int The site's default language. |
|
171
|
|
|
*/ |
|
172
|
|
|
public function getDefaultLanguage() |
|
173
|
|
|
{ |
|
174
|
|
|
return $this->defaultLanguageId; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Generates a list of page IDs in this site. Attention, this includes |
|
179
|
|
|
* all page types! Deleted pages are not included. |
|
180
|
|
|
* |
|
181
|
|
|
* @param int|string $rootPageId Page ID from where to start collection sub pages |
|
182
|
|
|
* @param int $maxDepth Maximum depth to descend into the site tree |
|
183
|
|
|
* @return array Array of pages (IDs) in this site |
|
184
|
|
|
*/ |
|
185
|
|
|
public function getPages($rootPageId = 'SITE_ROOT', $maxDepth = 999) |
|
186
|
|
|
{ |
|
187
|
|
|
$pageIds = []; |
|
188
|
|
|
if ($rootPageId === 'SITE_ROOT') { |
|
189
|
|
|
$rootPageId = (int)$this->rootPage['uid']; |
|
190
|
|
|
$pageIds[] = $rootPageId; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
$configurationAwareRecordService = GeneralUtility::makeInstance(ConfigurationAwareRecordService::class); |
|
194
|
|
|
// Fetch configuration in order to be able to read initialPagesAdditionalWhereClause |
|
195
|
|
|
$solrConfiguration = $this->getSolrConfiguration(); |
|
196
|
|
|
$indexQueueConfigurationName = $configurationAwareRecordService->getIndexingConfigurationName('pages', $this->rootPage['uid'], $solrConfiguration); |
|
197
|
|
|
$initialPagesAdditionalWhereClause = $solrConfiguration->getInitialPagesAdditionalWhereClause($indexQueueConfigurationName); |
|
198
|
|
|
|
|
199
|
|
|
return array_merge($pageIds, $this->pagesRepository->findAllSubPageIdsByRootPage($rootPageId, $maxDepth, $initialPagesAdditionalWhereClause)); |
|
|
|
|
|
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Generates the site's unique Site Hash. |
|
205
|
|
|
* |
|
206
|
|
|
* The Site Hash is build from the site's main domain, the system encryption |
|
207
|
|
|
* key, and the extension "tx_solr". These components are concatenated and |
|
208
|
|
|
* sha1-hashed. |
|
209
|
|
|
* |
|
210
|
|
|
* @return string Site Hash. |
|
211
|
|
|
*/ |
|
212
|
|
|
public function getSiteHash() |
|
213
|
|
|
{ |
|
214
|
|
|
return $this->siteHash; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* Gets the site's main domain. More specifically the first domain record in |
|
219
|
|
|
* the site tree. |
|
220
|
|
|
* |
|
221
|
|
|
* @return string The site's main domain. |
|
222
|
|
|
*/ |
|
223
|
|
|
public function getDomain() |
|
224
|
|
|
{ |
|
225
|
|
|
return $this->domain; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Gets the site's root page. |
|
230
|
|
|
* |
|
231
|
|
|
* @return array The site's root page. |
|
232
|
|
|
*/ |
|
233
|
|
|
public function getRootPage() |
|
234
|
|
|
{ |
|
235
|
|
|
return $this->rootPage; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* Gets the site's root page's title. |
|
240
|
|
|
* |
|
241
|
|
|
* @return string The site's root page's title |
|
242
|
|
|
*/ |
|
243
|
|
|
public function getTitle() |
|
244
|
|
|
{ |
|
245
|
|
|
return $this->rootPage['title']; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Retrieves the rootPageIds as an array from a set of sites. |
|
250
|
|
|
* |
|
251
|
|
|
* @param array $sites |
|
252
|
|
|
* @return array |
|
253
|
|
|
* @todo: move to SiteUtility? |
|
254
|
|
|
*/ |
|
255
|
|
|
public static function getRootPageIdsFromSites(array $sites): array |
|
256
|
|
|
{ |
|
257
|
|
|
$rootPageIds = []; |
|
258
|
|
|
foreach ($sites as $site) { |
|
259
|
|
|
$rootPageIds[] = (int)$site->getRootPageId(); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
return $rootPageIds; |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* @return array |
|
267
|
|
|
* @throws NoSolrConnectionFoundException |
|
268
|
|
|
*/ |
|
269
|
|
|
public function getAllSolrConnectionConfigurations(): array { |
|
270
|
|
|
$configs = []; |
|
271
|
|
|
foreach ($this->getAvailableLanguageIds() as $languageId) { |
|
272
|
|
|
try { |
|
273
|
|
|
$configs[$languageId] = $this->getSolrConnectionConfiguration($languageId); |
|
274
|
|
|
} catch (NoSolrConnectionFoundException $e) {} |
|
|
|
|
|
|
275
|
|
|
} |
|
276
|
|
|
return $configs; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* @param int $languageId |
|
281
|
|
|
* @return array |
|
282
|
|
|
*/ |
|
283
|
|
|
abstract function getSolrConnectionConfiguration(int $language = 0): array; |
|
284
|
|
|
} |