File: migrateNamespace.php

package info (click to toggle)
mediawiki 1%3A1.43.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 417,464 kB
  • sloc: php: 1,062,949; javascript: 664,290; sql: 9,714; python: 5,458; xml: 3,489; sh: 1,131; makefile: 64
file content (76 lines) | stat: -rw-r--r-- 2,205 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

namespace MediaWiki\Linter\Maintenance;

use MediaWiki\Maintenance\LoggedUpdateMaintenance;

/**
 * Maintenance script that migrates the page table page_namespace field values
 * to the linter table linter_namespace field to improve linter search performance.
 * Note: The schema migration "patch-linter-add-namespace.json" is expected to have been done.
 * The extension now populates this new field by default. This script will migrate any data
 * in existing records to this new field.
 */

$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
	$IP = __DIR__ . '/../../..';
}
require_once "$IP/maintenance/Maintenance.php";

class MigrateNamespace extends LoggedUpdateMaintenance {

	/**
	 * @inheritDoc
	 */
	public function __construct() {
		parent::__construct();
		$this->requireExtension( 'Linter' );
		$this->addDescription(
			'Copy the namespace data from the page table into the linter table'
		);
		$this->addOption(
			'sleep',
			'Sleep time (in seconds) between every batch. Default: 1 seconds',
			false,
			true
		);
		$this->setBatchSize( 1000 );
	}

	/**
	 * The Linter migrate namespace script can take a day to run using: --wiki enwiki
	 * @inheritDoc
	 */
	protected function doDBUpdates() {
		$this->output( "Running linter migrate namespace function, this may take a while\n" );

		$batchSize = $this->getBatchSize();
		$sleep = (int)$this->getOption( 'sleep', 1 );

		$dbw = $this->getDB( DB_PRIMARY );
		if ( !$dbw->fieldExists( 'linter', 'linter_namespace', __METHOD__ ) ) {
			$this->output( "Run update.php to add linter_namespace field to the linter table.\n" );
			return false;
		}

		$this->output( "Migrating the page table page_namespace field to the linter table...\n" );

		$database = $this->getServiceContainer()->get( 'Linter.Database' );
		$updated = $database->migrateNamespace( $batchSize, $batchSize, $sleep );

		$this->output( "Completed migration of page_namespace data to the linter table, $updated rows updated.\n" );

		return true;
	}

	/**
	 * @inheritDoc
	 */
	protected function getUpdateKey() {
		return 'migrate namespace id from page to linter table';
	}
}

$maintClass = MigrateNamespace::class;
require_once RUN_MAINTENANCE_IF_MAIN;