1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ApacheSolrForTypo3\Solr\Controller\Backend\Search; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TYPO3 CMS project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
10
|
|
|
* of the License, or any later version. |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please read the |
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* The TYPO3 project - inspiring people to share! |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
use ApacheSolrForTypo3\Solr\ConnectionManager; |
19
|
|
|
use ApacheSolrForTypo3\Solr\IndexQueue\Queue; |
20
|
|
|
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection; |
21
|
|
|
use Psr\Http\Message\ResponseInterface; |
22
|
|
|
use Throwable; |
23
|
|
|
use TYPO3\CMS\Core\Http\RedirectResponse; |
24
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
25
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Index Administration Module |
29
|
|
|
* |
30
|
|
|
* @author Ingo Renner <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class IndexAdministrationModuleController extends AbstractModuleController |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var Queue |
36
|
|
|
*/ |
37
|
|
|
protected Queue $indexQueue; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var ConnectionManager|null |
41
|
|
|
*/ |
42
|
|
|
protected ?ConnectionManager $solrConnectionManager = null; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param ConnectionManager $solrConnectionManager |
46
|
|
|
*/ |
47
|
3 |
|
public function setSolrConnectionManager(ConnectionManager $solrConnectionManager) |
48
|
|
|
{ |
49
|
3 |
|
$this->solrConnectionManager = $solrConnectionManager; |
50
|
3 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Index action, shows an overview of available index maintenance operations. |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
public function indexAction(): ResponseInterface |
58
|
|
|
{ |
59
|
|
|
if ($this->selectedSite === null || empty($this->solrConnectionManager->getConnectionsBySite($this->selectedSite))) { |
|
|
|
|
60
|
|
|
$this->view->assign('can_not_proceed', true); |
61
|
|
|
} |
62
|
|
|
$this->moduleTemplate->setContent($this->view->render()); |
63
|
|
|
return $this->htmlResponse($this->moduleTemplate->renderContent()); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Empties the site's indexes. |
68
|
|
|
*/ |
69
|
1 |
|
public function emptyIndexAction(): ResponseInterface |
70
|
|
|
{ |
71
|
1 |
|
$siteHash = $this->selectedSite->getSiteHash(); |
|
|
|
|
72
|
|
|
|
73
|
|
|
try { |
74
|
1 |
|
$affectedCores = []; |
75
|
1 |
|
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
|
|
|
|
76
|
1 |
|
foreach ($solrServers as $solrServer) { |
77
|
1 |
|
$writeService = $solrServer->getWriteService(); |
78
|
|
|
/* @var $solrServer SolrConnection */ |
79
|
1 |
|
$writeService->deleteByQuery('siteHash:' . $siteHash); |
80
|
1 |
|
$writeService->commit(false, false, false); |
81
|
1 |
|
$affectedCores[] = $writeService->getPrimaryEndpoint()->getCore(); |
82
|
|
|
} |
83
|
1 |
|
$message = LocalizationUtility::translate('solr.backend.index_administration.index_emptied_all', 'Solr', [$this->selectedSite->getLabel(), implode(', ', $affectedCores)]); |
84
|
1 |
|
$this->addFlashMessage($message); |
85
|
|
|
} catch (Throwable $e) { |
86
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('solr.backend.index_administration.error.on_empty_index', 'Solr', [$e->__toString()]), '', FlashMessage::ERROR); |
87
|
|
|
} |
88
|
|
|
|
89
|
1 |
|
return new RedirectResponse($this->uriBuilder->uriFor('index'), 303); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Reloads the site's Solr cores. |
94
|
|
|
* |
95
|
|
|
* @return ResponseInterface |
96
|
|
|
*/ |
97
|
2 |
|
public function reloadIndexConfigurationAction(): ResponseInterface |
98
|
|
|
{ |
99
|
2 |
|
$coresReloaded = true; |
100
|
2 |
|
$reloadedCores = []; |
101
|
2 |
|
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
|
|
|
|
102
|
|
|
|
103
|
2 |
|
foreach ($solrServers as $solrServer) { |
104
|
2 |
|
$coreAdmin = $solrServer->getAdminService(); |
105
|
2 |
|
$coreReloaded = $coreAdmin->reloadCore()->getHttpStatus() === 200; |
106
|
|
|
|
107
|
2 |
|
$coreName = $coreAdmin->getPrimaryEndpoint()->getCore(); |
108
|
2 |
|
if (!$coreReloaded) { |
109
|
|
|
$coresReloaded = false; |
110
|
|
|
|
111
|
|
|
$this->addFlashMessage( |
112
|
|
|
'Failed to reload index configuration for core "' . $coreName . '"', |
113
|
|
|
'', |
114
|
|
|
FlashMessage::ERROR |
115
|
|
|
); |
116
|
|
|
break; |
117
|
|
|
} |
118
|
|
|
|
119
|
2 |
|
$reloadedCores[] = $coreName; |
120
|
|
|
} |
121
|
|
|
|
122
|
2 |
|
if ($coresReloaded) { |
123
|
2 |
|
$this->addFlashMessage( |
124
|
2 |
|
'Core configuration reloaded (' . implode(', ', $reloadedCores) . ').', |
125
|
2 |
|
'', |
126
|
2 |
|
FlashMessage::OK |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
2 |
|
return new RedirectResponse($this->uriBuilder->uriFor('index'), 303); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.