$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(
// Some other options come from config itself
$services->getMainConfig()
),
- new $storeClass( $storeArg ),
+ $store,
$logger,
[ function () use ( $services ) {
$services->getResourceLoader()->getMessageBlobStore()->clear();
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)
*
}
public function execute() {
- global $wgLocalisationCacheConf;
+ global $wgLocalisationCacheConf, $wgCacheDirectory;
$force = $this->hasOption( 'force' );
$threads = $this->getOption( 'threads', 1 );
$conf,
MediaWikiServices::getInstance()->getMainConfig()
),
- new LCStoreDB( [] ),
+ LocalisationCache::getStoreFromConf( $conf, $wgCacheDirectory ),
LoggerFactory::getInstance( 'localisation' ),
[ function () {
MediaWikiServices::getInstance()->getResourceLoader()