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