r40923 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40922‎ | r40923 | r40924 >
Date:18:45, 16 September 2008
Author:aaron
Status:old
Tags:
Comment:
* Add transaction to undelete
* Avoid some dupe key errors. They should silently be corrected. (bug 14149)
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -412,7 +412,7 @@
413413 # we'll update the latest revision field in the record.
414414 $newid = 0;
415415 $pageId = $page->page_id;
416 - $previousRevId = $page->page_latest;
 416+ $previousRevId = $page->page_latest;
417417 # Get the time span of this page
418418 $previousTimestamp = $dbw->selectField( 'revision', 'rev_timestamp',
419419 array( 'rev_id' => $previousRevId ),
@@ -481,6 +481,7 @@
482482 $ret->seek( 0 );
483483 }
484484
 485+ $dbw->begin();
485486 if( $makepage ) {
486487 $newid = $article->insertOn( $dbw );
487488 $pageId = $newid;
@@ -502,6 +503,12 @@
503504 // a new text table entry will be created for it.
504505 $revText = Revision::getRevisionText( $row, 'ar_' );
505506 }
 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+
506513 $revision = new Revision( array(
507514 'page' => $pageId,
508515 'id' => $row->ar_rev_id,
@@ -520,8 +527,16 @@
521528
522529 wfRunHooks( 'ArticleRevisionUndeleted', array( &$this->title, $revision, $row->ar_page_id ) );
523530 }
 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+
524539 // Was anything restored at all?
525 - if($restored == 0)
 540+ if( $restored == 0 )
526541 return 0;
527542
528543 if( $revision ) {
@@ -550,14 +565,7 @@
551566 return self::UNDELETE_UNKNOWNERR;
552567 }
553568
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();
562570 return $restored;
563571 }
564572