Passed
Pull Request — master (#1287)
by Sascha
21:29
created

SolrConfigStatus   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 40
ccs 6
cts 14
cp 0.4286
rs 10
c 0
b 0
f 0

1 Method

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