Index: trunk/phase3/includes/specials/SpecialUndelete.php |
— | — | @@ -412,7 +412,7 @@ |
413 | 413 | # we'll update the latest revision field in the record. |
414 | 414 | $newid = 0; |
415 | 415 | $pageId = $page->page_id; |
416 | | - $previousRevId = $page->page_latest; |
| 416 | + $previousRevId = $page->page_latest; |
417 | 417 | # Get the time span of this page |
418 | 418 | $previousTimestamp = $dbw->selectField( 'revision', 'rev_timestamp', |
419 | 419 | array( 'rev_id' => $previousRevId ), |
— | — | @@ -481,6 +481,7 @@ |
482 | 482 | $ret->seek( 0 ); |
483 | 483 | } |
484 | 484 | |
| 485 | + $dbw->begin(); |
485 | 486 | if( $makepage ) { |
486 | 487 | $newid = $article->insertOn( $dbw ); |
487 | 488 | $pageId = $newid; |
— | — | @@ -502,6 +503,12 @@ |
503 | 504 | // a new text table entry will be created for it. |
504 | 505 | $revText = Revision::getRevisionText( $row, 'ar_' ); |
505 | 506 | } |
| 507 | + // Check for key dupes due to shitty archive integrity. |
| 508 | + if( $row->ar_rev_id ) { |
| 509 | + $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ ); |
| 510 | + if( $exists ) continue; // don't throw DB errors |
| 511 | + } |
| 512 | + |
506 | 513 | $revision = new Revision( array( |
507 | 514 | 'page' => $pageId, |
508 | 515 | 'id' => $row->ar_rev_id, |
— | — | @@ -520,8 +527,16 @@ |
521 | 528 | |
522 | 529 | wfRunHooks( 'ArticleRevisionUndeleted', array( &$this->title, $revision, $row->ar_page_id ) ); |
523 | 530 | } |
| 531 | + # Now that it's safely stored, take it out of the archive |
| 532 | + $dbw->delete( 'archive', |
| 533 | + /* WHERE */ array( |
| 534 | + 'ar_namespace' => $this->title->getNamespace(), |
| 535 | + 'ar_title' => $this->title->getDBkey(), |
| 536 | + $oldones ), |
| 537 | + __METHOD__ ); |
| 538 | + |
524 | 539 | // Was anything restored at all? |
525 | | - if($restored == 0) |
| 540 | + if( $restored == 0 ) |
526 | 541 | return 0; |
527 | 542 | |
528 | 543 | if( $revision ) { |
— | — | @@ -550,14 +565,7 @@ |
551 | 566 | return self::UNDELETE_UNKNOWNERR; |
552 | 567 | } |
553 | 568 | |
554 | | - # Now that it's safely stored, take it out of the archive |
555 | | - $dbw->delete( 'archive', |
556 | | - /* WHERE */ array( |
557 | | - 'ar_namespace' => $this->title->getNamespace(), |
558 | | - 'ar_title' => $this->title->getDBkey(), |
559 | | - $oldones ), |
560 | | - __METHOD__ ); |
561 | | - |
| 569 | + $dbw->commit(); |
562 | 570 | return $restored; |
563 | 571 | } |
564 | 572 | |