| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Linter\Maintenance; |
| 4 |
|
| 5 |
use MediaWiki\Maintenance\LoggedUpdateMaintenance; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
$IP = getenv( 'MW_INSTALL_PATH' ); |
| 16 |
if ( $IP === false ) { |
| 17 |
$IP = __DIR__ . '/../../..'; |
| 18 |
} |
| 19 |
require_once "$IP/maintenance/Maintenance.php"; |
| 20 |
|
| 21 |
class MigrateNamespace extends LoggedUpdateMaintenance { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public function __construct() { |
| 27 |
parent::__construct(); |
| 28 |
$this->requireExtension( 'Linter' ); |
| 29 |
$this->addDescription( |
| 30 |
'Copy the namespace data from the page table into the linter table' |
| 31 |
); |
| 32 |
$this->addOption( |
| 33 |
'sleep', |
| 34 |
'Sleep time (in seconds) between every batch. Default: 1 seconds', |
| 35 |
false, |
| 36 |
true |
| 37 |
); |
| 38 |
$this->setBatchSize( 1000 ); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
protected function doDBUpdates() { |
| 46 |
$this->output( "Running linter migrate namespace function, this may take a while\n" ); |
| 47 |
|
| 48 |
$batchSize = $this->getBatchSize(); |
| 49 |
$sleep = (int)$this->getOption( 'sleep', 1 ); |
| 50 |
|
| 51 |
$dbw = $this->getDB( DB_PRIMARY ); |
| 52 |
if ( !$dbw->fieldExists( 'linter', 'linter_namespace', __METHOD__ ) ) { |
| 53 |
$this->output( "Run update.php to add linter_namespace field to the linter table.\n" ); |
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
$this->output( "Migrating the page table page_namespace field to the linter table...\n" ); |
| 58 |
|
| 59 |
$database = $this->getServiceContainer()->get( 'Linter.Database' ); |
| 60 |
$updated = $database->migrateNamespace( $batchSize, $batchSize, $sleep ); |
| 61 |
|
| 62 |
$this->output( "Completed migration of page_namespace data to the linter table, $updated rows updated.\n" ); |
| 63 |
|
| 64 |
return true; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
protected function getUpdateKey() { |
| 71 |
return 'migrate namespace id from page to linter table'; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
$maintClass = MigrateNamespace::class; |
| 76 |
require_once RUN_MAINTENANCE_IF_MAIN; |