MediaWiki  REL1_24
DataUpdate.php
Go to the documentation of this file.
00001 <?php
00032 abstract class DataUpdate implements DeferrableUpdate {
00036     public function __construct() {
00037         # noop
00038     }
00039 
00044     public function beginTransaction() {
00045         //noop
00046     }
00047 
00052     public function commitTransaction() {
00053         //noop
00054     }
00055 
00060     public function rollbackTransaction() {
00061         //noop
00062     }
00063 
00079     public static function runUpdates( $updates ) {
00080         if ( empty( $updates ) ) {
00081             return; # nothing to do
00082         }
00083 
00084         $open_transactions = array();
00085         $exception = null;
00086 
00092         try {
00093             // begin transactions
00094             foreach ( $updates as $update ) {
00095                 $update->beginTransaction();
00096                 $open_transactions[] = $update;
00097             }
00098 
00099             // do work
00100             foreach ( $updates as $update ) {
00101                 $update->doUpdate();
00102             }
00103 
00104             // commit transactions
00105             while ( count( $open_transactions ) > 0 ) {
00106                 $trans = array_pop( $open_transactions );
00107                 $trans->commitTransaction();
00108             }
00109         } catch ( Exception $ex ) {
00110             $exception = $ex;
00111             wfDebug( "Caught exception, will rethrow after rollback: " .
00112                 $ex->getMessage() . "\n" );
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 }