Esempio n. 1
0
 /**
  * Constructor, always call this from child classes.
  */
 public function __construct()
 {
     global $wgMemc, $wgUser, $wgObjectCaches;
     $defaultConfig = new GlobalVarConfig();
     // all the stuff from DefaultSettings.php
     $installerConfig = self::getInstallerConfig($defaultConfig);
     // Reset all services and inject config overrides
     MediaWiki\MediaWikiServices::resetGlobalInstance($installerConfig);
     // Don't attempt to load user language options (T126177)
     // This will be overridden in the web installer with the user-specified language
     RequestContext::getMain()->setLanguage('en');
     // Disable the i18n cache
     // TODO: manage LocalisationCache singleton in MediaWikiServices
     Language::getLocalisationCache()->disableBackend();
     // Disable all global services, since we don't have any configuration yet!
     MediaWiki\MediaWikiServices::disableStorageBackend();
     // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and
     // SqlBagOStuff will then throw since we just disabled wfGetDB)
     $wgObjectCaches = MediaWikiServices::getInstance()->getMainConfig()->get('ObjectCaches');
     $wgMemc = ObjectCache::getInstance(CACHE_NONE);
     // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
     $wgUser = User::newFromId(0);
     RequestContext::getMain()->setUser($wgUser);
     $this->settings = $this->internalDefaults;
     foreach ($this->defaultVarNames as $var) {
         $this->settings[$var] = $GLOBALS[$var];
     }
     $this->doEnvironmentPreps();
     $this->compiledDBs = [];
     foreach (self::getDBTypes() as $type) {
         $installer = $this->getDBInstaller($type);
         if (!$installer->isCompiled()) {
             continue;
         }
         $this->compiledDBs[] = $type;
     }
     $this->parserTitle = Title::newFromText('Installer');
     $this->parserOptions = new ParserOptions($wgUser);
     // language will be wrong :(
     $this->parserOptions->setEditSection(false);
 }
Esempio n. 2
0
 /**
  * Disables all access to the load balancer, will cause all database access
  * to throw a DBAccessError
  */
 public static function disableBackend()
 {
     MediaWikiServices::disableStorageBackend();
 }
 public function testDisableStorageBackend()
 {
     $newServices = $this->newMediaWikiServices();
     $oldServices = MediaWikiServices::forceGlobalInstance($newServices);
     $lbFactory = $this->getMockBuilder('LBFactorySimple')->disableOriginalConstructor()->getMock();
     $lbFactory->expects($this->once())->method('destroy');
     $newServices->redefineService('DBLoadBalancerFactory', function () use($lbFactory) {
         return $lbFactory;
     });
     // force the service to become active, so we can check that it does get destroyed
     $newServices->getService('DBLoadBalancerFactory');
     MediaWikiServices::disableStorageBackend();
     // should destroy DBLoadBalancerFactory
     try {
         MediaWikiServices::getInstance()->getService('DBLoadBalancerFactory');
         $this->fail('DBLoadBalancerFactory shoudl have been disabled');
     } catch (ServiceDisabledException $ex) {
         // ok, as expected
     } catch (Throwable $ex) {
         $this->fail('ServiceDisabledException expected, caught ' . get_class($ex));
     }
     MediaWikiServices::forceGlobalInstance($oldServices);
     $newServices->destroy();
 }