jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/380873 )

Change subject: Centralise database hostname handling
......................................................................


Centralise database hostname handling

* Remove deadcode for $cluster as integer.
* Make code for appendin ".labsdb" suffix actually used.

Change-Id: I47fe2e622bec94ba2453ca41ce8819eb6094d1fb
---
M src/App.php
M src/Main.php
2 files changed, 18 insertions(+), 18 deletions(-)

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



diff --git a/src/App.php b/src/App.php
index db38076..57a69d6 100644
--- a/src/App.php
+++ b/src/App.php
@@ -35,20 +35,20 @@
      * @return PDO
      */
     private function openDB($database = 'wikidatawiki', $cluster = null) {
-        $this->aTP('Create connection to '.$cluster);
-        if (is_string($database)) {
-            $host = $database.'.labsdb';
-            $dbname = $database.'_p';
-        }
-        if (is_int($cluster)) {
-            $host = 's'.$cluster.'.labsdb';
-            $dbname = (is_string($database)) ? $database.'_p': 
'information_schema';
-        }
+        $dbname = "{$database}_p";
 
         if (is_string($cluster)) {
-            $host = $cluster;
-            $dbname = (is_string($database)) ? $database.'_p': 
'information_schema';
+            if (strpos($cluster, '.') === false) {
+                // Default suffix
+                $host = "{$cluster}.labsdb";
+            } else {
+                $host = $cluster;
+            }
+        } else {
+            $host = "{$database}.labsdb";
         }
+
+        $this->aTP('Create connection to ' . $cluster);
 
         try {
             // Establish connection
@@ -63,18 +63,18 @@
      * Gibt die Verbindung zu einem Wiki zurück (cache)
      *
      * @param string $database
-     * @param $clusterNr
+     * @param string $cluster
      * @return PDO
      */
-    public function getDB($database = 'meta', $clusterNr = 's1.labsdb') {
+    public function getDB($database = 'meta', $cluster = 's1') {
         if (!$clusterNr) {
             throw new Exception('Invalid DB cluster specification');
         }
-        // Bereits vorhanden?
-        if (!isset($this->clusters[$clusterNr])) {
-            $this->clusters[$clusterNr] = $this->openDB($database, $clusterNr);
+        // Reuse existing connection if possible
+        if (!isset($this->clusters[$cluster])) {
+            $this->clusters[$cluster] = $this->openDB($database, $cluster);
         }
-        $pdo = $this->clusters[$clusterNr];
+        $pdo = $this->clusters[$cluster];
 
         // Select the right database on this cluster server
         $m = $pdo->prepare('USE `'.$database.'_p`;');
diff --git a/src/Main.php b/src/Main.php
index 8d1812e..70fee63 100644
--- a/src/Main.php
+++ b/src/Main.php
@@ -260,7 +260,7 @@
         }
         if ($centralauthData === null) {
             $centralauthData = array();
-            $pdo = $this->app->getDB('centralauth', 'centralauth.labsdb');
+            $pdo = $this->app->getDB('centralauth', 'centralauth');
             $statement = $pdo->prepare('SELECT * FROM localuser WHERE lu_name 
= :user;');
             $statement->bindParam(':user', $this->user);
             $statement->execute();

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I47fe2e622bec94ba2453ca41ce8819eb6094d1fb
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/guc
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
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