16require_once __DIR__ .
'/Maintenance.php';
27 parent::__construct();
28 $this->
addDescription(
'Updates page_restrictions table from old page_restriction column' );
37 if ( !$dbw->tableExists(
'page_restrictions', __METHOD__ ) ) {
38 $this->
fatalError(
"page_restrictions table does not exist" );
41 if ( !$dbw->fieldExists(
'page',
'page_restrictions', __METHOD__ ) ) {
42 $this->
output(
"Migration is not needed.\n" );
46 $encodedExpiry = $dbw->getInfinity();
48 $maxPageId = $dbw->newSelectQueryBuilder()
49 ->select(
'MAX(page_id)' )
51 ->caller( __METHOD__ )->fetchField();
56 $batchMaxPageId = $batchMinPageId + $batchSize;
58 $this->
output(
"...processing page IDs from $batchMinPageId to $batchMaxPageId.\n" );
60 $res = $dbw->newSelectQueryBuilder()
61 ->select( [
'page_id',
'page_restrictions' ] )
64 $dbw->expr(
'page_restrictions',
'!=',
'' ),
65 $dbw->expr(
'page_id',
'>', $batchMinPageId ),
66 $dbw->expr(
'page_id',
'<=', $batchMaxPageId ),
68 ->caller( __METHOD__ )->fetchResultSet();
71 if ( !$res->numRows() ) {
72 $batchMinPageId = $batchMaxPageId;
79 foreach ( $res as $row ) {
80 $pageIds[] = $row->page_id;
82 $restrictionsByAction = $this->mapLegacyRestrictionBlob( $row->page_restrictions );
84 # Update restrictions table
85 foreach ( $restrictionsByAction as $action => $restrictions ) {
87 'pr_page' => $row->page_id,
89 'pr_level' => $restrictions,
91 'pr_expiry' => $encodedExpiry
100 $dbw->newInsertQueryBuilder()
101 ->insertInto(
'page_restrictions' )
104 ->caller( __METHOD__ )->execute();
107 $dbw->newUpdateQueryBuilder()
109 ->set( [
'page_restrictions' =>
'' ] )
110 ->where( [
'page_id' => $pageIds ] )
111 ->caller( __METHOD__ )
116 $batchMinPageId = $batchMaxPageId;
117 }
while ( $batchMaxPageId < $maxPageId );
119 $this->
output(
"...Done!\n" );
131 private function mapLegacyRestrictionBlob( $legacyBlob ) {
132 $oldRestrictions = [];
134 foreach ( explode(
':', trim( $legacyBlob ) ) as $restrict ) {
135 $temp = explode(
'=', trim( $restrict ) );
138 if ( count( $temp ) == 1 ) {
139 $level = trim( $temp[0] );
141 $oldRestrictions[
'edit'] = $level;
142 $oldRestrictions[
'move'] = $level;
144 $restriction = trim( $temp[1] );
146 if ( $restriction !=
'' ) {
147 $oldRestrictions[$temp[0]] = $restriction;
152 return $oldRestrictions;
163require_once RUN_MAINTENANCE_IF_MAIN;
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
addDescription( $text)
Set the description text.
Maintenance script that updates page_restrictions table from old page_restriction column.
doDBUpdates()
Do the actual work.All child classes will need to implement this. Return true to log the update as do...
getUpdateKey()
Get the update key name to go in the update log table.string
__construct()
Default constructor.
Update the CREDITS list by merging in the list of git commit authors.