1 | <?php |
||
39 | class InfoModuleController extends AbstractModuleController |
||
40 | { |
||
41 | /** |
||
42 | * @var \ApacheSolrForTypo3\Solr\ConnectionManager |
||
43 | * @inject |
||
44 | */ |
||
45 | protected $solrConnectionManager; |
||
46 | |||
47 | /** |
||
48 | * Set up the doc header properly here |
||
49 | * |
||
50 | * @param ViewInterface $view |
||
51 | * @return void |
||
52 | */ |
||
53 | protected function initializeView(ViewInterface $view) |
||
62 | |||
63 | /** |
||
64 | * Index action, shows an overview of the state of the Solr index |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | public function indexAction() |
||
69 | { |
||
70 | if ($this->selectedSite === null) { |
||
71 | $this->view->assign('can_not_proceed', true); |
||
72 | return; |
||
73 | } |
||
74 | |||
75 | $this->collectConnectionInfos(); |
||
76 | $this->collectStatistics(); |
||
77 | $this->collectIndexFieldsInfo(); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Checks whether the configured Solr server can be reached and provides a |
||
82 | * flash message according to the result of the check. |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | protected function collectConnectionInfos() |
||
87 | { |
||
88 | $connectedHosts = []; |
||
89 | $missingHosts = []; |
||
90 | $invalidPaths = []; |
||
91 | |||
92 | /* @var Path $path */ |
||
93 | $path = GeneralUtility::makeInstance(Path::class); |
||
94 | $connections = $this->solrConnectionManager->getConnectionsBySite($this->selectedSite); |
||
95 | |||
96 | if (empty($connections)) { |
||
97 | $this->view->assign('can_not_proceed', true); |
||
98 | return; |
||
99 | } |
||
100 | |||
101 | foreach ($connections as $connection) { |
||
102 | $coreUrl = $connection->getScheme() . '://' . $connection->getHost() . ':' . $connection->getPort() . $connection->getPath(); |
||
103 | |||
104 | if ($connection->ping()) { |
||
105 | $connectedHosts[] = $coreUrl; |
||
106 | } else { |
||
107 | $missingHosts[] = $coreUrl; |
||
108 | } |
||
109 | |||
110 | if (!$path->isValidSolrPath($connection->getPath())) { |
||
111 | $invalidPaths[] = $connection->getPath(); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | $this->view->assignMultiple([ |
||
116 | 'site' => $this->selectedSite, |
||
117 | 'apiKey' => Api::getApiKey(), |
||
118 | 'connectedHosts' => $connectedHosts, |
||
119 | 'missingHosts' => $missingHosts, |
||
120 | 'invalidPaths' => $invalidPaths |
||
121 | ]); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Index action, shows an overview of the state of the Solr index |
||
126 | * |
||
127 | * @return void |
||
128 | */ |
||
129 | protected function collectStatistics() |
||
162 | |||
163 | /** |
||
164 | * Gets Luke meta data for the currently selected core and provides a list |
||
165 | * of that data. |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | protected function collectIndexFieldsInfo() |
||
214 | |||
215 | /** |
||
216 | * Gets field metrics. |
||
217 | * |
||
218 | * @param \Apache_Solr_Response $lukeData Luke index data |
||
219 | * @param string $limitNote Note to display if there are too many documents in the index to show number of terms for a field |
||
220 | * |
||
221 | * @return array An array of field metrics |
||
222 | */ |
||
223 | protected function getFields(\Apache_Solr_Response $lukeData, $limitNote) |
||
240 | |||
241 | /** |
||
242 | * Gets general core metrics. |
||
243 | * |
||
244 | * @param \Apache_Solr_Response $lukeData Luke index data |
||
245 | * @param array $fields Fields metrics |
||
246 | * |
||
247 | * @return array An array of core metrics |
||
248 | */ |
||
249 | protected function getCoreMetrics(\Apache_Solr_Response $lukeData, array $fields) |
||
260 | } |
||
261 |