Completed
Branch master (a6ebf8)
by Timo
03:27
created

SolrConfigStatus   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
wmc 4
eloc 17
c 0
b 0
f 0
dl 0
loc 46
ccs 5
cts 20
cp 0.25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getStatus() 0 24 4
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 TYPO3\CMS\Core\Utility\GeneralUtility;
29
use TYPO3\CMS\Reports\Status;
30
31
/**
32
 * Provides a status report about which solrconfig version is used and checks
33
 * whether it fits the recommended version shipping with the extension.
34
 *
35
 * @author Ingo Renner <[email protected]>
36
 */
37
class SolrConfigStatus extends AbstractSolrStatus
38
{
39
40
    /**
41
     * The config name property is constructed as follows:
42
     *
43
     * tx_solr    - The extension key
44
     * x-y-z    - The extension version this config is meant to work with
45
     * YYYYMMDD    - The date the config file was changed the last time
46
     *
47
     * Must be updated when changing the solrconfig.
48
     *
49
     * @var string
50
     */
51
    const RECOMMENDED_SOLRCONFIG_VERSION = 'tx_solr-9-0-0--20180727';
52
53
    /**
54
     * Compiles a collection of solrconfig version checks against each configured
55
     * Solr server. Only adds an entry if a solrconfig other than the
56
     * recommended one was found.
57
     *
58
     */
59 1
    public function getStatus()
60
    {
61 1
        $reports = [];
62 1
        $solrConnections = GeneralUtility::makeInstance(ConnectionManager::class)->getAllConnections();
63
64 1
        foreach ($solrConnections as $solrConnection) {
65
            $adminService = $solrConnection->getAdminService();
66
67
            if ($adminService->ping() && $adminService->getSolrconfigName() != self::RECOMMENDED_SOLRCONFIG_VERSION) {
68
                $variables = ['solr' => $adminService, 'recommendedVersion' => self::RECOMMENDED_SOLRCONFIG_VERSION];
69
                $report = $this->getRenderedReport('SolrConfigStatus.html', $variables);
70
                $status = GeneralUtility::makeInstance(
71
                    Status::class,
72
                    /** @scrutinizer ignore-type */ 'Solrconfig Version',
73
                    /** @scrutinizer ignore-type */ 'Unsupported solrconfig.xml',
74
                    /** @scrutinizer ignore-type */ $report,
75
                    /** @scrutinizer ignore-type */ Status::WARNING
76
                );
77
78
                $reports[] = $status;
79
            }
80
        }
81
82 1
        return $reports;
83
    }
84
}
85