jenkins-bot has submitted this change and it was merged.

Change subject: Give store configurable access to other db clusters
......................................................................


Give store configurable access to other db clusters

Change-Id: Ibdbc0d539eddb20c8a9a9a1f6685eed3864a11cc
---
M extension.json
M src/CognateStore.php
M src/ServiceWiring.php
3 files changed, 14 insertions(+), 17 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index de00abd..7276618 100644
--- a/extension.json
+++ b/extension.json
@@ -13,7 +13,8 @@
     "CognateStore": "src/CognateStore.php"
   },
   "config": {
-    "CognateWiki": false,
+    "CognateDb": false,
+    "CognateCluster": false,
     "CognateNamespaces": [ 0 ]
   },
   "ServiceWiringFiles": [
diff --git a/src/CognateStore.php b/src/CognateStore.php
index 0b10293..b5fbb28 100644
--- a/src/CognateStore.php
+++ b/src/CognateStore.php
@@ -11,20 +11,13 @@
         */
        private $loadBalancer;
 
-       /**
-        * @var string
-        */
-       private $wikiName;
-
        const TABLE_NAME = 'inter_language_titles';
 
        /**
         * @param LoadBalancer $loadBalancer
-        * @param string $wikiName
         */
-       public function __construct( LoadBalancer $loadBalancer, $wikiName ) {
+       public function __construct( LoadBalancer $loadBalancer ) {
                $this->loadBalancer = $loadBalancer;
-               $this->wikiName = $wikiName;
        }
 
        /**
@@ -37,9 +30,8 @@
                        'ilt_language' => $language,
                        'ilt_title' => $title
                ];
-               $dbw = $this->loadBalancer->getConnection( DB_MASTER, [], 
$this->wikiName );
+               $dbw = $this->loadBalancer->getConnectionRef( DB_MASTER );
                $result = $dbw->insert( self::TABLE_NAME, $pageData, 
__METHOD__, [ 'IGNORE' ] );
-               $this->loadBalancer->reuseConnection( $dbw );
 
                return $result;
        }
@@ -54,12 +46,11 @@
        public function getTranslationsForPage( $language, $title ) {
                $languages = [];
 
-               $dbr = $this->loadBalancer->getConnection( DB_SLAVE, [], 
$this->wikiName );
+               $dbr = $this->loadBalancer->getConnectionRef( DB_SLAVE );
                $result = $dbr->select( self::TABLE_NAME, ['ilt_language'], [
                        'ilt_language != ' . $dbr->addQuotes( $language ),
                        'ilt_title' => $title
                ] );
-               $this->loadBalancer->reuseConnection( $dbr );
 
                while ( $row = $result->fetchRow() ) {
                        $languages[] = $row[ 'ilt_language' ];
diff --git a/src/ServiceWiring.php b/src/ServiceWiring.php
index 694a3ad..af44ab9 100644
--- a/src/ServiceWiring.php
+++ b/src/ServiceWiring.php
@@ -7,9 +7,14 @@
 
 return [
        'CognateStore' => function( MediaWikiServices $services ) {
-               return new CognateStore(
-                       $services->getDBLoadBalancer(),
-                       $services->getMainConfig()->get( 'CognateWiki' )
-               );
+               $lbFactory = $services->getDBLoadBalancerFactory();
+               $cognateDb = $services->getMainConfig()->get( 'CognateDb' );
+               $cognateCluster = $services->getMainConfig()->get( 
'CognateCluster' );
+               if ( $cognateCluster ) {
+                       $lb = $lbFactory->getExternalLB( $cognateCluster, 
$cognateDb );
+               } else {
+                       $lb = $lbFactory->getMainLB( $cognateDb );
+               }
+               return new CognateStore( $lb );
        },
 ];

-- 
To view, visit https://gerrit.wikimedia.org/r/311438
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibdbc0d539eddb20c8a9a9a1f6685eed3864a11cc
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Cognate
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Gabriel Birke <gabriel.bi...@wikimedia.de>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to