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->newSelectQueryBuilder()
58 ->select(
'MAX(page_id)' )
60 ->caller( __METHOD__ )->fetchField();
65 $batchMaxPageId = $batchMinPageId + $batchSize;
67 $this->
output(
"...processing page IDs from $batchMinPageId to $batchMaxPageId.\n" );
69 $res = $dbw->newSelectQueryBuilder()
70 ->select( [
'page_id',
'page_restrictions' ] )
73 $dbw->expr(
'page_restrictions',
'!=',
'' ),
74 $dbw->expr(
'page_id',
'>', $batchMinPageId ),
75 $dbw->expr(
'page_id',
'<=', $batchMaxPageId ),
77 ->caller( __METHOD__ )->fetchResultSet();
80 if ( !$res->numRows() ) {
81 $batchMinPageId = $batchMaxPageId;
88 foreach ( $res as $row ) {
89 $pageIds[] = $row->page_id;
91 $restrictionsByAction = $this->mapLegacyRestrictionBlob( $row->page_restrictions );
93 # Update restrictions table
94 foreach ( $restrictionsByAction as $action => $restrictions ) {
96 'pr_page' => $row->page_id,
98 'pr_level' => $restrictions,
100 'pr_expiry' => $encodedExpiry
109 $dbw->newInsertQueryBuilder()
110 ->insertInto(
'page_restrictions' )
113 ->caller( __METHOD__ )->execute();
116 $dbw->newUpdateQueryBuilder()
118 ->set( [
'page_restrictions' =>
'' ] )
119 ->where( [
'page_id' => $pageIds ] )
120 ->caller( __METHOD__ )
125 $batchMinPageId = $batchMaxPageId;
126 }
while ( $batchMaxPageId < $maxPageId );
128 $this->
output(
"...Done!\n" );
140 private function mapLegacyRestrictionBlob( $legacyBlob ) {
141 $oldRestrictions = [];
143 foreach ( explode(
':', trim( $legacyBlob ) ) as $restrict ) {
144 $temp = explode(
'=', trim( $restrict ) );
147 if ( count( $temp ) == 1 ) {
148 $level = trim( $temp[0] );
150 $oldRestrictions[
'edit'] = $level;
151 $oldRestrictions[
'move'] = $level;
153 $restriction = trim( $temp[1] );
155 if ( $restriction !=
'' ) {
156 $oldRestrictions[$temp[0]] = $restriction;
161 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.