39 parent::__construct();
40 $this->
addDescription(
'Updates page_restrictions table from old page_restriction column' );
48 if ( !$dbw->tableExists(
'page_restrictions', __METHOD__ ) ) {
49 $this->
fatalError(
"page_restrictions table does not exist" );
52 if ( !$dbw->fieldExists(
'page',
'page_restrictions', __METHOD__ ) ) {
53 $this->
output(
"Migration is not needed.\n" );
57 $encodedExpiry = $dbw->getInfinity();
59 $maxPageId = $dbw->newSelectQueryBuilder()
60 ->select(
'MAX(page_id)' )
62 ->caller( __METHOD__ )->fetchField();
67 $batchMaxPageId = $batchMinPageId + $batchSize;
69 $this->
output(
"...processing page IDs from $batchMinPageId to $batchMaxPageId.\n" );
71 $res = $dbw->newSelectQueryBuilder()
72 ->select( [
'page_id',
'page_restrictions' ] )
75 $dbw->expr(
'page_restrictions',
'!=',
'' ),
76 $dbw->expr(
'page_id',
'>', $batchMinPageId ),
77 $dbw->expr(
'page_id',
'<=', $batchMaxPageId ),
79 ->caller( __METHOD__ )->fetchResultSet();
82 if ( !$res->numRows() ) {
83 $batchMinPageId = $batchMaxPageId;
90 foreach ( $res as $row ) {
91 $pageIds[] = $row->page_id;
93 $restrictionsByAction = $this->mapLegacyRestrictionBlob( $row->page_restrictions );
95 # Update restrictions table
96 foreach ( $restrictionsByAction as $action => $restrictions ) {
98 'pr_page' => $row->page_id,
100 'pr_level' => $restrictions,
102 'pr_expiry' => $encodedExpiry
111 $dbw->newInsertQueryBuilder()
112 ->insertInto(
'page_restrictions' )
115 ->caller( __METHOD__ )->execute();
118 $dbw->newUpdateQueryBuilder()
120 ->set( [
'page_restrictions' =>
'' ] )
121 ->where( [
'page_id' => $pageIds ] )
122 ->caller( __METHOD__ )
127 $batchMinPageId = $batchMaxPageId;
128 }
while ( $batchMaxPageId < $maxPageId );
130 $this->
output(
"...Done!\n" );
142 private function mapLegacyRestrictionBlob( $legacyBlob ) {
143 $oldRestrictions = [];
145 foreach ( explode(
':', trim( $legacyBlob ) ) as $restrict ) {
146 $temp = explode(
'=', trim( $restrict ) );
149 if ( count( $temp ) == 1 ) {
150 $level = trim( $temp[0] );
152 $oldRestrictions[
'edit'] = $level;
153 $oldRestrictions[
'move'] = $level;
155 $restriction = trim( $temp[1] );
157 if ( $restriction !=
'' ) {
158 $oldRestrictions[$temp[0]] = $restriction;
163 return $oldRestrictions;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
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.