Pass correct store to rebuildLocalisationCache.php
authorAryeh Gregor <ayg@aryeh.name>
Mon, 26 Aug 2019 09:54:19 +0000 (12:54 +0300)
committerAryeh Gregor <ayg@aryeh.name>
Mon, 26 Aug 2019 09:56:52 +0000 (12:56 +0300)
e4468a1d6b6 completely broke rebuildLocalisationCache.php by
unconditionally passing in LCStoreDB( [] ) instead of constructing the
correct object.

Bug: T231183
Change-Id: I0d52662e8745cf0e10091169b3b08eff48ef2b8f

includes/ServiceWiring.php
includes/cache/localisation/LocalisationCache.php
maintenance/rebuildLocalisationCache.php

index 9daf70d..f331d57 100644 (file)
@@ -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();
index fb4675e..ed9421e 100644 (file)
@@ -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)
         *
index a239fa0..8a519e7 100644 (file)
@@ -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()