|
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 3 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\ConnectionManager; |
|
28
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\Queue; |
|
29
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection; |
|
30
|
|
|
use ApacheSolrForTypo3\Solr\Util; |
|
31
|
|
|
use TYPO3\CMS\Backend\Routing\UriBuilder as BackendUriBuilder; |
|
32
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
|
33
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
34
|
|
|
use TYPO3\CMS\Extbase\Mvc\Web\ReferringRequest; |
|
35
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Index Administration Module |
|
39
|
|
|
* |
|
40
|
|
|
* @author Ingo Renner <[email protected]> |
|
41
|
|
|
*/ |
|
42
|
|
|
class IndexAdministrationModuleController extends AbstractModuleController |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var Queue |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $indexQueue; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var ConnectionManager |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $solrConnectionManager = null; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param ConnectionManager $solrConnectionManager |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setSolrConnectionManager(ConnectionManager $solrConnectionManager) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->solrConnectionManager = $solrConnectionManager; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Initializes the controller before invoking an action method. |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function initializeAction() |
|
67
|
|
|
{ |
|
68
|
|
|
parent::initializeAction(); |
|
69
|
|
|
$this->indexQueue = GeneralUtility::makeInstance(Queue::class); |
|
70
|
|
|
$this->solrConnectionManager = GeneralUtility::makeInstance(ConnectionManager::class); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Index action, shows an overview of available index maintenance operations. |
|
75
|
|
|
* |
|
76
|
|
|
* @return void |
|
77
|
|
|
*/ |
|
78
|
|
|
public function indexAction() |
|
79
|
|
|
{ |
|
80
|
|
|
if ($this->selectedSite === null || empty($this->solrConnectionManager->getConnectionsBySite($this->selectedSite))) { |
|
81
|
|
|
$this->view->assign('can_not_proceed', true); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Empties the site's indexes. |
|
87
|
|
|
* |
|
88
|
|
|
* @return void |
|
89
|
|
|
*/ |
|
90
|
|
|
public function emptyIndexAction() |
|
91
|
|
|
{ |
|
92
|
|
|
$siteHash = $this->selectedSite->getSiteHash(); |
|
93
|
|
|
|
|
94
|
|
|
try { |
|
95
|
|
|
$affectedCores = []; |
|
96
|
|
|
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
|
97
|
|
|
foreach ($solrServers as $solrServer) { |
|
98
|
|
|
$writeService = $solrServer->getWriteService(); |
|
99
|
|
|
/* @var $solrServer SolrConnection */ |
|
100
|
|
|
$writeService->deleteByQuery('siteHash:' . $siteHash); |
|
101
|
|
|
$writeService->commit(false, false, false); |
|
|
|
|
|
|
102
|
|
|
$affectedCores[] = $writeService->getPrimaryEndpoint()->getCore(); |
|
103
|
|
|
} |
|
104
|
|
|
$message = LocalizationUtility::translate('solr.backend.index_administration.index_emptied_all', 'Solr', [$this->selectedSite->getLabel(), implode(', ', $affectedCores)]); |
|
105
|
|
|
$this->addFlashMessage($message); |
|
106
|
|
|
} catch (\Exception $e) { |
|
107
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('solr.backend.index_administration.error.on_empty_index', 'Solr', [$e->__toString()]), '', FlashMessage::ERROR); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$this->redirect('index'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Empties the Index Queue |
|
115
|
|
|
* |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
|
|
public function clearIndexQueueAction() |
|
119
|
|
|
{ |
|
120
|
|
|
$this->indexQueue->deleteItemsBySite($this->selectedSite); |
|
121
|
|
|
$this->addFlashMessage( |
|
122
|
|
|
LocalizationUtility::translate('solr.backend.index_administration.success.queue_emptied', 'Solr', |
|
123
|
|
|
[$this->selectedSite->getLabel()]) |
|
124
|
|
|
); |
|
125
|
|
|
$this->redirectToReferrerModule(); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Reloads the site's Solr cores. |
|
130
|
|
|
* |
|
131
|
|
|
* @return void |
|
132
|
|
|
*/ |
|
133
|
|
|
public function reloadIndexConfigurationAction() |
|
134
|
|
|
{ |
|
135
|
|
|
$coresReloaded = true; |
|
136
|
|
|
$reloadedCores = []; |
|
137
|
|
|
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
|
138
|
|
|
|
|
139
|
|
|
foreach ($solrServers as $solrServer) { |
|
140
|
|
|
/* @var $solrServer SolrConnection */ |
|
141
|
|
|
$coreAdmin = $solrServer->getAdminService(); |
|
142
|
|
|
$coreReloaded = $coreAdmin->reloadCore()->getHttpStatus() === 200; |
|
143
|
|
|
|
|
144
|
|
|
$coreName = $coreAdmin->getPrimaryEndpoint()->getCore(); |
|
145
|
|
|
if (!$coreReloaded) { |
|
146
|
|
|
$coresReloaded = false; |
|
147
|
|
|
|
|
148
|
|
|
$this->addFlashMessage( |
|
149
|
|
|
'Failed to reload index configuration for core "' . $coreName . '"', |
|
150
|
|
|
'', |
|
151
|
|
|
FlashMessage::ERROR |
|
152
|
|
|
); |
|
153
|
|
|
break; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
$reloadedCores[] = $coreName; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
if ($coresReloaded) { |
|
160
|
|
|
$this->addFlashMessage( |
|
161
|
|
|
'Core configuration reloaded (' . implode(', ', $reloadedCores) . ').', |
|
162
|
|
|
'', |
|
163
|
|
|
FlashMessage::OK |
|
164
|
|
|
); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
$this->redirect('index'); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Redirects to the referrer module index Action. |
|
172
|
|
|
* |
|
173
|
|
|
* Fluids <f:form VH can not make urls to other modules properly. |
|
174
|
|
|
* The module name/key is not provided in the hidden fields __referrer by bulding form. |
|
175
|
|
|
* So this is currently the single way to make it possible. |
|
176
|
|
|
* |
|
177
|
|
|
* @todo: remove this method if f:form works properly between backend modules. |
|
178
|
|
|
*/ |
|
179
|
|
|
protected function redirectToReferrerModule() |
|
180
|
|
|
{ |
|
181
|
|
|
$wasFromQueue = $this->request->hasArgument('fromQueue'); |
|
182
|
|
|
if (!$wasFromQueue) { |
|
183
|
|
|
$this->redirect('index'); |
|
184
|
|
|
return; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/* @var BackendUriBuilder $backendUriBuilder */ |
|
188
|
|
|
$backendUriBuilder = GeneralUtility::makeInstance(BackendUriBuilder::class); |
|
189
|
|
|
|
|
190
|
|
|
$parameters = ['id' => $this->selectedPageUID]; |
|
191
|
|
|
$referringUri = $backendUriBuilder->buildUriFromRoute('searchbackend_SolrIndexqueue', $parameters); |
|
192
|
|
|
|
|
193
|
|
|
$this->redirectToUri($referringUri); |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
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