X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdeferred%2FDeferredUpdates.php;h=8b3582db69e59b4048f1eb84b112cba0af363181;hb=ccab8f10f67e4d733a12118c5c18e5afa7af451c;hp=cd0266f6b86da96ca321268363d1142a771ecafa;hpb=e491904eef6614ee2d6e37c4d430482662343223;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/deferred/DeferredUpdates.php b/includes/deferred/DeferredUpdates.php index cd0266f6b8..8b3582db69 100644 --- a/includes/deferred/DeferredUpdates.php +++ b/includes/deferred/DeferredUpdates.php @@ -44,10 +44,10 @@ interface DeferrableUpdate { * @since 1.19 */ class DeferredUpdates { - /** - * @var array Updates to be deferred until the end of the request. - */ + /** @var DeferrableUpdate[] Updates to be deferred until the end of the request */ private static $updates = array(); + /** @var bool Defer updates fully even in CLI mode */ + private static $forceDeferral = false; /** * Add an update to the deferred list @@ -57,6 +57,9 @@ class DeferredUpdates { global $wgCommandLineMode; array_push( self::$updates, $update ); + if ( self::$forceDeferral ) { + return; + } // CLI scripts may forget to periodically flush these updates, // so try to handle that rather than OOMing and losing them. @@ -99,9 +102,22 @@ class DeferredUpdates { while ( count( $updates ) ) { self::clearPendingUpdates(); - - /** @var DeferrableUpdate $update */ + /** @var DataUpdate[] $dataUpdates */ + $dataUpdates = array(); + /** @var DeferrableUpdate[] $otherUpdates */ + $otherUpdates = array(); foreach ( $updates as $update ) { + if ( $update instanceof DataUpdate ) { + $dataUpdates[] = $update; + } else { + $otherUpdates[] = $update; + } + } + + // Delegate DataUpdate execution to the DataUpdate class + DataUpdate::runUpdates( $dataUpdates, 'run' ); + // Execute the non-DataUpdate tasks + foreach ( $otherUpdates as $update ) { try { $update->doUpdate(); @@ -129,4 +145,13 @@ class DeferredUpdates { public static function clearPendingUpdates() { self::$updates = array(); } + + /** + * @note This method is intended for testing purposes + * @param bool $value Whether to *always* defer updates, even in CLI mode + * @since 1.26 + */ + public static function forceDeferral( $value ) { + self::$forceDeferral = $value; + } }