From 99339b4598379b183315d4bb2a519a472288e5ff Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 28 Sep 2016 16:37:26 -0700 Subject: [PATCH] Make multi-write backend "template" config work as expected * FileBackendGroup now applies the usual config for these sub-backends, the same config get() applies. * Also make sure FileBackendMultiWrite::concatenate() uses the status wrapper. Bug: T146904 Change-Id: I1e9b5027dbac11ea9484cd16851e5db998574429 --- includes/filebackend/FileBackendGroup.php | 49 ++++++++++--------- .../filebackend/FileBackendMultiWrite.php | 5 +- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index ede73aa2fb..87d9441c3b 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -149,30 +149,11 @@ class FileBackendGroup { * @throws InvalidArgumentException */ public function get( $name ) { - if ( !isset( $this->backends[$name] ) ) { - throw new InvalidArgumentException( "No backend defined with the name `$name`." ); - } // Lazy-load the actual backend instance if ( !isset( $this->backends[$name]['instance'] ) ) { - $class = $this->backends[$name]['class']; - $config = $this->backends[$name]['config']; - $config += [ - 'wikiId' => wfWikiID(), // e.g. "my_wiki-en_" - 'mimeCallback' => [ $this, 'guessMimeInternal' ], - 'obResetFunc' => 'wfResetOutputBuffers', - 'streamMimeFunc' => [ 'StreamFile', 'contentTypeFromPath' ] - ]; - $config['lockManager'] = - LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] ); - $config['fileJournal'] = isset( $config['fileJournal'] ) - ? FileJournal::factory( $config['fileJournal'], $name ) - : FileJournal::factory( [ 'class' => 'NullFileJournal' ], $name ); - $config['wanCache'] = ObjectCache::getMainWANInstance(); - $config['srvCache'] = ObjectCache::getLocalServerInstance( 'hash' ); - $config['statusWrapper'] = [ 'Status', 'wrap' ]; - $config['tmpDirectory'] = wfTempDir(); - $config['logger'] = LoggerFactory::getInstance( 'FileOperation' ); - $config['profiler'] = Profiler::instance(); + $config = $this->config( $name ); + + $class = $config['class']; if ( $class === 'FileBackendMultiWrite' ) { foreach ( $config['backends'] as $index => $beConfig ) { if ( isset( $beConfig['template'] ) ) { @@ -193,7 +174,7 @@ class FileBackendGroup { * Get the config array for a backend object with a given name * * @param string $name - * @return array + * @return array Parameters to FileBackend::__construct() * @throws InvalidArgumentException */ public function config( $name ) { @@ -202,7 +183,27 @@ class FileBackendGroup { } $class = $this->backends[$name]['class']; - return [ 'class' => $class ] + $this->backends[$name]['config']; + $config = $this->backends[$name]['config']; + $config['class'] = $class; + $config += [ // set defaults + 'wikiId' => wfWikiID(), // e.g. "my_wiki-en_" + 'mimeCallback' => [ $this, 'guessMimeInternal' ], + 'obResetFunc' => 'wfResetOutputBuffers', + 'streamMimeFunc' => [ 'StreamFile', 'contentTypeFromPath' ], + 'tmpDirectory' => wfTempDir(), + 'statusWrapper' => [ 'Status', 'wrap' ], + 'wanCache' => ObjectCache::getMainWANInstance(), + 'srvCache' => ObjectCache::getLocalServerInstance( 'hash' ), + 'logger' => LoggerFactory::getInstance( 'FileOperation' ), + 'profiler' => Profiler::instance() + ]; + $config['lockManager'] = + LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] ); + $config['fileJournal'] = isset( $config['fileJournal'] ) + ? FileJournal::factory( $config['fileJournal'], $name ) + : FileJournal::factory( [ 'class' => 'NullFileJournal' ], $name ); + + return $config; } /** diff --git a/includes/libs/filebackend/FileBackendMultiWrite.php b/includes/libs/filebackend/FileBackendMultiWrite.php index 7c32d02e86..212e84f026 100644 --- a/includes/libs/filebackend/FileBackendMultiWrite.php +++ b/includes/libs/filebackend/FileBackendMultiWrite.php @@ -575,11 +575,14 @@ class FileBackendMultiWrite extends FileBackend { } public function concatenate( array $params ) { + $status = $this->newStatus(); // We are writing to an FS file, so we don't need to do this per-backend $index = $this->getReadIndexFromParams( $params ); $realParams = $this->substOpPaths( $params, $this->backends[$index] ); - return $this->backends[$index]->concatenate( $realParams ); + $status->merge( $this->backends[$index]->concatenate( $realParams ) ); + + return $status; } public function fileExists( array $params ) { -- 2.20.1