Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 38
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
MigrateTagTemplate
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 doDBUpdates
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
12
 getUpdateKey
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Maintenance script that migrates the linter_params field value to the new tag and template fields
5 * note: This should be run once the tag and template write functionality in linter
6 *   recordLintJob has been enabled by setting LinterWriteTagAndTemplateColumnsStage true.
7 */
8
9$IP = getenv( 'MW_INSTALL_PATH' );
10if ( $IP === false ) {
11    $IP = __DIR__ . '/../../..';
12}
13require_once "$IP/maintenance/Maintenance.php";
14
15class MigrateTagTemplate extends LoggedUpdateMaintenance {
16
17    /**
18     * @inheritDoc
19     */
20    public function __construct() {
21        parent::__construct();
22        $this->requireExtension( 'Linter' );
23        $this->addDescription(
24            'Copy the tag and template data from the params field in the linter table'
25        );
26        $this->addOption(
27            'sleep',
28            'Sleep time (in seconds) between every batch. Default: 1 seconds',
29            false,
30            true
31        );
32        $this->setBatchSize( 1000 );
33    }
34
35    /**
36     * The Linter migrate linter_params to linter_tag and linter_template script can take a day to run on --wiki enwiki
37     * @inheritDoc
38     */
39    protected function doDBUpdates() {
40        $config = $this->getConfig();
41        $enableMigrateTagAndTemplateStage = $config->get( 'LinterWriteTagAndTemplateColumnsStage' );
42        if ( !$enableMigrateTagAndTemplateStage ) {
43            $this->output( "LinterWriteTagAndTemplateColumnsStage config value is false, code disabled\n" );
44            return false;
45        }
46
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 = self::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, false );
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$maintClass = MigrateTagTemplate::class;
79require_once RUN_MAINTENANCE_IF_MAIN;