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