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