1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Controller\Backend\Search; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2013-2015 Ingo Renner <[email protected]> |
8
|
|
|
* All rights reserved |
9
|
|
|
* |
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
11
|
|
|
* free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* The GNU General Public License can be found at |
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
18
|
|
|
* |
19
|
|
|
* This script is distributed in the hope that it will be useful, |
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
|
|
|
* GNU General Public License for more details. |
23
|
|
|
* |
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
25
|
|
|
***************************************************************/ |
26
|
|
|
|
27
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\Queue; |
28
|
|
|
use ApacheSolrForTypo3\Solr\SolrService; |
29
|
|
|
use TYPO3\CMS\Backend\Routing\UriBuilder as BackendUriBuilder; |
30
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
31
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
32
|
|
|
use TYPO3\CMS\Extbase\Mvc\Web\ReferringRequest; |
33
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Index Administration Module |
37
|
|
|
* |
38
|
|
|
* @author Ingo Renner <[email protected]> |
39
|
|
|
*/ |
40
|
|
|
class IndexAdministrationModuleController extends AbstractModuleController |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var Queue |
45
|
|
|
*/ |
46
|
|
|
protected $indexQueue; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var \ApacheSolrForTypo3\Solr\ConnectionManager |
50
|
|
|
* @inject |
51
|
|
|
*/ |
52
|
|
|
protected $solrConnectionManager = null; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Initializes the controller before invoking an action method. |
56
|
|
|
*/ |
57
|
|
|
protected function initializeAction() |
58
|
|
|
{ |
59
|
|
|
parent::initializeAction(); |
60
|
|
|
$this->indexQueue = GeneralUtility::makeInstance(Queue::class); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Index action, shows an overview of available index maintenance operations. |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
|
|
public function indexAction() |
69
|
|
|
{ |
70
|
|
|
if ($this->selectedSite === null) { |
71
|
|
|
$this->view->assignMultiple([ |
72
|
|
|
'can_not_proceed' => true, |
73
|
|
|
'pageUID' => $this->selectedPageUID |
74
|
|
|
]); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Empties the site's indexes. |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function emptyIndexAction() |
84
|
|
|
{ |
85
|
|
|
$siteHash = $this->selectedSite->getSiteHash(); |
86
|
|
|
|
87
|
|
|
try { |
88
|
|
|
$affectedCores = []; |
89
|
|
|
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
90
|
|
|
foreach ($solrServers as $solrServer) { |
91
|
|
|
/* @var $solrServer SolrService */ |
92
|
|
|
$solrServer->deleteByQuery('siteHash:' . $siteHash); |
93
|
|
|
$solrServer->commit(false, false, false); |
94
|
|
|
$affectedCores[] = $solrServer->getCoreName(); |
95
|
|
|
} |
96
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('solr.backend.index_administration.index_emptied_all', 'Solr', [$this->selectedSite->getLabel(), implode(', ', $affectedCores)])); |
97
|
|
|
} catch (\Exception $e) { |
98
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('solr.backend.index_administration.error.on_empty_index', 'Solr', [$e->__toString()]), '', FlashMessage::ERROR); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$this->redirect('index'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Empties the Index Queue |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
|
|
public function clearIndexQueueAction() |
110
|
|
|
{ |
111
|
|
|
$this->indexQueue->deleteItemsBySite($this->selectedSite); |
112
|
|
|
$this->addFlashMessage( |
113
|
|
|
LocalizationUtility::translate('solr.backend.index_administration.success.queue_emptied', 'Solr', |
114
|
|
|
[$this->selectedSite->getLabel()]) |
115
|
|
|
); |
116
|
|
|
$this->redirectToReferrerModule(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Reloads the site's Solr cores. |
121
|
|
|
* |
122
|
|
|
* @return void |
123
|
|
|
*/ |
124
|
|
|
public function reloadIndexConfigurationAction() |
125
|
|
|
{ |
126
|
|
|
$coresReloaded = true; |
127
|
|
|
$reloadedCores = []; |
128
|
|
|
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
129
|
|
|
|
130
|
|
|
foreach ($solrServers as $solrServer) { |
131
|
|
|
/* @var $solrServer SolrService */ |
132
|
|
|
$coreReloaded = $solrServer->reloadCore()->getHttpStatus() === 200; |
133
|
|
|
$coreName = $solrServer->getCoreName(); |
134
|
|
|
|
135
|
|
|
if (!$coreReloaded) { |
136
|
|
|
$coresReloaded = false; |
137
|
|
|
|
138
|
|
|
$this->addFlashMessage( |
139
|
|
|
'Failed to reload index configuration for core "' . $coreName . '"', |
140
|
|
|
'', |
141
|
|
|
FlashMessage::ERROR |
142
|
|
|
); |
143
|
|
|
break; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$reloadedCores[] = $coreName; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
if ($coresReloaded) { |
150
|
|
|
$this->addFlashMessage( |
151
|
|
|
'Core configuration reloaded ('.implode(', ', $reloadedCores).').', |
152
|
|
|
'', |
153
|
|
|
FlashMessage::OK |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$this->redirect('index'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Redirects to the referrer module index Action. |
162
|
|
|
* |
163
|
|
|
* Fluids <f:form VH can not make urls to other modules properly. |
164
|
|
|
* The module name/key is not provided in the hidden fields __referrer by bulding form. |
165
|
|
|
* So this is currently the single way to make it possible. |
166
|
|
|
* |
167
|
|
|
* @todo: remove this method if f:form works properly between backend modules. |
168
|
|
|
*/ |
169
|
|
|
protected function redirectToReferrerModule() |
170
|
|
|
{ |
171
|
|
|
/* @var ReferringRequest $referringRequest */ |
172
|
|
|
$referringRequest = $this->request->getReferringRequest(); |
|
|
|
|
173
|
|
|
$controllerName = $this->request->getControllerName(); |
174
|
|
|
$referrerControllerName = $referringRequest->getControllerName(); |
175
|
|
|
if ($controllerName === $referrerControllerName) { |
176
|
|
|
$this->redirect('index'); |
177
|
|
|
return; |
178
|
|
|
} |
179
|
|
|
/* @var BackendUriBuilder $backendUriBuilder */ |
180
|
|
|
$backendUriBuilder = GeneralUtility::makeInstance(BackendUriBuilder::class); |
181
|
|
|
$referrerUriFromBackendUriBuilder = $backendUriBuilder->buildUriFromModule( |
182
|
|
|
'searchbackend_SolrIndexqueue', |
183
|
|
|
[ |
184
|
|
|
'id' => $this->selectedPageUID |
185
|
|
|
] |
186
|
|
|
); |
187
|
|
|
$this->redirectToUri($referrerUriFromBackendUriBuilder); |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: