]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/filerepo/ForeignDBViaLBRepo.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / filerepo / ForeignDBViaLBRepo.php
index 4c530b511d3e5ee9ce221321496e537e14dd4536..bcd253fb4a6b742dae7046b93e1b0dbaf2db8d84 100644 (file)
@@ -1,6 +1,21 @@
 <?php
 /**
- * A foreign repository with a MediaWiki database accessible via the configured LBFactory
+ * A foreign repository with a MediaWiki database accessible via the configured LBFactory.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
  * @ingroup FileRepo
  * @ingroup FileRepo
  */
 class ForeignDBViaLBRepo extends LocalRepo {
-       var $wiki, $dbName, $tablePrefix;
-       var $fileFactory = array( 'ForeignDBFile', 'newFromTitle' );
-       var $fileFromRowFactory = array( 'ForeignDBFile', 'newFromRow' );
+       /** @var string */
+       protected $wiki;
+
+       /** @var string */
+       protected $dbName;
+
+       /** @var string */
+       protected $tablePrefix;
 
+       /** @var array */
+       protected $fileFactory = [ 'ForeignDBFile', 'newFromTitle' ];
+
+       /** @var array */
+       protected $fileFromRowFactory = [ 'ForeignDBFile', 'newFromRow' ];
+
+       /** @var bool */
+       protected $hasSharedCache;
+
+       /**
+        * @param array|null $info
+        */
        function __construct( $info ) {
                parent::__construct( $info );
                $this->wiki = $info['wiki'];
@@ -23,39 +55,55 @@ class ForeignDBViaLBRepo extends LocalRepo {
                $this->hasSharedCache = $info['hasSharedCache'];
        }
 
+       /**
+        * @return IDatabase
+        */
        function getMasterDB() {
-               return wfGetDB( DB_MASTER, array(), $this->wiki );
+               return wfGetLB( $this->wiki )->getConnectionRef( DB_MASTER, [], $this->wiki );
        }
 
-       function getSlaveDB() {
-               return wfGetDB( DB_SLAVE, array(), $this->wiki );
+       /**
+        * @return IDatabase
+        */
+       function getReplicaDB() {
+               return wfGetLB( $this->wiki )->getConnectionRef( DB_REPLICA, [], $this->wiki );
        }
+
+       /**
+        * @return Closure
+        */
+       protected function getDBFactory() {
+               return function ( $index ) {
+                       return wfGetLB( $this->wiki )->getConnectionRef( $index, [], $this->wiki );
+               };
+       }
+
        function hasSharedCache() {
                return $this->hasSharedCache;
        }
 
        /**
         * Get a key on the primary cache for this repository.
-        * Returns false if the repository's cache is not accessible at this site. 
+        * Returns false if the repository's cache is not accessible at this site.
         * The parameters are the parts of the key, as for wfMemcKey().
+        * @return bool|string
         */
        function getSharedCacheKey( /*...*/ ) {
                if ( $this->hasSharedCache() ) {
                        $args = func_get_args();
                        array_unshift( $args, $this->wiki );
+
                        return implode( ':', $args );
                } else {
                        return false;
                }
        }
 
-       function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
-               throw new MWException( get_class($this) . ': write operations are not supported' );
+       protected function assertWritableRepo() {
+               throw new MWException( static::class . ': write operations are not supported.' );
        }
-       function publish( $srcPath, $dstRel, $archiveRel, $flags = 0 ) {
-               throw new MWException( get_class($this) . ': write operations are not supported' );
-       }
-       function deleteBatch( $fileMap ) {
-               throw new MWException( get_class($this) . ': write operations are not supported' );
+
+       public function getInfo() {
+               return FileRepo::getInfo();
        }
 }