37 parent::__construct();
38 $this->
addDescription(
'Updates page_restrictions table from old page_restriction column' );
46 if ( !$dbw->tableExists(
'page_restrictions', __METHOD__ ) ) {
47 $this->
fatalError(
"page_restrictions table does not exist" );
50 if ( !$dbw->fieldExists(
'page',
'page_restrictions' ) ) {
51 $this->
output(
"Migration is not needed.\n" );
55 $encodedExpiry = $dbw->getInfinity();
57 $maxPageId = $dbw->selectField(
'page',
'MAX(page_id)',
'', __METHOD__ );
58 $escapedEmptyBlobValue = $dbw->addQuotes(
'' );
63 $batchMaxPageId = $batchMinPageId + $batchSize;
65 $this->
output(
"...processing page IDs from $batchMinPageId to $batchMaxPageId.\n" );
69 [
'page_id',
'page_restrictions' ],
71 "page_restrictions != $escapedEmptyBlobValue",
72 'page_id > ' . $dbw->addQuotes( $batchMinPageId ),
73 'page_id <= ' . $dbw->addQuotes( $batchMaxPageId ),
79 if ( !
$res->numRows() ) {
80 $batchMinPageId = $batchMaxPageId;
87 foreach (
$res as $row ) {
88 $pageIds[] = $row->page_id;
90 $restrictionsByAction = $this->mapLegacyRestrictionBlob( $row->page_restrictions );
92 # Update restrictions table
93 foreach ( $restrictionsByAction as $action => $restrictions ) {
95 'pr_page' => $row->page_id,
97 'pr_level' => $restrictions,
99 'pr_expiry' => $encodedExpiry
116 $dbw->update(
'page', [
'page_restrictions' =>
'' ], [
'page_id' => $pageIds ], __METHOD__ );
120 $batchMinPageId = $batchMaxPageId;
121 }
while ( $batchMaxPageId < $maxPageId );
123 $this->
output(
"...Done!\n" );
135 private function mapLegacyRestrictionBlob( $legacyBlob ) {
136 $oldRestrictions = [];
138 foreach ( explode(
':', trim( $legacyBlob ) ) as $restrict ) {
139 $temp = explode(
'=', trim( $restrict ) );
142 if ( count( $temp ) == 1 ) {
143 $level = trim( $temp[0] );
145 $oldRestrictions[
'edit'] = $level;
146 $oldRestrictions[
'move'] = $level;
148 $restriction = trim( $temp[1] );
150 if ( $restriction !=
'' ) {
151 $oldRestrictions[$temp[0]] = $restriction;
156 return $oldRestrictions;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
beginTransaction(IDatabase $dbw, $fname)
Begin a transaction on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transaction on a DB handle and wait for replica DBs to catch up.
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.