|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Controller; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the TYPO3 CMS project. |
|
6
|
|
|
* |
|
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
9
|
|
|
* of the License, or any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
* |
|
14
|
|
|
* The TYPO3 project - inspiring people to share! |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
use ApacheSolrForTypo3\Solr\ConnectionManager; |
|
18
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService; |
|
19
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequestBuilder; |
|
20
|
|
|
use ApacheSolrForTypo3\Solr\Search; |
|
21
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
|
22
|
|
|
use ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext; |
|
23
|
|
|
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; |
|
24
|
|
|
use ApacheSolrForTypo3\Solr\System\Service\ConfigurationService; |
|
25
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager as SolrConfigurationManager; |
|
26
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
27
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; |
|
28
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
|
29
|
|
|
use TYPO3\CMS\Extbase\Service\TypoScriptService; |
|
|
|
|
|
|
30
|
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; |
|
31
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Class AbstractBaseController |
|
35
|
|
|
* |
|
36
|
|
|
* @author Frans Saris <[email protected]> |
|
37
|
|
|
* @author Timo Hund <[email protected]> |
|
38
|
|
|
* @package ApacheSolrForTypo3\Solr\Controller |
|
39
|
|
|
*/ |
|
40
|
|
|
abstract class AbstractBaseController extends ActionController |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @var ContentObjectRenderer |
|
44
|
|
|
*/ |
|
45
|
|
|
private $contentObjectRenderer; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var TypoScriptFrontendController |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $typoScriptFrontendController; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $configurationManager; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var SolrConfigurationManager |
|
59
|
|
|
*/ |
|
60
|
|
|
private $solrConfigurationManager; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* The configuration is private if you need it please get it from the controllerContext. |
|
64
|
|
|
* |
|
65
|
|
|
* @var TypoScriptConfiguration |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $typoScriptConfiguration; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $controllerContext; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var \ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $searchService; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @var \ApacheSolrForTypo3\Solr\Domain\Search\SearchRequestBuilder |
|
81
|
|
|
*/ |
|
82
|
|
|
protected $searchRequestBuilder; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @var bool |
|
86
|
|
|
*/ |
|
87
|
|
|
protected $resetConfigurationBeforeInitialize = true; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager |
|
91
|
|
|
* @return void |
|
92
|
|
|
*/ |
|
93
|
41 |
|
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) |
|
94
|
|
|
{ |
|
95
|
41 |
|
$this->configurationManager = $configurationManager; |
|
96
|
41 |
|
$this->contentObjectRenderer = $this->configurationManager->getContentObject(); |
|
97
|
41 |
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer |
|
101
|
|
|
*/ |
|
102
|
1 |
|
public function setContentObjectRenderer($contentObjectRenderer) |
|
103
|
|
|
{ |
|
104
|
1 |
|
$this->contentObjectRenderer = $contentObjectRenderer; |
|
105
|
1 |
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getContentObjectRenderer() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->contentObjectRenderer; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param SolrConfigurationManager $configurationManager |
|
117
|
|
|
*/ |
|
118
|
41 |
|
public function injectSolrConfigurationManager(SolrConfigurationManager $configurationManager) |
|
119
|
|
|
{ |
|
120
|
41 |
|
$this->solrConfigurationManager = $configurationManager; |
|
121
|
41 |
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param boolean $resetConfigurationBeforeInitialize |
|
125
|
|
|
*/ |
|
126
|
22 |
|
public function setResetConfigurationBeforeInitialize($resetConfigurationBeforeInitialize) |
|
127
|
|
|
{ |
|
128
|
22 |
|
$this->resetConfigurationBeforeInitialize = $resetConfigurationBeforeInitialize; |
|
129
|
22 |
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Initialize the controller context |
|
133
|
|
|
* |
|
134
|
|
|
* @return \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext ControllerContext to be passed to the view |
|
135
|
|
|
* @api |
|
136
|
|
|
*/ |
|
137
|
41 |
|
protected function buildControllerContext() |
|
138
|
|
|
{ |
|
139
|
|
|
/** @var $controllerContext \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext */ |
|
140
|
41 |
|
$controllerContext = $this->objectManager->get(SolrControllerContext::class); |
|
141
|
41 |
|
$controllerContext->setRequest($this->request); |
|
142
|
41 |
|
$controllerContext->setResponse($this->response); |
|
143
|
41 |
|
if ($this->arguments !== null) { |
|
144
|
41 |
|
$controllerContext->setArguments($this->arguments); |
|
145
|
|
|
} |
|
146
|
41 |
|
$controllerContext->setUriBuilder($this->uriBuilder); |
|
147
|
|
|
|
|
148
|
41 |
|
$controllerContext->setTypoScriptConfiguration($this->typoScriptConfiguration); |
|
149
|
|
|
|
|
150
|
41 |
|
return $controllerContext; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Initialize action |
|
155
|
|
|
*/ |
|
156
|
41 |
|
protected function initializeAction() |
|
157
|
|
|
{ |
|
158
|
|
|
// Reset configuration (to reset flexform overrides) if resetting is enabled |
|
159
|
41 |
|
if ($this->resetConfigurationBeforeInitialize) { |
|
160
|
19 |
|
$this->solrConfigurationManager->reset(); |
|
161
|
|
|
} |
|
162
|
|
|
/** @var TypoScriptService $typoScriptService */ |
|
163
|
41 |
|
$typoScriptService = $this->objectManager->get(TypoScriptService::class); |
|
164
|
|
|
|
|
165
|
|
|
// Merge settings done by typoscript with solrConfiguration plugin.tx_solr (obsolete when part of ext:solr) |
|
166
|
41 |
|
$frameWorkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); |
|
167
|
41 |
|
$pluginSettings = []; |
|
168
|
41 |
|
foreach (['search', 'settings', 'suggest', 'statistics', 'logging', 'general', 'solr', 'view'] as $key) { |
|
169
|
41 |
|
if (isset($frameWorkConfiguration[$key])) { |
|
170
|
41 |
|
$pluginSettings[$key] = $frameWorkConfiguration[$key]; |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
41 |
|
$this->typoScriptConfiguration = $this->solrConfigurationManager->getTypoScriptConfiguration(); |
|
175
|
41 |
|
if ($pluginSettings !== []) { |
|
176
|
|
|
$this->typoScriptConfiguration->mergeSolrConfiguration( |
|
177
|
|
|
$typoScriptService->convertPlainArrayToTypoScriptArray($pluginSettings), |
|
178
|
|
|
true, |
|
179
|
|
|
false |
|
180
|
|
|
); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
41 |
|
$this->objectManager->get(ConfigurationService::class) |
|
184
|
41 |
|
->overrideConfigurationWithFlexFormSettings( |
|
185
|
41 |
|
$this->contentObjectRenderer->data['pi_flexform'], |
|
186
|
41 |
|
$this->typoScriptConfiguration |
|
187
|
|
|
); |
|
188
|
|
|
|
|
189
|
41 |
|
parent::initializeAction(); |
|
190
|
41 |
|
$this->typoScriptFrontendController = $GLOBALS['TSFE']; |
|
191
|
41 |
|
$this->initializeSettings(); |
|
192
|
41 |
|
$this->initializeSearch(); |
|
193
|
41 |
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Inject settings of plugin.tx_solr |
|
197
|
|
|
* |
|
198
|
|
|
* @return void |
|
199
|
|
|
*/ |
|
200
|
41 |
|
protected function initializeSettings() |
|
201
|
|
|
{ |
|
202
|
|
|
/** @var $typoScriptService TypoScriptService */ |
|
203
|
41 |
|
$typoScriptService = $this->objectManager->get(TypoScriptService::class); |
|
204
|
|
|
|
|
205
|
|
|
// Make sure plugin.tx_solr.settings are available in the view as {settings} |
|
206
|
41 |
|
$this->settings = $typoScriptService->convertTypoScriptArrayToPlainArray( |
|
207
|
41 |
|
$this->typoScriptConfiguration->getObjectByPathOrDefault('plugin.tx_solr.settings.', []) |
|
208
|
|
|
); |
|
209
|
41 |
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Initialize the Solr connection and |
|
213
|
|
|
* test the connection through a ping |
|
214
|
|
|
*/ |
|
215
|
41 |
|
protected function initializeSearch() |
|
216
|
|
|
{ |
|
217
|
|
|
/** @var \ApacheSolrForTypo3\Solr\ConnectionManager $solrConnection */ |
|
218
|
41 |
|
$solrConnection = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId($this->typoScriptFrontendController->id, $this->typoScriptFrontendController->sys_language_uid, $this->typoScriptFrontendController->MP); |
|
219
|
41 |
|
$search = GeneralUtility::makeInstance(Search::class, $solrConnection); |
|
|
|
|
|
|
220
|
|
|
|
|
221
|
41 |
|
$this->searchService = GeneralUtility::makeInstance(SearchResultSetService::class, $this->typoScriptConfiguration, $search); |
|
|
|
|
|
|
222
|
41 |
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @return SearchRequestBuilder |
|
226
|
|
|
*/ |
|
227
|
36 |
|
protected function getSearchRequestBuilder() |
|
228
|
|
|
{ |
|
229
|
36 |
|
if ($this->searchRequestBuilder === null) { |
|
230
|
36 |
|
$this->searchRequestBuilder = GeneralUtility::makeInstance(SearchRequestBuilder::class, $this->typoScriptConfiguration); |
|
|
|
|
|
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
36 |
|
return $this->searchRequestBuilder; |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
/** |
|
237
|
|
|
* Called when the solr server is unavailable. |
|
238
|
|
|
* |
|
239
|
|
|
* @return void |
|
240
|
|
|
*/ |
|
241
|
2 |
|
protected function handleSolrUnavailable() |
|
242
|
|
|
{ |
|
243
|
2 |
|
if ($this->typoScriptConfiguration->getLoggingExceptions()) { |
|
244
|
|
|
/** @var SolrLogManager $logger */ |
|
245
|
2 |
|
$logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__); |
|
|
|
|
|
|
246
|
2 |
|
$logger->log(SolrLogManager::ERROR, 'Solr server is not available'); |
|
247
|
|
|
} |
|
248
|
2 |
|
} |
|
249
|
|
|
} |
|
250
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths