Merge "API to fetch data about stashed images"
[lhc/web/wiklou.git] / includes / deferred / CdnCacheUpdate.php
index eb54bc2..9f7d8ca 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Squid cache purging.
+ * CDN cache purging.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@
 use Wikimedia\Assert\Assert;
 
 /**
- * Handles purging appropriate Squid URLs given a title (or titles)
+ * Handles purging appropriate CDN URLs given a title (or titles)
  * @ingroup Cache
  */
 class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
@@ -38,6 +38,13 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
                $this->urls = $urlArr;
        }
 
+       public function merge( MergeableUpdate $update ) {
+               /** @var CdnCacheUpdate $update */
+               Assert::parameterType( __CLASS__, $update, '$update' );
+
+               $this->urls = array_merge( $this->urls, $update->urls );
+       }
+
        /**
         * Create an update object from an array of Title objects, or a TitleArray object
         *
@@ -48,7 +55,7 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
        public static function newFromTitles( $titles, $urlArr = array() ) {
                /** @var Title $title */
                foreach ( $titles as $title ) {
-                       $urlArr = array_merge( $urlArr, $title->getSquidURLs() );
+                       $urlArr = array_merge( $urlArr, $title->getCdnUrls() );
                }
 
                return new CdnCacheUpdate( $urlArr );
@@ -60,28 +67,32 @@ class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
         * @deprecated 1.27
         */
        public static function newSimplePurge( Title $title ) {
-               return new CdnCacheUpdate( $title->getSquidURLs() );
+               return new CdnCacheUpdate( $title->getCdnUrls() );
        }
 
        /**
         * Purges the list of URLs passed to the constructor.
         */
        public function doUpdate() {
-               self::purge( $this->urls );
-       }
+               global $wgCdnReboundPurgeDelay;
 
-       public function merge( MergeableUpdate $update ) {
-               /** @var CdnCacheUpdate $update */
-               Assert::parameterType( __CLASS__, $update, '$update' );
+               self::purge( $this->urls );
 
-               $this->urls = array_merge( $this->urls, $update->urls );
+               if ( $wgCdnReboundPurgeDelay > 0 ) {
+                       JobQueueGroup::singleton()->lazyPush( new CdnPurgeJob(
+                               Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __CLASS__ ),
+                               array(
+                                       'urls' => $this->urls,
+                                       'jobReleaseTimestamp' => time() + $wgCdnReboundPurgeDelay
+                               )
+                       ) );
+               }
        }
 
        /**
-        * Purges a list of Squids defined in $wgSquidServers.
+        * Purges a list of CDN nodes defined in $wgSquidServers.
         * $urlArr should contain the full URLs to purge as values
         * (example: $urlArr[] = 'http://my.host/something')
-        * XXX report broken Squids per mail or log
         *
         * @param string[] $urlArr List of full URLs to purge
         */