Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| MigrateTagTemplate | |
0.00% |
0 / 27 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| doDBUpdates | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
| getUpdateKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Linter\Maintenance; |
| 4 | |
| 5 | use MediaWiki\Maintenance\LoggedUpdateMaintenance; |
| 6 | |
| 7 | /** |
| 8 | * Maintenance script that migrates the linter_params field value to the new tag and template fields |
| 9 | * Note: The schema migration "patch-linter-add-template-tag-fields.json" is expected to have been done. |
| 10 | * The extension now populates these new fields by default. This script will migrate any data |
| 11 | * in existing records to the new fields. |
| 12 | */ |
| 13 | |
| 14 | // @codeCoverageIgnoreStart |
| 15 | $IP = getenv( 'MW_INSTALL_PATH' ); |
| 16 | if ( $IP === false ) { |
| 17 | $IP = __DIR__ . '/../../..'; |
| 18 | } |
| 19 | require_once "$IP/maintenance/Maintenance.php"; |
| 20 | // @codeCoverageIgnoreEnd |
| 21 | |
| 22 | class MigrateTagTemplate extends LoggedUpdateMaintenance { |
| 23 | |
| 24 | /** |
| 25 | * @inheritDoc |
| 26 | */ |
| 27 | public function __construct() { |
| 28 | parent::__construct(); |
| 29 | $this->requireExtension( 'Linter' ); |
| 30 | $this->addDescription( |
| 31 | 'Copy the tag and template data from the params field in the linter table' |
| 32 | ); |
| 33 | $this->addOption( |
| 34 | 'sleep', |
| 35 | 'Sleep time (in seconds) between every batch. Default: 1 seconds', |
| 36 | false, |
| 37 | true |
| 38 | ); |
| 39 | $this->setBatchSize( 1000 ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * The Linter migrate linter_params to linter_tag and linter_template script can take a day to run on --wiki enwiki |
| 44 | * @inheritDoc |
| 45 | */ |
| 46 | protected function doDBUpdates() { |
| 47 | $this->output( "Running linter migrate linter_params to tag and template function, this may take a while\n" ); |
| 48 | |
| 49 | $batchSize = $this->getBatchSize(); |
| 50 | $sleep = (int)$this->getOption( 'sleep', 1 ); |
| 51 | |
| 52 | $dbw = $this->getDB( DB_PRIMARY ); |
| 53 | if ( !$dbw->fieldExists( 'linter', 'linter_template', __METHOD__ ) ) { |
| 54 | $this->output( "Run update.php to add linter_tag and linter_template fields to the linter table.\n" ); |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | $this->output( "Migrating the linter_params field to the linter_tag and linter_template fields...\n" ); |
| 59 | |
| 60 | $database = $this->getServiceContainer()->get( 'Linter.Database' ); |
| 61 | $updated = $database->migrateTemplateAndTagInfo( $batchSize, $sleep ); |
| 62 | |
| 63 | $this->output( |
| 64 | "Completed migration of linter_params data in the linter table, $updated rows updated.\n" |
| 65 | ); |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @inheritDoc |
| 72 | */ |
| 73 | protected function getUpdateKey() { |
| 74 | return 'migrate linter table linter_params data to the linter_tag and linter_template fields'; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // @codeCoverageIgnoreStart |
| 79 | $maintClass = MigrateTagTemplate::class; |
| 80 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 81 | // @codeCoverageIgnoreEnd |