Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| NumberOfShardsValidator | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| validate | |
0.00% |
0 / 12 |
|
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\Language\RawMessage; |
| 8 | use MediaWiki\Status\Status; |
| 9 | |
| 10 | class NumberOfShardsValidator extends Validator { |
| 11 | /** |
| 12 | * @var Index |
| 13 | */ |
| 14 | private $index; |
| 15 | |
| 16 | /** |
| 17 | * @var int |
| 18 | */ |
| 19 | protected $shardCount; |
| 20 | |
| 21 | /** |
| 22 | * @param Index $index |
| 23 | * @param int $shardCount |
| 24 | * @param Printer|null $out |
| 25 | */ |
| 26 | public function __construct( Index $index, $shardCount, ?Printer $out = null ) { |
| 27 | parent::__construct( $out ); |
| 28 | |
| 29 | $this->index = $index; |
| 30 | $this->shardCount = $shardCount; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @return Status |
| 35 | */ |
| 36 | public function validate() { |
| 37 | $this->outputIndented( "\tValidating number of shards..." ); |
| 38 | $settings = $this->index->getSettings()->get(); |
| 39 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
| 40 | $actualShardCount = $settings['number_of_shards']; |
| 41 | if ( $actualShardCount == $this->shardCount ) { |
| 42 | $this->output( "ok\n" ); |
| 43 | } else { |
| 44 | $this->output( "is $actualShardCount but should be " . $this->shardCount . "...cannot correct!\n" ); |
| 45 | return Status::newFatal( new RawMessage( |
| 46 | "Number of shards is incorrect and cannot be changed without a rebuild. You can solve this\n" . |
| 47 | "problem by running this program again with either --startOver or --reindexAndRemoveOk. Make\n" . |
| 48 | "sure you understand the consequences of either choice.. This script will now continue to\n" . |
| 49 | "validate everything else." ) ); |
| 50 | } |
| 51 | |
| 52 | return Status::newGood(); |
| 53 | } |
| 54 | } |