Krenair

OS migration script changes v4

Dec 21st, 2012
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.87 KB | None | 0 0
  1. diff --git a/migrateToRevDel.php b/migrateToRevDel.php
  2. index 4722106..d5062f7 100644
  3. --- a/migrateToRevDel.php
  4. +++ b/migrateToRevDel.php
  5. @@ -49,14 +49,18 @@ class MigrateOversightRevisions extends Maintenance {
  6.                 foreach ( $hiddenRows as $hiddenRow ) {
  7.                         $insertData = array();
  8.  
  9. -                       $pageExistsQuery = $dbw->selectRow(
  10. -                               'page',
  11. -                               'page_id',
  12. -                               array( 'page_id' => $hiddenRow->hidden_page )
  13. -                       );
  14. +                       $pageExists = Revision::newFromPageId( $hiddenRow->hidden_page ) != null;
  15. +                       if (
  16. +                               $pageExists &&
  17. +                               Revision::newFromPageId( $hiddenRow->hidden_page )->getTimestamp()
  18. +                               <
  19. +                               wfTimestamp( TS_MW, $hiddenRow->hidden_timestamp )
  20. +                       ) {
  21. +                               $this->output( "Warning: Revision ID {$hiddenRow->hidden_rev_id} will end up as the latest revision on
  22. +                       }
  23.  
  24. -                       $fieldPrefix = $pageExistsQuery ? 'rev_' : 'ar_';
  25. -                       $tableName = $pageExistsQuery ? 'revision' : 'archive';
  26. +                       $fieldPrefix = $pageExists ? 'rev_' : 'ar_';
  27. +                       $tableName = $pageExists ? 'revision' : 'archive';
  28.  
  29.                         $revIdFieldName = ( $tableName == 'archive' ? 'ar_' : '' ) . 'rev_id';
  30.                         $pageIdFieldName = $fieldPrefix . 'page' . ( $tableName == 'archive' ? '_id' : '' );
  31. @@ -79,26 +83,62 @@ class MigrateOversightRevisions extends Maintenance {
  32.                         $insertData[$fieldPrefix . 'len'] = strlen( $revText );
  33.                         $insertData[$fieldPrefix . 'sha1'] = Revision::base36Sha1( $revText );
  34.  
  35. -                       $parentIdLookupConditions = array(
  36. -                               $pageIdFieldName => $hiddenRow->hidden_page,
  37. -                               $fieldPrefix . 'timestamp' => $hiddenRow->hidden_timestamp,
  38. -                               $revIdFieldName . ' < ' . $hiddenRow->hidden_rev_id
  39. -                       );
  40. -
  41.                         if ( $tableName == 'archive' ) {
  42. -                               $parentIdLookupConditions['ar_namespace'] = $hiddenRow->hidden_namespace;
  43. -                               $parentIdLookupConditions['ar_title'] = $hiddenRow->hidden_title;
  44. +                               $insertData['ar_parent_id'] = null;
  45.                                 $insertData['ar_namespace'] = $hiddenRow->hidden_namespace;
  46.                                 $insertData['ar_title'] = $hiddenRow->hidden_title;
  47. +                       } else {
  48. +                               $parentIdFromTables = array(
  49. +                                       $dbw->selectRow(
  50. +                                               'revision',
  51. +                                               array( 'rev_id', 'rev_timestamp AS timestamp' ),
  52. +                                               array(
  53. +                                                       'rev_page' => $hiddenRow->hidden_page,
  54. +                                                       'rev_timestamp < ' . $hiddenRow->hidden_timestamp,
  55. +                                                       'rev_id < ' . $hiddenRow->hidden_rev_id
  56. +                                               ),
  57. +                                               array( 'ORDER BY' => 'rev_timestamp DESC' )
  58. +                                       ),
  59. +                                       $dbw->selectRow(
  60. +                                               'hidden',
  61. +                                               array( 'hidden_rev_id AS rev_id', 'hidden_timestamp AS timestamp' ),
  62. +                                               array(
  63. +                                                       'hidden_page' => $hiddenRow->hidden_page,
  64. +                                                       'hidden_timestamp < ' . $hiddenRow->hidden_timestamp,
  65. +                                                       'hidden_rev_id < ' . $hiddenRow->hidden_rev_id
  66. +                                               ),
  67. +                                               $options = array( 'ORDER BY' => 'hidden_timestamp DESC' )
  68. +                                       ),
  69. +                                       $dbw->selectRow(
  70. +                                               'archive',
  71. +                                               array( 'ar_rev_id AS rev_id', 'ar_timestamp AS timestamp' ),
  72. +                                               array(
  73. +                                                       'ar_page_id' => $hiddenRow->hidden_page,
  74. +                                                       'ar_timestamp < ' . $hiddenRow->hidden_timestamp,
  75. +                                                       'ar_rev_id < ' . $hiddenRow->hidden_rev_id,
  76. +                                                       'ar_namespace' => $hiddenRow->hidden_namespace,
  77. +                                                       'ar_title' => $hiddenRow->hidden_title
  78. +                                               ),
  79. +                                               array( 'ORDER BY' => 'ar_timestamp DESC' )
  80. +                                       )
  81. +                               );
  82. +
  83. +                               $timestampsToRevIds = array();
  84. +                               foreach ( $parentIdFromTables as $parentIdFromTable ) {
  85. +                                       if ( $parentIdFromTable != false ) {
  86. +                                               $timestampsToRevIds[$parentIdFromTable->timestamp] = $parentIdFromTable->rev_id;
  87. +                                       }
  88. +                               }
  89. +
  90. +                               if ( count( $timestampsToRevIds ) == 0 ) {
  91. +                                       $insertData['rev_parent_id'] = 0;
  92. +                                       $this->output( "Warning: There may be an issue with revision ID {$hiddenRow->hidden_rev_id}. I
  93. +                               } else {
  94. +                                       $highestTimestamp = max( array_keys( $timestampsToRevIds ) );
  95. +                                       $insertData['rev_parent_id'] = $timestampsToRevIds[$highestTimestamp];
  96. +                               }
  97.                         }
  98.  
  99. -                       $insertData[$fieldPrefix . 'parent_id'] = $dbw->selectField(
  100. -                               $tableName,
  101. -                               $revIdFieldName,
  102. -                               $parentIdLookupConditions,
  103. -                               $options = array( 'LIMIT' => 1, 'ORDER BY' => $revIdFieldName )
  104. -                       );
  105. -
  106.                         $dbw->insert( $tableName, $insertData, __METHOD__ );
  107.  
  108.                         $dbw->insert( 'logging', array(
Advertisement
Add Comment
Please, Sign In to add comment