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