Fix duplicate automatic file backend bug
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 6 Oct 2015 21:43:12 +0000 (14:43 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 6 Oct 2015 21:50:12 +0000 (14:50 -0700)
Follow-up 8a3816529a

Bug: T114810
Change-Id: I2706c90077627b3df35fe530e0a919cfd0a75d78

includes/filebackend/FileBackendGroup.php

index 59b2fd6..b6ddbad 100644 (file)
@@ -63,6 +63,9 @@ class FileBackendGroup {
        protected function initFromGlobals() {
                global $wgLocalFileRepo, $wgForeignFileRepos, $wgFileBackends;
 
+               // Register explicitly defined backends
+               $this->register( $wgFileBackends, wfConfiguredReadOnlyReason() );
+
                $autoBackends = array();
                // Automatically create b/c backends for file repos...
                $repos = array_merge( $wgForeignFileRepos, array( $wgLocalFileRepo ) );
@@ -102,25 +105,18 @@ class FileBackendGroup {
                        );
                }
 
-               $backends = array_merge( $autoBackends, $wgFileBackends );
-
-               // Apply $wgReadOnly to all backends if not already read-only
-               foreach ( $backends as &$backend ) {
-                       $backend['readOnly'] = !empty( $backend['readOnly'] )
-                               ? $backend['readOnly']
-                               : wfConfiguredReadOnlyReason();
-               }
-
-               $this->register( $backends );
+               // Register implicitly defined backends
+               $this->register( $autoBackends, wfConfiguredReadOnlyReason() );
        }
 
        /**
         * Register an array of file backend configurations
         *
         * @param array $configs
+        * @param string|null $readOnlyReason
         * @throws FileBackendException
         */
-       protected function register( array $configs ) {
+       protected function register( array $configs, $readOnlyReason = null ) {
                foreach ( $configs as $config ) {
                        if ( !isset( $config['name'] ) ) {
                                throw new FileBackendException( "Cannot register a backend with no name." );
@@ -133,6 +129,10 @@ class FileBackendGroup {
                        }
                        $class = $config['class'];
 
+                       $config['readOnly'] = !empty( $config['readOnly'] )
+                               ? $config['readOnly']
+                               : $readOnlyReason;
+
                        unset( $config['class'] ); // backend won't need this
                        $this->backends[$name] = array(
                                'class' => $class,