Passed
Push — task/3376-TYPO3_12_compatibili... ( dc7e5a...379ca7 )
by Rafael
40:48
created

SolrConfigStatus::getStatus()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 28
rs 9.7666
c 0
b 0
f 0
cc 4
nc 3
nop 0
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 Doctrine\DBAL\Driver\Exception as DBALDriverException;
22
use Throwable;
23
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
24
use TYPO3\CMS\Core\Utility\GeneralUtility;
25
use TYPO3\CMS\Reports\Status;
26
27
/**
28
 * Provides a status report about which solrconfig 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 SolrConfigStatus extends AbstractSolrStatus
34
{
35
    /**
36
     * The config name property is constructed as follows:
37
     *
38
     * tx_solr    - The extension key
39
     * x-y-z    - The extension version this config is meant to work with
40
     * YYYYMMDD    - The date the config file was changed the last time
41
     *
42
     * Must be updated when changing the solrconfig.
43
     *
44
     * @var string
45
     */
46
    const RECOMMENDED_SOLRCONFIG_VERSION = 'tx_solr-11-5-0--20211001';
47
48
    /**
49
     * Compiles a collection of solrconfig version checks against each configured
50
     * Solr server. Only adds an entry if a solrconfig other than the
51
     * recommended one was found.
52
     *
53
     * @return array
54
     *
55
     * @throws DBALDriverException
56
     * @throws Throwable
57
     */
58
    public function getStatus(): array
59
    {
60
        $reports = [];
61
        $solrConnections = GeneralUtility::makeInstance(ConnectionManager::class)->getAllConnections();
62
63
        foreach ($solrConnections as $solrConnection) {
64
            $adminService = $solrConnection->getAdminService();
65
66
            if ($adminService->ping() && $adminService->getSolrconfigName() != self::RECOMMENDED_SOLRCONFIG_VERSION) {
67
                $variables = ['solr' => $adminService, 'recommendedVersion' => self::RECOMMENDED_SOLRCONFIG_VERSION];
68
                $report = $this->getRenderedReport('SolrConfigStatus.html', $variables);
69
                $status = GeneralUtility::makeInstance(
70
                    Status::class,
71
                    /** @scrutinizer ignore-type */
72
                    'Solrconfig Version',
73
                    /** @scrutinizer ignore-type */
74
                    'Unsupported solrconfig.xml',
75
                    /** @scrutinizer ignore-type */
76
                    $report,
77
                    /** @scrutinizer ignore-type */
78
                    ContextualFeedbackSeverity::WARNING
79
                );
80
81
                $reports[] = $status;
82
            }
83
        }
84
85
        return $reports;
86
    }
87
88
    /**
89
     * {@inheritDoc}
90
     */
91
    public function getLabel(): string
92
    {
93
        return 'solr/config';
94
    }
95
}
96