From 64060bea46c42de6d09a2f8da3be552e3e0e85e9 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 21 Sep 2016 09:47:34 -0700 Subject: [PATCH] Split out new ObjectCache::newWANCacheFromParams() method Change-Id: Ib2e409dd129bd1e2871fe239e71a4eb8fb42944c --- includes/objectcache/ObjectCache.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 14809a87e2..d81f9e13cb 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -321,23 +321,41 @@ class ObjectCache { * @since 1.26 * @param string $id A key in $wgWANObjectCaches. * @return WANObjectCache - * @throws InvalidArgumentException + * @throws UnexpectedValueException */ public static function newWANCacheFromId( $id ) { - global $wgWANObjectCaches; + global $wgWANObjectCaches, $wgObjectCaches; if ( !isset( $wgWANObjectCaches[$id] ) ) { - throw new InvalidArgumentException( "Invalid object cache type \"$id\" requested. " . - "It is not present in \$wgWANObjectCaches." ); + throw new UnexpectedValueException( + "Cache type \"$id\" requested is not present in \$wgWANObjectCaches." ); } $params = $wgWANObjectCaches[$id]; + if ( !isset( $wgObjectCaches[$params['cacheId']] ) ) { + throw new UnexpectedValueException( + "Cache type \"{$params['cacheId']}\" is not present in \$wgObjectCaches." ); + } + $params['store'] = $wgObjectCaches[$params['cacheId']]; + + return self::newWANCacheFromParams( $params ); + } + + /** + * Create a new cache object of the specified type. + * + * @since 1.28 + * @param array $params + * @return WANObjectCache + * @throws UnexpectedValueException + */ + public static function newWANCacheFromParams( array $params ) { foreach ( $params['channels'] as $action => $channel ) { $params['relayers'][$action] = MediaWikiServices::getInstance()->getEventRelayerGroup() ->getRelayer( $channel ); $params['channels'][$action] = $channel; } - $params['cache'] = self::newFromId( $params['cacheId'] ); + $params['cache'] = self::newFromParams( $params['store'] ); if ( isset( $params['loggroup'] ) ) { $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] ); } else { -- 2.20.1