Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReplicaCountValidator
0.00% covered (danger)
0.00%
0 / 12
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 / 9
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace CirrusSearch\Maintenance\Validators;
4
5use CirrusSearch\Maintenance\Printer;
6use CirrusSearch\ReplicaCount;
7use Elastica\Index;
8use MediaWiki\Status\Status;
9
10class ReplicaCountValidator extends Validator {
11    /**
12     * @var Index
13     */
14    private $index;
15
16    /**
17     * @var ReplicaCount
18     */
19    protected $replicaCount;
20
21    /**
22     * @param Index $index
23     * @param ReplicaCount $replicaCount
24     * @param Printer|null $out
25     */
26    public function __construct( Index $index, ReplicaCount $replicaCount, ?Printer $out = null ) {
27        parent::__construct( $out );
28
29        $this->index = $index;
30        $this->replicaCount = $replicaCount;
31    }
32
33    /**
34     * @return Status
35     */
36    public function validate() {
37        $this->outputIndented( "\tValidating replica count..." );
38        $settings = $this->index->getSettings()->get();
39        if ( $this->replicaCount->matchesIndexSettings( $settings ) ) {
40            $this->output( "ok\n" );
41        } else {
42            $actualReplicaCount = ReplicaCount::fromIndexSettings( $settings );
43            $this->output( "is $actualReplicaCount but should be " . $this->replicaCount . '...' );
44            $this->index->getSettings()->set( $this->replicaCount->toUpdateSettings() );
45            $this->output( "corrected\n" );
46        }
47
48        return Status::newGood();
49    }
50}