Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ValidateTemplateData | |
0.00% |
0 / 36 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | $IP = getenv( 'MW_INSTALL_PATH' ); |
| 4 | if ( $IP === false ) { |
| 5 | $IP = __DIR__ . '/../../..'; |
| 6 | } |
| 7 | require_once "$IP/maintenance/Maintenance.php"; |
| 8 | |
| 9 | use MediaWiki\Extension\TemplateData\TemplateDataBlob; |
| 10 | use MediaWiki\Maintenance\Maintenance; |
| 11 | use MediaWiki\Title\Title; |
| 12 | |
| 13 | /** |
| 14 | * @license GPL-2.0-or-later |
| 15 | */ |
| 16 | class ValidateTemplateData extends Maintenance { |
| 17 | |
| 18 | public function __construct() { |
| 19 | parent::__construct(); |
| 20 | $this->addDescription( 'Checks all TemplateData JSON pages are valid and outputs the name of invalid rows' ); |
| 21 | |
| 22 | $this->setBatchSize( 500 ); |
| 23 | $this->requireExtension( 'TemplateData' ); |
| 24 | } |
| 25 | |
| 26 | public function execute() { |
| 27 | $db = $this->getReplicaDB(); |
| 28 | |
| 29 | $lastId = 0; |
| 30 | $rowsChecked = 0; |
| 31 | $badRows = 0; |
| 32 | $this->output( "Pages with invalid Template Data:\n" ); |
| 33 | do { |
| 34 | $res = $db->newSelectQueryBuilder() |
| 35 | ->from( 'page_props' ) |
| 36 | ->join( 'page', null, 'pp_page=page_id' ) |
| 37 | ->fields( [ 'pp_page', 'pp_value', 'page_namespace', 'page_title' ] ) |
| 38 | ->where( [ |
| 39 | $db->expr( 'pp_page', '>', $lastId ), |
| 40 | 'pp_propname' => 'templatedata' |
| 41 | ] ) |
| 42 | ->orderBy( 'pp_page' ) |
| 43 | ->limit( $this->getBatchSize() ) |
| 44 | ->caller( __METHOD__ ) |
| 45 | ->fetchResultSet(); |
| 46 | |
| 47 | $count = $res->numRows(); |
| 48 | |
| 49 | foreach ( $res as $row ) { |
| 50 | $tdb = TemplateDataBlob::newFromDatabase( $db, $row->pp_value ); |
| 51 | $status = $tdb->getStatus(); |
| 52 | if ( !$status->isOK() ) { |
| 53 | $this->output( |
| 54 | Title::newFromRow( $row )->getPrefixedText() . "\n" |
| 55 | ); |
| 56 | $badRows++; |
| 57 | } |
| 58 | $lastId = $row->pp_page; |
| 59 | $rowsChecked++; |
| 60 | } |
| 61 | } while ( $count !== 0 ); |
| 62 | |
| 63 | $this->output( "\nDone!\n" ); |
| 64 | $this->output( "Rows checked: {$rowsChecked}\n" ); |
| 65 | $this->output( "Bad rows: {$badRows}\n" ); |
| 66 | } |
| 67 | |
| 68 | } |
| 69 | |
| 70 | $maintClass = ValidateTemplateData::class; |
| 71 | require_once RUN_MAINTENANCE_IF_MAIN; |