MediaWiki  REL1_19
DeferredUpdates.php
Go to the documentation of this file.
00001 <?php
00008 interface DeferrableUpdate {
00012         function doUpdate();
00013 }
00014 
00020 class DeferredUpdates {
00024         private static $updates = array();
00025 
00030         public static function addUpdate( DeferrableUpdate $update ) {
00031                 array_push( self::$updates, $update );
00032         }
00033 
00041         public static function addHTMLCacheUpdate( $title, $table ) {
00042                 self::addUpdate( new HTMLCacheUpdate( $title, $table ) );
00043         }
00044 
00051         public static function doUpdates( $commit = '' ) {
00052                 global $wgDeferredUpdateList;
00053 
00054                 wfProfileIn( __METHOD__ );
00055 
00056                 $updates = array_merge( $wgDeferredUpdateList, self::$updates );
00057 
00058                 // No need to get master connections in case of empty updates array
00059                 if ( !count( $updates ) ) {
00060                         wfProfileOut( __METHOD__ );
00061                         return;
00062                 }
00063 
00064                 $doCommit = $commit == 'commit';
00065                 if ( $doCommit ) {
00066                         $dbw = wfGetDB( DB_MASTER );
00067                 }
00068 
00069                 foreach ( $updates as $update ) {
00070                         $update->doUpdate();
00071 
00072                         if ( $doCommit && $dbw->trxLevel() ) {
00073                                 $dbw->commit( __METHOD__ );
00074                         }
00075                 }
00076 
00077                 self::clearPendingUpdates();
00078                 wfProfileOut( __METHOD__ );
00079         }
00080 
00085         public static function clearPendingUpdates() {
00086                 global $wgDeferredUpdateList;
00087                 $wgDeferredUpdateList = self::$updates = array();
00088         }
00089 }