MediaWiki  REL1_22
DataUpdate.php
Go to the documentation of this file.
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 ) ) {
00082             return; # nothing to do
00083         }
00084 
00085         $open_transactions = array();
00086         $exception = null;
00087 
00093         try {
00094             // begin transactions
00095             foreach ( $updates as $update ) {
00096                 $update->beginTransaction();
00097                 $open_transactions[] = $update;
00098             }
00099 
00100             // do work
00101             foreach ( $updates as $update ) {
00102                 $update->doUpdate();
00103             }
00104 
00105             // commit transactions
00106             while ( count( $open_transactions ) > 0 ) {
00107                 $trans = array_pop( $open_transactions );
00108                 $trans->commitTransaction();
00109             }
00110         } catch ( Exception $ex ) {
00111             $exception = $ex;
00112             wfDebug( "Caught exception, will rethrow after rollback: " . $ex->getMessage() );
00113         }
00114 
00115         // rollback remaining transactions
00116         while ( count( $open_transactions ) > 0 ) {
00117             $trans = array_pop( $open_transactions );
00118             $trans->rollbackTransaction();
00119         }
00120 
00121         if ( $exception ) {
00122             throw $exception; // rethrow after cleanup
00123         }
00124     }
00125 
00126 }