From: Kunal Mehta Date: Thu, 7 Aug 2014 20:57:14 +0000 (+0100) Subject: Maintenance: Add an easy way to access Config instances X-Git-Tag: 1.31.0-rc.0~14095^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=b016aa66dc6368fbd37c259c1973714be4ded969;p=lhc%2Fweb%2Fwiklou.git Maintenance: Add an easy way to access Config instances Change-Id: I97d50c624e988c70bb2ac0da4fc33957ce3cf524 --- diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index ffb07eb82e..8d30df4c61 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -113,6 +113,13 @@ abstract class Maintenance { */ public $fileHandle; + /** + * Accessible via getConfig() + * + * @var Config + */ + private $config; + /** * Default constructor. Children should call this *first* if implementing * their own constructors @@ -457,6 +464,26 @@ abstract class Maintenance { $this->mDependantParameters = array_diff_key( $this->mParams, $this->mGenericParameters ); } + /** + * @since 1.24 + * @return Config + */ + public function getConfig() { + if ( $this->config === null ) { + $this->config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); + } + + return $this->config; + } + + /** + * @since 1.24 + * @param Config $config + */ + public function setConfig( Config $config ) { + $this->config = $config; + } + /** * Run a child maintenance script. Pass all of the current arguments * to it. diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index 28a054549d..46844c9d47 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -44,6 +44,7 @@ if ( !$maintClass || !class_exists( $maintClass ) ) { } // Get an object to start us off +/** @var Maintenance $maintenance */ $maintenance = new $maintClass(); // Basic sanity checks and such @@ -89,6 +90,8 @@ if ( $maintenance->getDbType() === Maintenance::DB_NONE ) { $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; } } + +$maintenance->setConfig( ConfigFactory::getDefaultInstance()->makeConfig( 'main' ) ); $maintenance->finalSetup(); // Some last includes require_once "$IP/includes/Setup.php"; diff --git a/tests/phpunit/maintenance/MaintenanceTest.php b/tests/phpunit/maintenance/MaintenanceTest.php index a13f7bf9a4..e2fc82474e 100644 --- a/tests/phpunit/maintenance/MaintenanceTest.php +++ b/tests/phpunit/maintenance/MaintenanceTest.php @@ -810,4 +810,21 @@ class MaintenanceTest extends MediaWikiTestCase { $m2->simulateShutdown(); $this->assertOutputPrePostShutdown( "foobar\n\n", false ); } + + /** + * @covers Maintenance::getConfig + */ + public function testGetConfig() { + $this->assertInstanceOf( 'Config', $this->m->getConfig() ); + $this->assertSame( ConfigFactory::getDefaultInstance()->makeConfig( 'main' ), $this->m->getConfig() ); + } + + /** + * @covers Maintenance::setConfig + */ + public function testSetConfig() { + $conf = $this->getMock( 'Config' ); + $this->m->setConfig( $conf ); + $this->assertSame( $conf, $this->m->getConfig() ); + } }