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\Service\ConfigurationService; |
24
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager as SolrConfigurationManager; |
25
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
26
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; |
27
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
28
|
|
|
use TYPO3\CMS\Extbase\Service\TypoScriptService; |
29
|
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; |
30
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class AbstractBaseController |
34
|
|
|
* |
35
|
|
|
* @author Frans Saris <[email protected]> |
36
|
|
|
* @author Timo Hund <[email protected]> |
37
|
|
|
* @package ApacheSolrForTypo3\Solr\Controller |
38
|
|
|
*/ |
39
|
|
|
abstract class AbstractBaseController extends ActionController |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @var ContentObjectRenderer |
43
|
|
|
*/ |
44
|
|
|
private $contentObjectRenderer; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var TypoScriptFrontendController |
48
|
|
|
*/ |
49
|
|
|
protected $typoScriptFrontendController; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface |
53
|
|
|
*/ |
54
|
|
|
protected $configurationManager; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var SolrConfigurationManager |
58
|
|
|
*/ |
59
|
|
|
private $solrConfigurationManager; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The configuration is private if you need it please get it from the controllerContext. |
63
|
|
|
* |
64
|
|
|
* @var TypoScriptConfiguration |
65
|
|
|
*/ |
66
|
|
|
protected $typoScriptConfiguration; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext |
70
|
|
|
*/ |
71
|
|
|
protected $controllerContext; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var \ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService |
75
|
|
|
*/ |
76
|
|
|
protected $searchService; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var \ApacheSolrForTypo3\Solr\Domain\Search\SearchRequestBuilder |
80
|
|
|
*/ |
81
|
|
|
protected $searchRequestBuilder; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var bool |
85
|
|
|
*/ |
86
|
34 |
|
protected $resetConfigurationBeforeInitialize = true; |
87
|
|
|
|
88
|
34 |
|
/** |
89
|
34 |
|
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager |
90
|
34 |
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) |
93
|
|
|
{ |
94
|
|
|
$this->configurationManager = $configurationManager; |
95
|
1 |
|
$this->contentObjectRenderer = $this->configurationManager->getContentObject(); |
96
|
|
|
} |
97
|
1 |
|
|
98
|
1 |
|
/** |
99
|
|
|
* @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer |
100
|
|
|
*/ |
101
|
|
|
public function setContentObjectRenderer($contentObjectRenderer) |
102
|
|
|
{ |
103
|
|
|
$this->contentObjectRenderer = $contentObjectRenderer; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer |
108
|
|
|
*/ |
109
|
|
|
public function getContentObjectRenderer() |
110
|
|
|
{ |
111
|
34 |
|
return $this->contentObjectRenderer; |
112
|
|
|
} |
113
|
34 |
|
|
114
|
34 |
|
/** |
115
|
|
|
* @param SolrConfigurationManager $configurationManager |
116
|
|
|
*/ |
117
|
|
|
public function injectSolrConfigurationManager(SolrConfigurationManager $configurationManager) |
118
|
|
|
{ |
119
|
17 |
|
$this->solrConfigurationManager = $configurationManager; |
120
|
|
|
} |
121
|
17 |
|
|
122
|
17 |
|
/** |
123
|
|
|
* @param boolean $resetConfigurationBeforeInitialize |
124
|
|
|
*/ |
125
|
|
|
public function setResetConfigurationBeforeInitialize($resetConfigurationBeforeInitialize) |
126
|
|
|
{ |
127
|
|
|
$this->resetConfigurationBeforeInitialize = $resetConfigurationBeforeInitialize; |
128
|
|
|
} |
129
|
|
|
|
130
|
34 |
|
/** |
131
|
|
|
* Initialize the controller context |
132
|
|
|
* |
133
|
34 |
|
* @return \TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext ControllerContext to be passed to the view |
134
|
34 |
|
* @api |
135
|
34 |
|
*/ |
136
|
34 |
|
protected function buildControllerContext() |
137
|
34 |
|
{ |
138
|
|
|
/** @var $controllerContext \ApacheSolrForTypo3\Solr\Mvc\Controller\SolrControllerContext */ |
139
|
34 |
|
$controllerContext = $this->objectManager->get(SolrControllerContext::class); |
140
|
|
|
$controllerContext->setRequest($this->request); |
141
|
34 |
|
$controllerContext->setResponse($this->response); |
142
|
|
|
if ($this->arguments !== null) { |
143
|
34 |
|
$controllerContext->setArguments($this->arguments); |
144
|
|
|
} |
145
|
|
|
$controllerContext->setUriBuilder($this->uriBuilder); |
146
|
|
|
|
147
|
|
|
$controllerContext->setTypoScriptConfiguration($this->typoScriptConfiguration); |
148
|
|
|
|
149
|
34 |
|
return $controllerContext; |
150
|
|
|
} |
151
|
|
|
|
152
|
34 |
|
/** |
153
|
17 |
|
* Initialize action |
154
|
|
|
*/ |
155
|
|
|
protected function initializeAction() |
156
|
34 |
|
{ |
157
|
|
|
// Reset configuration (to reset flexform overrides) if resetting is enabled |
158
|
|
|
if ($this->resetConfigurationBeforeInitialize) { |
159
|
34 |
|
$this->solrConfigurationManager->reset(); |
160
|
34 |
|
} |
161
|
34 |
|
/** @var TypoScriptService $typoScriptService */ |
162
|
34 |
|
$typoScriptService = $this->objectManager->get(TypoScriptService::class); |
163
|
34 |
|
|
164
|
|
|
// Merge settings done by typoscript with solrConfiguration plugin.tx_solr (obsolete when part of ext:solr) |
165
|
|
|
$frameWorkConfiguration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); |
166
|
|
|
$pluginSettings = []; |
167
|
34 |
|
foreach (['search', 'settings', 'suggest', 'statistics', 'logging', 'general', 'solr', 'view'] as $key) { |
168
|
34 |
|
if (isset($frameWorkConfiguration[$key])) { |
169
|
2 |
|
$pluginSettings[$key] = $frameWorkConfiguration[$key]; |
170
|
2 |
|
} |
171
|
2 |
|
} |
172
|
2 |
|
|
173
|
|
|
$this->typoScriptConfiguration = $this->solrConfigurationManager->getTypoScriptConfiguration(); |
174
|
|
|
if ($pluginSettings !== []) { |
175
|
|
|
$this->typoScriptConfiguration->mergeSolrConfiguration( |
176
|
34 |
|
$typoScriptService->convertPlainArrayToTypoScriptArray($pluginSettings), |
177
|
34 |
|
true, |
178
|
34 |
|
false |
179
|
34 |
|
); |
180
|
|
|
} |
181
|
|
|
|
182
|
34 |
|
$this->objectManager->get(ConfigurationService::class) |
183
|
34 |
|
->overrideConfigurationWithFlexFormSettings( |
184
|
34 |
|
$this->contentObjectRenderer->data['pi_flexform'], |
185
|
34 |
|
$this->typoScriptConfiguration |
186
|
34 |
|
); |
187
|
|
|
|
188
|
|
|
parent::initializeAction(); |
189
|
|
|
$this->typoScriptFrontendController = $GLOBALS['TSFE']; |
190
|
|
|
$this->initializeSettings(); |
191
|
|
|
$this->initializeSearch(); |
192
|
|
|
} |
193
|
34 |
|
|
194
|
|
|
/** |
195
|
|
|
* Inject settings of plugin.tx_solr |
196
|
34 |
|
* |
197
|
|
|
* @return void |
198
|
|
|
*/ |
199
|
34 |
|
protected function initializeSettings() |
200
|
34 |
|
{ |
201
|
|
|
/** @var $typoScriptService TypoScriptService */ |
202
|
34 |
|
$typoScriptService = $this->objectManager->get(TypoScriptService::class); |
203
|
|
|
|
204
|
|
|
// Make sure plugin.tx_solr.settings are available in the view as {settings} |
205
|
|
|
$this->settings = $typoScriptService->convertTypoScriptArrayToPlainArray( |
206
|
|
|
$this->typoScriptConfiguration->getObjectByPathOrDefault('plugin.tx_solr.settings.', []) |
207
|
|
|
); |
208
|
34 |
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
34 |
|
* Initialize the Solr connection and |
212
|
34 |
|
* test the connection through a ping |
213
|
|
|
*/ |
214
|
34 |
|
protected function initializeSearch() |
215
|
34 |
|
{ |
216
|
|
|
/** @var \ApacheSolrForTypo3\Solr\ConnectionManager $solrConnection */ |
217
|
|
|
$solrConnection = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId($this->typoScriptFrontendController->id, $this->typoScriptFrontendController->sys_language_uid, $this->typoScriptFrontendController->MP); |
218
|
|
|
$search = GeneralUtility::makeInstance(Search::class, $solrConnection); |
219
|
|
|
|
220
|
|
|
$this->searchService = GeneralUtility::makeInstance(SearchResultSetService::class, $this->typoScriptConfiguration, $search); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @return SearchRequestBuilder |
225
|
|
|
*/ |
226
|
|
|
protected function getSearchRequestBuilder() |
227
|
|
|
{ |
228
|
|
|
if ($this->searchRequestBuilder === null) { |
229
|
|
|
$this->searchRequestBuilder = GeneralUtility::makeInstance(SearchRequestBuilder::class, $this->typoScriptConfiguration); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
return $this->searchRequestBuilder; |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|