From: Aryeh Gregor Date: Mon, 26 Aug 2019 09:54:19 +0000 (+0300) Subject: Pass correct store to rebuildLocalisationCache.php X-Git-Tag: 1.34.0-rc.0~580 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=76a940350d36c323ebedb4ab45cc81ed1c6b6c92;p=lhc%2Fweb%2Fwiklou.git Pass correct store to rebuildLocalisationCache.php e4468a1d6b6 completely broke rebuildLocalisationCache.php by unconditionally passing in LCStoreDB( [] ) instead of constructing the correct object. Bug: T231183 Change-Id: I0d52662e8745cf0e10091169b3b08eff48ef2b8f --- diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 9daf70ddd8..f331d579f0 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -295,28 +295,9 @@ return [ $logger = LoggerFactory::getInstance( 'localisation' ); - // Figure out what class to use for the LCStore - $storeArg = []; - $storeArg['directory'] = - $conf['storeDirectory'] ?: $services->getMainConfig()->get( 'CacheDirectory' ); - - if ( !empty( $conf['storeClass'] ) ) { - $storeClass = $conf['storeClass']; - } elseif ( $conf['store'] === 'files' || $conf['store'] === 'file' || - ( $conf['store'] === 'detect' && $storeArg['directory'] ) - ) { - $storeClass = LCStoreCDB::class; - } elseif ( $conf['store'] === 'db' || $conf['store'] === 'detect' ) { - $storeClass = LCStoreDB::class; - $storeArg['server'] = $conf['storeServer'] ?? []; - } elseif ( $conf['store'] === 'array' ) { - $storeClass = LCStoreStaticArray::class; - } else { - throw new MWException( - 'Please set $wgLocalisationCacheConf[\'store\'] to something sensible.' - ); - } - $logger->debug( "LocalisationCache: using store $storeClass" ); + $store = LocalisationCache::getStoreFromConf( + $conf, $services->getMainConfig()->get( 'CacheDirectory' ) ); + $logger->debug( 'LocalisationCache: using store ' . get_class( $store ) ); return new $conf['class']( new ServiceOptions( @@ -331,7 +312,7 @@ return [ // Some other options come from config itself $services->getMainConfig() ), - new $storeClass( $storeArg ), + $store, $logger, [ function () use ( $services ) { $services->getResourceLoader()->getMessageBlobStore()->clear(); diff --git a/includes/cache/localisation/LocalisationCache.php b/includes/cache/localisation/LocalisationCache.php index fb4675eb30..ed9421e255 100644 --- a/includes/cache/localisation/LocalisationCache.php +++ b/includes/cache/localisation/LocalisationCache.php @@ -190,6 +190,38 @@ class LocalisationCache { private $mergeableKeys = null; + /** + * Return a suitable LCStore as specified by the given configuration. + * + * @param array $conf In the format of $wgLocalisationCacheConf + * @param string|false|null $fallbackCacheDir In case 'storeDirectory' isn't specified + * @return LCStore + */ + public static function getStoreFromConf( array $conf, $fallbackCacheDir ) : LCStore { + $storeArg = []; + $storeArg['directory'] = + $conf['storeDirectory'] ?: $fallbackCacheDir; + + if ( !empty( $conf['storeClass'] ) ) { + $storeClass = $conf['storeClass']; + } elseif ( $conf['store'] === 'files' || $conf['store'] === 'file' || + ( $conf['store'] === 'detect' && $storeArg['directory'] ) + ) { + $storeClass = LCStoreCDB::class; + } elseif ( $conf['store'] === 'db' || $conf['store'] === 'detect' ) { + $storeClass = LCStoreDB::class; + $storeArg['server'] = $conf['storeServer'] ?? []; + } elseif ( $conf['store'] === 'array' ) { + $storeClass = LCStoreStaticArray::class; + } else { + throw new MWException( + 'Please set $wgLocalisationCacheConf[\'store\'] to something sensible.' + ); + } + + return new $storeClass( $storeArg ); + } + /** * @todo Make this a const when HHVM support is dropped (T192166) * diff --git a/maintenance/rebuildLocalisationCache.php b/maintenance/rebuildLocalisationCache.php index a239fa0e28..8a519e7178 100644 --- a/maintenance/rebuildLocalisationCache.php +++ b/maintenance/rebuildLocalisationCache.php @@ -62,7 +62,7 @@ class RebuildLocalisationCache extends Maintenance { } public function execute() { - global $wgLocalisationCacheConf; + global $wgLocalisationCacheConf, $wgCacheDirectory; $force = $this->hasOption( 'force' ); $threads = $this->getOption( 'threads', 1 ); @@ -92,7 +92,7 @@ class RebuildLocalisationCache extends Maintenance { $conf, MediaWikiServices::getInstance()->getMainConfig() ), - new LCStoreDB( [] ), + LocalisationCache::getStoreFromConf( $conf, $wgCacheDirectory ), LoggerFactory::getInstance( 'localisation' ), [ function () { MediaWikiServices::getInstance()->getResourceLoader()