Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/migrateToRevDel.php b/migrateToRevDel.php
- index 4722106..d5062f7 100644
- --- a/migrateToRevDel.php
- +++ b/migrateToRevDel.php
- @@ -49,14 +49,18 @@ class MigrateOversightRevisions extends Maintenance {
- foreach ( $hiddenRows as $hiddenRow ) {
- $insertData = array();
- - $pageExistsQuery = $dbw->selectRow(
- - 'page',
- - 'page_id',
- - array( 'page_id' => $hiddenRow->hidden_page )
- - );
- + $pageExists = Revision::newFromPageId( $hiddenRow->hidden_page ) != null;
- + if (
- + $pageExists &&
- + Revision::newFromPageId( $hiddenRow->hidden_page )->getTimestamp()
- + <
- + wfTimestamp( TS_MW, $hiddenRow->hidden_timestamp )
- + ) {
- + $this->output( "Warning: Revision ID {$hiddenRow->hidden_rev_id} will end up as the latest revision on
- + }
- - $fieldPrefix = $pageExistsQuery ? 'rev_' : 'ar_';
- - $tableName = $pageExistsQuery ? 'revision' : 'archive';
- + $fieldPrefix = $pageExists ? 'rev_' : 'ar_';
- + $tableName = $pageExists ? 'revision' : 'archive';
- $revIdFieldName = ( $tableName == 'archive' ? 'ar_' : '' ) . 'rev_id';
- $pageIdFieldName = $fieldPrefix . 'page' . ( $tableName == 'archive' ? '_id' : '' );
- @@ -79,26 +83,62 @@ class MigrateOversightRevisions extends Maintenance {
- $insertData[$fieldPrefix . 'len'] = strlen( $revText );
- $insertData[$fieldPrefix . 'sha1'] = Revision::base36Sha1( $revText );
- - $parentIdLookupConditions = array(
- - $pageIdFieldName => $hiddenRow->hidden_page,
- - $fieldPrefix . 'timestamp' => $hiddenRow->hidden_timestamp,
- - $revIdFieldName . ' < ' . $hiddenRow->hidden_rev_id
- - );
- -
- if ( $tableName == 'archive' ) {
- - $parentIdLookupConditions['ar_namespace'] = $hiddenRow->hidden_namespace;
- - $parentIdLookupConditions['ar_title'] = $hiddenRow->hidden_title;
- + $insertData['ar_parent_id'] = null;
- $insertData['ar_namespace'] = $hiddenRow->hidden_namespace;
- $insertData['ar_title'] = $hiddenRow->hidden_title;
- + } else {
- + $parentIdFromTables = array(
- + $dbw->selectRow(
- + 'revision',
- + array( 'rev_id', 'rev_timestamp AS timestamp' ),
- + array(
- + 'rev_page' => $hiddenRow->hidden_page,
- + 'rev_timestamp < ' . $hiddenRow->hidden_timestamp,
- + 'rev_id < ' . $hiddenRow->hidden_rev_id
- + ),
- + array( 'ORDER BY' => 'rev_timestamp DESC' )
- + ),
- + $dbw->selectRow(
- + 'hidden',
- + array( 'hidden_rev_id AS rev_id', 'hidden_timestamp AS timestamp' ),
- + array(
- + 'hidden_page' => $hiddenRow->hidden_page,
- + 'hidden_timestamp < ' . $hiddenRow->hidden_timestamp,
- + 'hidden_rev_id < ' . $hiddenRow->hidden_rev_id
- + ),
- + $options = array( 'ORDER BY' => 'hidden_timestamp DESC' )
- + ),
- + $dbw->selectRow(
- + 'archive',
- + array( 'ar_rev_id AS rev_id', 'ar_timestamp AS timestamp' ),
- + array(
- + 'ar_page_id' => $hiddenRow->hidden_page,
- + 'ar_timestamp < ' . $hiddenRow->hidden_timestamp,
- + 'ar_rev_id < ' . $hiddenRow->hidden_rev_id,
- + 'ar_namespace' => $hiddenRow->hidden_namespace,
- + 'ar_title' => $hiddenRow->hidden_title
- + ),
- + array( 'ORDER BY' => 'ar_timestamp DESC' )
- + )
- + );
- +
- + $timestampsToRevIds = array();
- + foreach ( $parentIdFromTables as $parentIdFromTable ) {
- + if ( $parentIdFromTable != false ) {
- + $timestampsToRevIds[$parentIdFromTable->timestamp] = $parentIdFromTable->rev_id;
- + }
- + }
- +
- + if ( count( $timestampsToRevIds ) == 0 ) {
- + $insertData['rev_parent_id'] = 0;
- + $this->output( "Warning: There may be an issue with revision ID {$hiddenRow->hidden_rev_id}. I
- + } else {
- + $highestTimestamp = max( array_keys( $timestampsToRevIds ) );
- + $insertData['rev_parent_id'] = $timestampsToRevIds[$highestTimestamp];
- + }
- }
- - $insertData[$fieldPrefix . 'parent_id'] = $dbw->selectField(
- - $tableName,
- - $revIdFieldName,
- - $parentIdLookupConditions,
- - $options = array( 'LIMIT' => 1, 'ORDER BY' => $revIdFieldName )
- - );
- -
- $dbw->insert( $tableName, $insertData, __METHOD__ );
- $dbw->insert( 'logging', array(
Advertisement
Add Comment
Please, Sign In to add comment