27 require_once __DIR__ .
'/Maintenance.php';
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();
61 $escapedEmptyBlobValue = $dbw->addQuotes(
'' );
66 $batchMaxPageId = $batchMinPageId + $batchSize;
68 $this->
output(
"...processing page IDs from $batchMinPageId to $batchMaxPageId.\n" );
70 $res = $dbw->newSelectQueryBuilder()
71 ->select( [
'page_id',
'page_restrictions' ] )
74 "page_restrictions != $escapedEmptyBlobValue",
75 'page_id > ' . $dbw->addQuotes( $batchMinPageId ),
76 'page_id <= ' . $dbw->addQuotes( $batchMaxPageId ),
78 ->caller( __METHOD__ )->fetchResultSet();
81 if ( !$res->numRows() ) {
82 $batchMinPageId = $batchMaxPageId;
89 foreach ( $res as $row ) {
90 $pageIds[] = $row->page_id;
92 $restrictionsByAction = $this->mapLegacyRestrictionBlob( $row->page_restrictions );
94 # Update restrictions table
95 foreach ( $restrictionsByAction as $action => $restrictions ) {
97 'pr_page' => $row->page_id,
99 'pr_level' => $restrictions,
101 'pr_expiry' => $encodedExpiry
118 $dbw->update(
'page', [
'page_restrictions' =>
'' ], [
'page_id' => $pageIds ], __METHOD__ );
122 $batchMinPageId = $batchMaxPageId;
123 }
while ( $batchMaxPageId < $maxPageId );
125 $this->
output(
"...Done!\n" );
137 private function mapLegacyRestrictionBlob( $legacyBlob ) {
138 $oldRestrictions = [];
140 foreach ( explode(
':', trim( $legacyBlob ) ) as $restrict ) {
141 $temp = explode(
'=', trim( $restrict ) );
144 if ( count( $temp ) == 1 ) {
145 $level = trim( $temp[0] );
147 $oldRestrictions[
'edit'] = $level;
148 $oldRestrictions[
'move'] = $level;
150 $restriction = trim( $temp[1] );
152 if ( $restriction !=
'' ) {
153 $oldRestrictions[$temp[0]] = $restriction;
158 return $oldRestrictions;
163 require_once RUN_MAINTENANCE_IF_MAIN;
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.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script that updates page_restrictions table from old page_restriction column.
__construct()
Default constructor.
execute()
Do the actual work.