3 * Interface that deferrable updates should implement. Basically required so we
4 * can validate input on DeferredUpdates::addUpdate()
8 interface DeferrableUpdate
{
10 * Perform the actual work
16 * Class for mananging the deferred updates.
20 class DeferredUpdates
{
22 * Store of updates to be deferred until the end of the request.
24 private static $updates = array();
27 * Add an update to the deferred list
28 * @param $update DeferrableUpdate Some object that implements doUpdate()
30 public static function addUpdate( DeferrableUpdate
$update ) {
31 array_push( self
::$updates, $update );
35 * HTMLCacheUpdates are the most common deferred update people use. This
36 * is a shortcut method for that.
37 * @see HTMLCacheUpdate::__construct()
41 public static function addHTMLCacheUpdate( $title, $table ) {
42 self
::addUpdate( new HTMLCacheUpdate( $title, $table ) );
46 * Do any deferred updates and clear the list
48 * @param $commit String: set to 'commit' to commit after every update to
49 * prevent lock contention
51 public static function doUpdates( $commit = '' ) {
52 global $wgDeferredUpdateList;
54 wfProfileIn( __METHOD__
);
56 $updates = array_merge( $wgDeferredUpdateList, self
::$updates );
58 // No need to get master connections in case of empty updates array
59 if ( !count( $updates ) ) {
60 wfProfileOut( __METHOD__
);
64 $doCommit = $commit == 'commit';
66 $dbw = wfGetDB( DB_MASTER
);
69 foreach ( $updates as $update ) {
72 if ( $doCommit && $dbw->trxLevel() ) {
73 $dbw->commit( __METHOD__
);
77 self
::clearPendingUpdates();
78 wfProfileOut( __METHOD__
);
82 * Clear all pending updates without performing them. Generally, you don't
83 * want or need to call this. Unit tests need it though.
85 public static function clearPendingUpdates() {
86 global $wgDeferredUpdateList;
87 $wgDeferredUpdateList = self
::$updates = array();