46 $batchSize = $this->getBatchSize();
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
107 $this->beginTransaction( $dbw, __METHOD__ );
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__ )
125 $this->commitTransaction( $dbw, __METHOD__ );
127 $batchMinPageId = $batchMaxPageId;
128 }
while ( $batchMaxPageId < $maxPageId );
130 $this->output(
"...Done!\n" );