|
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\Core\Messaging\FlashMessage; |
|
30
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
31
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Index Administration Module |
|
35
|
|
|
* |
|
36
|
|
|
* @author Ingo Renner <[email protected]> |
|
37
|
|
|
*/ |
|
38
|
|
|
class IndexAdministrationModuleController extends AbstractModuleController |
|
39
|
|
|
{ |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var Queue |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $indexQueue; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var \ApacheSolrForTypo3\Solr\ConnectionManager |
|
48
|
|
|
* @inject |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $solrConnectionManager = null; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Initializes the controller before invoking an action method. |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function initializeAction() |
|
56
|
|
|
{ |
|
57
|
|
|
parent::initializeAction(); |
|
58
|
|
|
$this->indexQueue = GeneralUtility::makeInstance(Queue::class); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Index action, shows an overview of available index maintenance operations. |
|
63
|
|
|
* |
|
64
|
|
|
* @return void |
|
65
|
|
|
*/ |
|
66
|
|
|
public function indexAction() |
|
67
|
|
|
{ |
|
68
|
|
|
if ($this->selectedSite === null) { |
|
69
|
|
|
$this->view->assignMultiple([ |
|
70
|
|
|
'can_not_proceed' => true, |
|
71
|
|
|
'pageUID' => $this->selectedPageUID |
|
72
|
|
|
]); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Empties the site's indexes. |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
|
public function emptyIndexAction() |
|
82
|
|
|
{ |
|
83
|
|
|
$siteHash = $this->selectedSite->getSiteHash(); |
|
84
|
|
|
|
|
85
|
|
|
try { |
|
86
|
|
|
$affectedCores = []; |
|
87
|
|
|
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
|
88
|
|
|
foreach ($solrServers as $solrServer) { |
|
89
|
|
|
/* @var $solrServer SolrService */ |
|
90
|
|
|
$solrServer->deleteByQuery('siteHash:' . $siteHash); |
|
91
|
|
|
$solrServer->commit(false, false, false); |
|
92
|
|
|
$affectedCores[] = $solrServer->getCoreName(); |
|
93
|
|
|
} |
|
94
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('solr.backend.index_administration.index_emptied_all', 'Solr', [$this->selectedSite->getLabel(), implode(', ', $affectedCores)])); |
|
95
|
|
|
} catch (\Exception $e) { |
|
96
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('solr.backend.index_administration.error.on_empty_index', 'Solr', [$e->__toString()]), '', FlashMessage::ERROR); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$this->redirect('index'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Empties the Index Queue |
|
104
|
|
|
* |
|
105
|
|
|
* @return void |
|
106
|
|
|
*/ |
|
107
|
|
|
public function clearIndexQueueAction() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->indexQueue->deleteItemsBySite($this->selectedSite); |
|
110
|
|
|
$this->addFlashMessage( |
|
111
|
|
|
LocalizationUtility::translate('solr.backend.index_administration.success.queue_emptied', 'Solr', |
|
112
|
|
|
[$this->selectedSite->getLabel()]) |
|
113
|
|
|
); |
|
114
|
|
|
|
|
115
|
|
|
$this->redirect('index'); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Reloads the site's Solr cores. |
|
120
|
|
|
* |
|
121
|
|
|
* @return void |
|
122
|
|
|
*/ |
|
123
|
|
|
public function reloadIndexConfigurationAction() |
|
124
|
|
|
{ |
|
125
|
|
|
$coresReloaded = true; |
|
126
|
|
|
$reloadedCores = []; |
|
127
|
|
|
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
|
128
|
|
|
|
|
129
|
|
|
foreach ($solrServers as $solrServer) { |
|
130
|
|
|
/* @var $solrServer SolrService */ |
|
131
|
|
|
$coreReloaded = $solrServer->reloadCore()->getHttpStatus() === 200; |
|
132
|
|
|
$coreName = $solrServer->getCoreName(); |
|
133
|
|
|
|
|
134
|
|
|
if (!$coreReloaded) { |
|
135
|
|
|
$coresReloaded = false; |
|
136
|
|
|
|
|
137
|
|
|
$this->addFlashMessage( |
|
138
|
|
|
'Failed to reload index configuration for core "' . $coreName . '"', |
|
139
|
|
|
'', |
|
140
|
|
|
FlashMessage::ERROR |
|
141
|
|
|
); |
|
142
|
|
|
break; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
$reloadedCores[] = $coreName; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
if ($coresReloaded) { |
|
149
|
|
|
$this->addFlashMessage( |
|
150
|
|
|
'Core configuration reloaded ('.implode(', ', $reloadedCores).').', |
|
151
|
|
|
'', |
|
152
|
|
|
FlashMessage::OK |
|
153
|
|
|
); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
$this->redirect('index'); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|