*/
use Wikimedia\Assert\Assert;
+use MediaWiki\MediaWikiServices;
/**
* Handles purging appropriate CDN URLs given a title (or titles)
*/
class CdnCacheUpdate implements DeferrableUpdate, MergeableUpdate {
/** @var string[] Collection of URLs to purge */
- protected $urls = array();
+ protected $urls = [];
/**
* @param string[] $urlArr Collection of URLs to purge
* @param string[] $urlArr
* @return CdnCacheUpdate
*/
- public static function newFromTitles( $titles, $urlArr = array() ) {
+ public static function newFromTitles( $titles, $urlArr = [] ) {
/** @var Title $title */
foreach ( $titles as $title ) {
$urlArr = array_merge( $urlArr, $title->getCdnUrls() );
if ( $wgCdnReboundPurgeDelay > 0 ) {
JobQueueGroup::singleton()->lazyPush( new CdnPurgeJob(
Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __CLASS__ ),
- array(
+ [
'urls' => $this->urls,
'jobReleaseTimestamp' => time() + $wgCdnReboundPurgeDelay
- )
+ ]
) );
}
}
wfDebugLog( 'squid', __METHOD__ . ': ' . implode( ' ', $urlArr ) );
// Reliably broadcast the purge to all edge nodes
- $relayer = EventRelayerGroup::singleton()->getRelayer( 'cdn-url-purges' );
- $relayer->notify(
+ $relayer = MediaWikiServices::getInstance()->getEventRelayerGroup()
+ ->getRelayer( 'cdn-url-purges' );
+ $ts = microtime( true );
+ $relayer->notifyMulti(
'cdn-url-purges',
- array(
- 'urls' => array_values( $urlArr ), // JSON array
- 'timestamp' => microtime( true )
+ array_map(
+ function ( $url ) use ( $ts ) {
+ return [
+ 'url' => $url,
+ 'timestamp' => $ts,
+ ];
+ },
+ $urlArr
)
);
if ( isset( $conf['host'] ) && isset( $conf['port'] ) ) {
// Normalize single entries
- $conf = array( $conf );
+ $conf = [ $conf ];
}
foreach ( $conf as $subconf ) {
if ( !isset( $subconf['host'] ) || !isset( $subconf['port'] ) ) {