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() . "\n" ); } // rollback remaining transactions while ( count( $open_transactions ) > 0 ) { $trans = array_pop( $open_transactions ); $trans->rollbackTransaction(); } if ( $exception ) { throw $exception; // rethrow after cleanup } } /** * Enqueue jobs for every DataUpdate that support enqueueUpdate() * and return the remaining DataUpdate objects (those that do not) * * @param DataUpdate[] $updates A list of DataUpdate instances * @return DataUpdate[] * @since 1.26 */ protected static function enqueueUpdates( array $updates ) { $remaining = array(); foreach ( $updates as $update ) { if ( $update instanceof EnqueueableDataUpdate ) { $update->enqueueUpdate(); } else { $remaining[] = $update; } } return $remaining; } } /** * @since 1.26 */ interface EnqueueableDataUpdate { /** * Push the update into the job queue */ public function enqueueUpdate(); }