MediaWiki
REL1_20
|
00001 <?php 00032 abstract class DataUpdate implements DeferrableUpdate { 00033 00037 public function __construct( ) { 00038 # noop 00039 } 00040 00045 public function beginTransaction() { 00046 //noop 00047 } 00048 00053 public function commitTransaction() { 00054 //noop 00055 } 00056 00061 public function rollbackTransaction() { 00062 //noop 00063 } 00064 00080 public static function runUpdates( $updates ) { 00081 if ( empty( $updates ) ) return; # nothing to do 00082 00083 $open_transactions = array(); 00084 $exception = null; 00085 00091 try { 00092 // begin transactions 00093 foreach ( $updates as $update ) { 00094 $update->beginTransaction(); 00095 $open_transactions[] = $update; 00096 } 00097 00098 // do work 00099 foreach ( $updates as $update ) { 00100 $update->doUpdate(); 00101 } 00102 00103 // commit transactions 00104 while ( count( $open_transactions ) > 0 ) { 00105 $trans = array_pop( $open_transactions ); 00106 $trans->commitTransaction(); 00107 } 00108 } catch ( Exception $ex ) { 00109 $exception = $ex; 00110 wfDebug( "Caught exception, will rethrow after rollback: " . $ex->getMessage() ); 00111 } 00112 00113 // rollback remaining transactions 00114 while ( count( $open_transactions ) > 0 ) { 00115 $trans = array_pop( $open_transactions ); 00116 $trans->rollbackTransaction(); 00117 } 00118 00119 if ( $exception ) { 00120 throw $exception; // rethrow after cleanup 00121 } 00122 } 00123 00124 }