Debian Codegraph @

extensions/Linter/maintenance/migrateTagTemplate.php

raw symbols SCIP
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 $IP = getenv( 'MW_INSTALL_PATH' );
15 if ( $IP === false ) {
16 $IP = __DIR__ . '/../../..';
17 }
18 require_once "$IP/maintenance/Maintenance.php";
19
20 class MigrateTagTemplate extends LoggedUpdateMaintenance {
21
22 /**
23 * @inheritDoc
24 */
25 public function __construct() {
26 parent::__construct();
27 $this->requireExtension( 'Linter' );
28 $this->addDescription(
29 'Copy the tag and template data from the params field in the linter table'
30 );
31 $this->addOption(
32 'sleep',
33 'Sleep time (in seconds) between every batch. Default: 1 seconds',
34 false,
35 true
36 );
37 $this->setBatchSize( 1000 );
38 }
39
40 /**
41 * The Linter migrate linter_params to linter_tag and linter_template script can take a day to run on --wiki enwiki
42 * @inheritDoc
43 */
44 protected function doDBUpdates() {
45 $this->output( "Running linter migrate linter_params to tag and template function, this may take a while\n" );
46
47 $batchSize = $this->getBatchSize();
48 $sleep = (int)$this->getOption( 'sleep', 1 );
49
50 $dbw = $this->getDB( DB_PRIMARY );
51 if ( !$dbw->fieldExists( 'linter', 'linter_template', __METHOD__ ) ) {
52 $this->output( "Run update.php to add linter_tag and linter_template fields to the linter table.\n" );
53 return false;
54 }
55
56 $this->output( "Migrating the linter_params field to the linter_tag and linter_template fields...\n" );
57
58 $database = $this->getServiceContainer()->get( 'Linter.Database' );
59 $updated = $database->migrateTemplateAndTagInfo( $batchSize, $sleep );
60
61 $this->output(
62 "Completed migration of linter_params data in the linter table, $updated rows updated.\n"
63 );
64
65 return true;
66 }
67
68 /**
69 * @inheritDoc
70 */
71 protected function getUpdateKey() {
72 return 'migrate linter table linter_params data to the linter_tag and linter_template fields';
73 }
74 }
75
76 $maintClass = MigrateTagTemplate::class;
77 require_once RUN_MAINTENANCE_IF_MAIN;