Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
MigrateNamespace
0.00% covered (danger)
0.00%
0 / 30
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 / 17
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 page table page_namespace field values
5 * to the linter table linter_namespace field to improve linter search performance.
6 * note: This should be run once the namespace write functionality in linter
7 *   recordLintJob has been enabled by setting LinterWriteNamespaceColumnStage true.
8 * note: This code is based on migrateRevisionActorTemp.php and migrateLinksTable.php
9 */
10
11$IP = getenv( 'MW_INSTALL_PATH' );
12if ( $IP === false ) {
13    $IP = __DIR__ . '/../../..';
14}
15require_once "$IP/maintenance/Maintenance.php";
16
17class MigrateNamespace extends LoggedUpdateMaintenance {
18
19    /**
20     * @inheritDoc
21     */
22    public function __construct() {
23        parent::__construct();
24        $this->requireExtension( 'Linter' );
25        $this->addDescription(
26            'Copy the namespace data from the page table into the linter table'
27        );
28        $this->addOption(
29            'sleep',
30            'Sleep time (in seconds) between every batch. Default: 1 seconds',
31            false,
32            true
33        );
34        $this->setBatchSize( 1000 );
35    }
36
37    /**
38     * The Linter migrate namespace script can take a day to run using: --wiki enwiki
39     * @inheritDoc
40     */
41    protected function doDBUpdates() {
42        $config = $this->getConfig();
43        $enableMigrateNamespaceStage = $config->get( 'LinterWriteNamespaceColumnStage' );
44        if ( !$enableMigrateNamespaceStage ) {
45            $this->output( "LinterWriteNamespaceColumnStage config value is false, code is disabled, exiting\n" );
46            return false;
47        }
48
49        $this->output( "Running linter migrate namespace function, this may take a while\n" );
50
51        $batchSize = $this->getBatchSize();
52        $sleep = (int)$this->getOption( 'sleep', 1 );
53
54        $dbw = self::getDB( DB_PRIMARY );
55        if ( !$dbw->fieldExists( 'linter', 'linter_namespace', __METHOD__ ) ) {
56            $this->output( "Run update.php to add linter_namespace field to the linter table.\n" );
57            return false;
58        }
59
60        $this->output( "Migrating the page table page_namespace field to the linter table...\n" );
61
62        $database = $this->getServiceContainer()->get( 'Linter.Database' );
63        $updated = $database->migrateNamespace( $batchSize, $batchSize, $sleep, false );
64
65        $this->output( "Completed migration of page_namespace data to the linter table, $updated rows updated.\n" );
66
67        return true;
68    }
69
70    /**
71     * @inheritDoc
72     */
73    protected function getUpdateKey() {
74        return 'migrate namespace id from page to linter table';
75    }
76}
77
78$maintClass = MigrateNamespace::class;
79require_once RUN_MAINTENANCE_IF_MAIN;