30require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
42 $this->
addDescription(
'Updates page_restrictions table from old page_restriction column' );
51 if ( !$dbw->tableExists(
'page_restrictions', __METHOD__ ) ) {
52 $this->
fatalError(
"page_restrictions table does not exist" );
55 if ( !$dbw->fieldExists(
'page',
'page_restrictions', __METHOD__ ) ) {
56 $this->
output(
"Migration is not needed.\n" );
60 $encodedExpiry = $dbw->getInfinity();
62 $maxPageId = $dbw->newSelectQueryBuilder()
63 ->select(
'MAX(page_id)' )
65 ->caller( __METHOD__ )->fetchField();
70 $batchMaxPageId = $batchMinPageId + $batchSize;
72 $this->
output(
"...processing page IDs from $batchMinPageId to $batchMaxPageId.\n" );
74 $res = $dbw->newSelectQueryBuilder()
75 ->select( [
'page_id',
'page_restrictions' ] )
78 $dbw->expr(
'page_restrictions',
'!=',
'' ),
79 $dbw->expr(
'page_id',
'>', $batchMinPageId ),
80 $dbw->expr(
'page_id',
'<=', $batchMaxPageId ),
82 ->caller( __METHOD__ )->fetchResultSet();
85 if ( !$res->numRows() ) {
86 $batchMinPageId = $batchMaxPageId;
93 foreach ( $res as $row ) {
94 $pageIds[] = $row->page_id;
96 $restrictionsByAction = $this->mapLegacyRestrictionBlob( $row->page_restrictions );
98 # Update restrictions table
99 foreach ( $restrictionsByAction as $action => $restrictions ) {
101 'pr_page' => $row->page_id,
102 'pr_type' => $action,
103 'pr_level' => $restrictions,
105 'pr_expiry' => $encodedExpiry
114 $dbw->newInsertQueryBuilder()
115 ->insertInto(
'page_restrictions' )
118 ->caller( __METHOD__ )->execute();
121 $dbw->newUpdateQueryBuilder()
123 ->set( [
'page_restrictions' =>
'' ] )
124 ->where( [
'page_id' => $pageIds ] )
125 ->caller( __METHOD__ )
130 $batchMinPageId = $batchMaxPageId;
131 }
while ( $batchMaxPageId < $maxPageId );
133 $this->
output(
"...Done!\n" );
145 private function mapLegacyRestrictionBlob( $legacyBlob ) {
146 $oldRestrictions = [];
148 foreach ( explode(
':', trim( $legacyBlob ) ) as $restrict ) {
149 $temp = explode(
'=', trim( $restrict ) );
152 if ( count( $temp ) == 1 ) {
153 $level = trim( $temp[0] );
155 $oldRestrictions[
'edit'] = $level;
156 $oldRestrictions[
'move'] = $level;
158 $restriction = trim( $temp[1] );
160 if ( $restriction !=
'' ) {
161 $oldRestrictions[$temp[0]] = $restriction;
166 return $oldRestrictions;
172require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
commitTransaction(IDatabase $dbw, $fname)
Commit the transaction on a DB handle and wait for replica DB servers to catch up.
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.
beginTransaction(IDatabase $dbw, $fname)
Begin a transaction on a DB handle.
addDescription( $text)
Set the description text.
Maintenance script that updates page_restrictions table from old page_restriction column.
__construct()
Default constructor.
execute()
Do the actual work.All child classes will need to implement thisbool|null|void True for success,...