beginTransaction(); $open_transactions[] = $update; } // do work foreach ( $updates as $update ) { $update->doUpdate(); } // commit transactions while ( count( $open_transactions ) > 0 ) { $trans = array_pop( $open_transactions ); $trans->commitTransaction(); } } catch ( Exception $ex ) { $exception = $ex; wfDebug( "Caught exception, will rethrow after rollback: " . $ex->getMessage() ); } // rollback remaining transactions while ( count( $open_transactions ) > 0 ) { $trans = array_pop( $open_transactions ); $trans->rollbackTransaction(); } if ( $exception ) { throw $exception; // rethrow after cleanup } } }