MediaWiki  REL1_20
DeferredUpdates.php
Go to the documentation of this file.
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 doUpdates( $commit = '' ) {
00073                 global $wgDeferredUpdateList;
00074 
00075                 wfProfileIn( __METHOD__ );
00076 
00077                 $updates = array_merge( $wgDeferredUpdateList, self::$updates );
00078 
00079                 // No need to get master connections in case of empty updates array
00080                 if ( !count( $updates ) ) {
00081                         wfProfileOut( __METHOD__ );
00082                         return;
00083                 }
00084 
00085                 $doCommit = $commit == 'commit';
00086                 if ( $doCommit ) {
00087                         $dbw = wfGetDB( DB_MASTER );
00088                 }
00089 
00090                 foreach ( $updates as $update ) {
00091                         try {
00092                                 $update->doUpdate();
00093 
00094                                 if ( $doCommit && $dbw->trxLevel() ) {
00095                                         $dbw->commit( __METHOD__ );
00096                                 }
00097                         } catch ( MWException $e ) {
00098                                 // We don't want exceptions thrown during deferred updates to
00099                                 // be reported to the user since the output is already sent.
00100                                 // Instead we just log them.
00101                                 if ( !$e instanceof ErrorPageError ) {
00102                                         wfDebugLog( 'exception', $e->getLogMessage() );
00103                                 }
00104                         }
00105                 }
00106 
00107                 self::clearPendingUpdates();
00108                 wfProfileOut( __METHOD__ );
00109         }
00110 
00115         public static function clearPendingUpdates() {
00116                 global $wgDeferredUpdateList;
00117                 $wgDeferredUpdateList = self::$updates = array();
00118         }
00119 }