Installer: Disable broken CACHE_DB after backend is disabled
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 4 Jun 2014 19:22:14 +0000 (21:22 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 4 Jun 2014 19:22:14 +0000 (21:22 +0200)
We're currently not hitting any code that calls wfGetCache(), but
this seems like a good thing to do and would allow us to re-use
more code instead of duplicating a large method just because it
has a call to wfGetCache() somewhere.

This is already done for DB access and LocalisationCache in
general by the installer, but via SqlBagOStuff it can still
cause an exception from LBFactoryFake.

Change-Id: I69c1e34365c1d7503aea8ef47942d20c34318e85

includes/installer/Installer.php

index 17c5ab2..88478f4 100644 (file)
@@ -351,10 +351,23 @@ abstract class Installer {
        public function __construct() {
                global $wgMessagesDirs, $wgUser;
 
-               // Disable the i18n cache and LoadBalancer
+               // Disable the i18n cache
                Language::getLocalisationCache()->disableBackend();
+               // Disable LoadBalancer and wfGetDB etc.
                LBFactory::disableBackend();
 
+               // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and
+               // SqlBagOStuff will then throw since we just disabled wfGetDB)
+               $GLOBALS['wgMemc'] = new EmptyBagOStuff;
+               ObjectCache::clear();
+               $emptyCache = array( 'class' => 'EmptyBagOStuff' );
+               $GLOBALS['wgObjectCaches'] = array(
+                       CACHE_NONE => $emptyCache,
+                       CACHE_DB => $emptyCache,
+                       CACHE_ANYTHING => $emptyCache,
+                       CACHE_MEMCACHED => $emptyCache,
+               );
+
                // Load the installer's i18n.
                $wgMessagesDirs['MediawikiInstaller'] = __DIR__ . '/i18n';
 
@@ -389,7 +402,7 @@ abstract class Installer {
                $this->compiledDBs = $compiledDBs;
 
                $this->parserTitle = Title::newFromText( 'Installer' );
-               $this->parserOptions = new ParserOptions; // language will  be wrong :(
+               $this->parserOptions = new ParserOptions; // language will be wrong :(
                $this->parserOptions->setEditSection( false );
        }