MediaWiki
REL1_22
|
00001 <?php 00029 interface DeferrableUpdate { 00033 function doUpdate(); 00034 } 00035 00041 class DeferredUpdates { 00045 private static $updates = array(); 00046 00051 public static function addUpdate( DeferrableUpdate $update ) { 00052 array_push( self::$updates, $update ); 00053 } 00054 00062 public static function addHTMLCacheUpdate( $title, $table ) { 00063 self::addUpdate( new HTMLCacheUpdate( $title, $table ) ); 00064 } 00065 00072 public static function addCallableUpdate( $callable ) { 00073 self::addUpdate( new MWCallableUpdate( $callable ) ); 00074 } 00075 00082 public static function doUpdates( $commit = '' ) { 00083 global $wgDeferredUpdateList; 00084 00085 wfProfileIn( __METHOD__ ); 00086 00087 $updates = array_merge( $wgDeferredUpdateList, self::$updates ); 00088 00089 // No need to get master connections in case of empty updates array 00090 if ( !count( $updates ) ) { 00091 wfProfileOut( __METHOD__ ); 00092 return; 00093 } 00094 00095 $doCommit = $commit == 'commit'; 00096 if ( $doCommit ) { 00097 $dbw = wfGetDB( DB_MASTER ); 00098 } 00099 00100 foreach ( $updates as $update ) { 00101 try { 00102 $update->doUpdate(); 00103 00104 if ( $doCommit && $dbw->trxLevel() ) { 00105 $dbw->commit( __METHOD__, 'flush' ); 00106 } 00107 } catch ( MWException $e ) { 00108 // We don't want exceptions thrown during deferred updates to 00109 // be reported to the user since the output is already sent. 00110 // Instead we just log them. 00111 if ( !$e instanceof ErrorPageError ) { 00112 MWExceptionHandler::logException( $e ); 00113 } 00114 } 00115 } 00116 00117 self::clearPendingUpdates(); 00118 wfProfileOut( __METHOD__ ); 00119 } 00120 00125 public static function clearPendingUpdates() { 00126 global $wgDeferredUpdateList; 00127 $wgDeferredUpdateList = self::$updates = array(); 00128 } 00129 }