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\System\Solr\SolrConnection; |
19
|
|
|
use Psr\Http\Message\ResponseInterface; |
20
|
|
|
use Throwable; |
21
|
|
|
use TYPO3\CMS\Core\Http\RedirectResponse; |
22
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessage; |
23
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Index Administration Module |
27
|
|
|
* |
28
|
|
|
* @author Ingo Renner <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class IndexAdministrationModuleController extends AbstractModuleController |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Index action, shows an overview of available index maintenance operations. |
34
|
|
|
* |
35
|
|
|
* @return ResponseInterface |
36
|
|
|
*/ |
37
|
|
|
public function indexAction(): ResponseInterface |
38
|
|
|
{ |
39
|
|
|
if ($this->selectedSite === null || empty($this->solrConnectionManager->getConnectionsBySite($this->selectedSite))) { |
40
|
|
|
$this->view->assign('can_not_proceed', true); |
41
|
|
|
} |
42
|
|
|
$this->moduleTemplate->setContent($this->view->render()); |
43
|
|
|
return $this->htmlResponse($this->moduleTemplate->renderContent()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Empties the site's indexes. |
48
|
|
|
*/ |
49
|
1 |
|
public function emptyIndexAction(): ResponseInterface |
50
|
|
|
{ |
51
|
1 |
|
$siteHash = $this->selectedSite->getSiteHash(); |
|
|
|
|
52
|
|
|
|
53
|
|
|
try { |
54
|
1 |
|
$affectedCores = []; |
55
|
1 |
|
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
|
|
|
|
56
|
1 |
|
foreach ($solrServers as $solrServer) { |
57
|
1 |
|
$writeService = $solrServer->getWriteService(); |
58
|
|
|
/* @var $solrServer SolrConnection */ |
59
|
1 |
|
$writeService->deleteByQuery('siteHash:' . $siteHash); |
60
|
1 |
|
$writeService->commit(false, false, false); |
61
|
1 |
|
$affectedCores[] = $writeService->getPrimaryEndpoint()->getCore(); |
62
|
|
|
} |
63
|
1 |
|
$message = LocalizationUtility::translate('solr.backend.index_administration.index_emptied_all', 'Solr', [$this->selectedSite->getLabel(), implode(', ', $affectedCores)]); |
64
|
1 |
|
$this->addFlashMessage($message); |
65
|
|
|
} catch (Throwable $e) { |
66
|
|
|
$this->addFlashMessage(LocalizationUtility::translate('solr.backend.index_administration.error.on_empty_index', 'Solr', [$e->__toString()]), '', FlashMessage::ERROR); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
return new RedirectResponse($this->uriBuilder->uriFor('index'), 303); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Reloads the site's Solr cores. |
74
|
|
|
* |
75
|
|
|
* @return ResponseInterface |
76
|
|
|
*/ |
77
|
2 |
|
public function reloadIndexConfigurationAction(): ResponseInterface |
78
|
|
|
{ |
79
|
2 |
|
$coresReloaded = true; |
80
|
2 |
|
$reloadedCores = []; |
81
|
2 |
|
$solrServers = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
|
|
|
|
82
|
|
|
|
83
|
2 |
|
foreach ($solrServers as $solrServer) { |
84
|
2 |
|
$coreAdmin = $solrServer->getAdminService(); |
85
|
2 |
|
$coreReloaded = $coreAdmin->reloadCore()->getHttpStatus() === 200; |
86
|
|
|
|
87
|
2 |
|
$coreName = $coreAdmin->getPrimaryEndpoint()->getCore(); |
88
|
2 |
|
if (!$coreReloaded) { |
89
|
|
|
$coresReloaded = false; |
90
|
|
|
|
91
|
|
|
$this->addFlashMessage( |
92
|
|
|
'Failed to reload index configuration for core "' . $coreName . '"', |
93
|
|
|
'', |
94
|
|
|
FlashMessage::ERROR |
95
|
|
|
); |
96
|
|
|
break; |
97
|
|
|
} |
98
|
|
|
|
99
|
2 |
|
$reloadedCores[] = $coreName; |
100
|
|
|
} |
101
|
|
|
|
102
|
2 |
|
if ($coresReloaded) { |
103
|
2 |
|
$this->addFlashMessage( |
104
|
2 |
|
'Core configuration reloaded (' . implode(', ', $reloadedCores) . ').', |
105
|
2 |
|
'', |
106
|
2 |
|
FlashMessage::OK |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
2 |
|
return new RedirectResponse($this->uriBuilder->uriFor('index'), 303); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
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.