Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
AnalyzersValidator
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 validate
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace CirrusSearch\Maintenance\Validators;
4
5use CirrusSearch\Maintenance\Printer;
6use Elastica\Index;
7use MediaWiki\Language\RawMessage;
8use MediaWiki\Status\Status;
9
10class AnalyzersValidator extends Validator {
11    /**
12     * @var Index
13     */
14    private $index;
15
16    /**
17     * @var array
18     */
19    private $analysisConfig;
20
21    /**
22     * @param Index $index
23     * @param array $analysisConfig
24     * @param Printer|null $out
25     */
26    public function __construct( Index $index, array $analysisConfig, ?Printer $out = null ) {
27        parent::__construct( $out );
28
29        $this->index = $index;
30        $this->analysisConfig = $analysisConfig;
31    }
32
33    /**
34     * @return Status
35     */
36    public function validate() {
37        $this->outputIndented( "Validating analyzers..." );
38        $settings = $this->index->getSettings()->get();
39        // @phan-suppress-next-line PhanTypeArraySuspiciousNullable
40        if ( $this->checkConfig( $settings[ 'analysis' ], $this->analysisConfig ) ) {
41            $this->output( "ok\n" );
42        } else {
43            $this->output( "cannot correct\n" );
44            return Status::newFatal( new RawMessage(
45                "This script encountered an index difference that requires that the index be\n" .
46                "copied, indexed to, and then the old index removed. Re-run this script with the\n" .
47                "--reindexAndRemoveOk --indexIdentifier=now parameters to do this." ) );
48        }
49
50        return Status::newGood();
51    }
52}