From: Aaron Date: Wed, 9 May 2012 17:35:04 +0000 (-0700) Subject: [FileBackend] Made it easy to use registed file backend config in multi-write backends. X-Git-Tag: 1.31.0-rc.0~23586^2 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=d086fc9f6df93088c18c419b85f030416c4be808;p=lhc%2Fweb%2Fwiklou.git [FileBackend] Made it easy to use registed file backend config in multi-write backends. Change-Id: Idce8c06a56bd0debac5f2217bef89b4fe8bf5ba8 --- diff --git a/includes/filerepo/backend/FileBackendGroup.php b/includes/filerepo/backend/FileBackendGroup.php index 69c227da8c..8bbc96d0de 100644 --- a/includes/filerepo/backend/FileBackendGroup.php +++ b/includes/filerepo/backend/FileBackendGroup.php @@ -156,6 +156,21 @@ class FileBackendGroup { return $this->backends[$name]['instance']; } + /** + * Get the config array for a backend object with a given name + * + * @param $name string + * @return Array + * @throws MWException + */ + public function config( $name ) { + if ( !isset( $this->backends[$name] ) ) { + throw new MWException( "No backend defined with the name `$name`." ); + } + $class = $this->backends[$name]['class']; + return array( 'class' => $class ) + $this->backends[$name]['config']; + } + /** * Get an appropriate backend object from a storage path * diff --git a/includes/filerepo/backend/FileBackendMultiWrite.php b/includes/filerepo/backend/FileBackendMultiWrite.php index 769aef69b0..8cb32feb48 100644 --- a/includes/filerepo/backend/FileBackendMultiWrite.php +++ b/includes/filerepo/backend/FileBackendMultiWrite.php @@ -57,6 +57,9 @@ class FileBackendMultiWrite extends FileBackend { * FileBackendStore class, but with these additional settings: * 'class' : The name of the backend class * 'isMultiMaster' : This must be set for one backend. + * 'template: : If given a backend name, this will use + * the config of that backend as a template. + * Values specified here take precedence. * 'syncChecks' : Integer bitfield of internal backend sync checks to perform. * Possible bits include self::CHECK_SIZE and self::CHECK_TIME. * The checks are done before allowing any file operations. @@ -68,6 +71,11 @@ class FileBackendMultiWrite extends FileBackend { // Construct backends here rather than via registration // to keep these backends hidden from outside the proxy. foreach ( $config['backends'] as $index => $config ) { + if ( isset( $config['template'] ) ) { + // Config is just a modified version of a registered backend's. + // This should only be used when that config is used only be this backend. + $config = $config + FileBackendGroup::singleton()->config( $config['template'] ); + } $name = $config['name']; if ( isset( $namesUsed[$name] ) ) { // don't break FileOp predicates throw new MWException( "Two or more backends defined with the name $name." );