From 7ab928329235451aaa0a813fc16e37cf44d8999a Mon Sep 17 00:00:00 2001 From: Hashar Date: Thu, 29 Sep 2016 08:43:58 +0000 Subject: [PATCH] Revert "Add the main stash, WAN, and server caches to MediaWikiServices" $ php maintenance/eval.php > $wgMessageCacheType = CACHE_ACCEL; > wfGetMessageCacheStorage(); PHP Warning: Illegal offset type in isset or empty in includes/objectcache/ObjectCache.php on line 93 PHP Warning: Illegal offset type in isset or empty in includes/objectcache/ObjectCache.php on line 125 PHP Notice: Array to string conversion in includes/objectcache/ObjectCache.php on line 133 Caught exception InvalidArgumentException: Invalid object cache type "Array" requested. It is not present in $wgObjectCaches. #0 includes/objectcache/ObjectCache.php(94): ObjectCache::newFromId(Array) #1 includes/objectcache/ObjectCache.php(287): ObjectCache::getInstance(Array) #2 [internal function]: ObjectCache::getLocalServerInstance(Array) #3 includes/objectcache/ObjectCache.php(181): call_user_func('ObjectCache::ge...', Array) #4 includes/objectcache/ObjectCache.php(137): ObjectCache::newFromParams(Array) #5 includes/objectcache/ObjectCache.php(94): ObjectCache::newFromId(3) #6 includes/GlobalFunctions.php(3430): ObjectCache::getInstance(3) #7 maintenance/eval.php(78) : eval()'d code(1): wfGetMessageCacheStorage() #8 maintenance/eval.php(78): eval() #9 {main} This reverts commit 6d99fa58247a1de7eaf9a79a061f0b4207154072. Change-Id: I4d756eb6f66318a12d8cbbc1ba546397be8a29bf --- includes/MediaWikiServices.php | 24 --------- includes/ServiceWiring.php | 53 ------------------- includes/objectcache/ObjectCache.php | 31 +++++++---- tests/phpunit/MediaWikiTestCase.php | 4 -- .../includes/MediaWikiServicesTest.php | 7 +-- 5 files changed, 23 insertions(+), 96 deletions(-) diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php index 199472ad20..b16044e12d 100644 --- a/includes/MediaWikiServices.php +++ b/includes/MediaWikiServices.php @@ -589,30 +589,6 @@ class MediaWikiServices extends ServiceContainer { return $this->getService( 'TitleParser' ); } - /** - * @since 1.28 - * @return \BagOStuff - */ - public function getMainObjectStash() { - return $this->getService( 'MainObjectStash' ); - } - - /** - * @since 1.28 - * @return \WANObjectCache - */ - public function getMainWANObjectCache() { - return $this->getService( 'MainWANObjectCache' ); - } - - /** - * @since 1.28 - * @return \BagOStuff - */ - public function getLocalServerObjectCache() { - return $this->getService( 'LocalServerObjectCache' ); - } - /** * @since 1.28 * @return VirtualRESTServiceClient diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 0e4daa6fa7..604491192a 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -218,59 +218,6 @@ return [ return $services->getService( '_MediaWikiTitleCodec' ); }, - 'MainObjectStash' => function( MediaWikiServices $services ) { - $mainConfig = $services->getMainConfig(); - - $id = $mainConfig->get( 'MainStash' ); - if ( !isset( $mainConfig->get( 'ObjectCaches' )[$id] ) ) { - throw new UnexpectedValueException( - "Cache type \"$id\" is not present in \$wgObjectCaches." ); - } - - return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] ); - }, - - 'MainWANObjectCache' => function( MediaWikiServices $services ) { - $mainConfig = $services->getMainConfig(); - - $id = $mainConfig->get( 'MainWANCache' ); - if ( !isset( $mainConfig->get( 'WANObjectCaches' )[$id] ) ) { - throw new UnexpectedValueException( - "WAN cache type \"$id\" is not present in \$wgWANObjectCaches." ); - } - - $params = $mainConfig->get( 'WANObjectCaches' )[$id]; - $objectCacheId = $params['cacheId']; - if ( !isset( $mainConfig->get( 'ObjectCaches' )[$objectCacheId] ) ) { - throw new UnexpectedValueException( - "Cache type \"$objectCacheId\" is not present in \$wgObjectCaches." ); - } - $params['store'] = $mainConfig->get( 'ObjectCaches' )[$objectCacheId]; - - return \ObjectCache::newWANCacheFromParams( $params ); - }, - - 'LocalServerObjectCache' => function( MediaWikiServices $services ) { - $mainConfig = $services->getMainConfig(); - - if ( function_exists( 'apc_fetch' ) ) { - $id = 'apc'; - } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) { - $id = 'xcache'; - } elseif ( function_exists( 'wincache_ucache_get' ) ) { - $id = 'wincache'; - } else { - $id = CACHE_NONE; - } - - if ( !isset( $mainConfig->get( 'ObjectCaches' )[$id] ) ) { - throw new UnexpectedValueException( - "Cache type \"$id\" is not present in \$wgObjectCaches." ); - } - - return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] ); - }, - 'VirtualRESTServiceClient' => function( MediaWikiServices $services ) { $config = $services->getMainConfig()->get( 'VirtualRestConfig' ); diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 0f18479bbd..d81f9e13cb 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -274,18 +274,27 @@ class ObjectCache { * // From $wgObjectCaches via newFromParams() * ObjectCache::getLocalServerInstance( [ 'fallback' => $fallbackType ] ); * - * @param int|string $fallback Fallback cache ID + * @param int|string|array $fallback Fallback cache or parameter map with 'fallback' * @return BagOStuff * @throws InvalidArgumentException * @since 1.27 - * @deprecated Since 1.28; use MediaWikiServices::getLocalServerObjectCache */ public static function getLocalServerInstance( $fallback = CACHE_NONE ) { - $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); + if ( function_exists( 'apc_fetch' ) ) { + $id = 'apc'; + } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) { + $id = 'xcache'; + } elseif ( function_exists( 'wincache_ucache_get' ) ) { + $id = 'wincache'; + } else { + if ( is_array( $fallback ) ) { + $id = isset( $fallback['fallback'] ) ? $fallback['fallback'] : CACHE_NONE; + } else { + $id = $fallback; + } + } - return ( $cache instanceof EmptyBagOStuff ) - ? self::getInstance( $fallback ) - : $cache; + return self::getInstance( $id ); } /** @@ -374,10 +383,11 @@ class ObjectCache { * * @since 1.26 * @return WANObjectCache - * @deprecated Since 1.28 Use MediaWikiServices::getMainWANCache() */ public static function getMainWANInstance() { - return MediaWikiServices::getInstance()->getMainWANObjectCache(); + global $wgMainWANCache; + + return self::getWANInstance( $wgMainWANCache ); } /** @@ -397,10 +407,11 @@ class ObjectCache { * * @return BagOStuff * @since 1.26 - * @deprecated Since 1.28 Use MediaWikiServices::getMainObjectStash */ public static function getMainStashInstance() { - return MediaWikiServices::getInstance()->getMainObjectStash(); + global $wgMainStash; + + return self::getInstance( $wgMainStash ); } /** diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index e53a958387..45a7ce5f59 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -336,10 +336,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { JobQueueGroup::destroySingletons(); ObjectCache::clear(); - $services = MediaWikiServices::getInstance(); - $services->resetServiceForTesting( 'MainObjectStash' ); - $services->resetServiceForTesting( 'LocalServerObjectCache' ); - $services->getMainWANObjectCache()->clearProcessCache(); FileBackendGroup::destroySingleton(); // TODO: move global state into MediaWikiServices diff --git a/tests/phpunit/includes/MediaWikiServicesTest.php b/tests/phpunit/includes/MediaWikiServicesTest.php index 4fbef6ce67..a05e39d974 100644 --- a/tests/phpunit/includes/MediaWikiServicesTest.php +++ b/tests/phpunit/includes/MediaWikiServicesTest.php @@ -320,11 +320,8 @@ class MediaWikiServicesTest extends MediaWikiTestCase { '_MediaWikiTitleCodec' => [ '_MediaWikiTitleCodec', MediaWikiTitleCodec::class ], 'TitleFormatter' => [ 'TitleFormatter', TitleFormatter::class ], 'TitleParser' => [ 'TitleParser', TitleParser::class ], - 'ProxyLookup' => [ 'ProxyLookup', ProxyLookup::class ], - 'MainObjectStash' => [ 'MainObjectStash', BagOStuff::class ], - 'MainWANObjectCache' => [ 'MainWANObjectCache', WANObjectCache::class ], - 'LocalServerObjectCache' => [ 'LocalServerObjectCache', BagOStuff::class ], - 'VirtualRESTServiceClient' => [ 'VirtualRESTServiceClient', VirtualRESTServiceClient::class ] + 'VirtualRESTServiceClient' => [ 'VirtualRESTServiceClient', VirtualRESTServiceClient::class ], + 'ProxyLookup' => [ 'ProxyLookup', ProxyLookup::class ] ]; } -- 2.20.1