1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr\Report; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2010-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\System\Solr\SolrConnection; |
29
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
30
|
|
|
use TYPO3\CMS\Reports\Status; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Provides an status report about which schema version is used and checks |
34
|
|
|
* whether it fits the recommended version shipping with the extension. |
35
|
|
|
* |
36
|
|
|
* @author Ingo Renner <[email protected]> |
37
|
|
|
*/ |
38
|
|
|
class SchemaStatus extends AbstractSolrStatus |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The schema name property is constructed as follows: |
43
|
|
|
* |
44
|
|
|
* tx_solr - The extension key |
45
|
|
|
* x-y-z - The extension version this schema is meant to work with |
46
|
|
|
* YYYYMMDD - The date the schema file was changed the last time |
47
|
|
|
* |
48
|
|
|
* Must be updated when changing the schema. |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
const RECOMMENDED_SCHEMA_VERSION = 'tx_solr-9-0-0--20180727'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Compiles a collection of schema version checks against each configured |
56
|
|
|
* Solr server. Only adds an entry if a schema other than the |
57
|
|
|
* recommended one was found. |
58
|
|
|
* |
59
|
|
|
*/ |
60
|
1 |
|
public function getStatus() |
61
|
|
|
{ |
62
|
1 |
|
$reports = []; |
63
|
|
|
/** @var $connectionManager ConnectionManager */ |
64
|
1 |
|
$connectionManager = GeneralUtility::makeInstance(ConnectionManager::class); |
65
|
1 |
|
$solrConnections = $connectionManager->getAllConnections(); |
66
|
|
|
|
67
|
1 |
|
foreach ($solrConnections as $solrConnection) { |
68
|
|
|
$adminService = $solrConnection->getAdminService(); |
69
|
|
|
/** @var $solrConnection SolrConnection */ |
70
|
|
|
if (!$adminService->ping()) { |
71
|
|
|
$url = $adminService->__toString(); |
72
|
|
|
$pingFailedMsg = 'Could not ping solr server, can not check version ' . (string)$url; |
73
|
|
|
$status = GeneralUtility::makeInstance( |
74
|
|
|
Status::class, |
75
|
|
|
/** @scrutinizer ignore-type */ 'Apache Solr Version', |
76
|
|
|
/** @scrutinizer ignore-type */ 'Not accessible', |
77
|
|
|
/** @scrutinizer ignore-type */ $pingFailedMsg, |
78
|
|
|
/** @scrutinizer ignore-type */ Status::ERROR |
79
|
|
|
); |
80
|
|
|
$reports[] = $status; |
81
|
|
|
continue; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$isWrongSchema = $adminService->getSchema()->getName() != self::RECOMMENDED_SCHEMA_VERSION; |
85
|
|
|
if ($isWrongSchema) { |
86
|
|
|
$variables = ['solr' => $adminService, 'recommendedVersion' => self::RECOMMENDED_SCHEMA_VERSION]; |
87
|
|
|
$report = $this->getRenderedReport('SchemaStatus.html', $variables); |
88
|
|
|
$status = GeneralUtility::makeInstance( |
89
|
|
|
Status::class, |
90
|
|
|
/** @scrutinizer ignore-type */ 'Schema Version', |
91
|
|
|
/** @scrutinizer ignore-type */ 'Unsupported Schema', |
92
|
|
|
/** @scrutinizer ignore-type */ $report, |
93
|
|
|
/** @scrutinizer ignore-type */ Status::WARNING |
94
|
|
|
); |
95
|
|
|
$reports[] = $status; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
return $reports; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|