Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/174903

Change subject: settings: Read config from replica.my.cnf
......................................................................

settings: Read config from replica.my.cnf

Change-Id: I26da65203c064e5cc87760a6847dbe18e91ccc96
---
M settings.php
1 file changed, 24 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/tools/guc 
refs/changes/03/174903/1

diff --git a/settings.php b/settings.php
index 2d809c8..19816f9 100644
--- a/settings.php
+++ b/settings.php
@@ -9,42 +9,39 @@
      * @return string wert
      */
     public static function getSetting($setting) {
-        $settings = array(
-
-            // Database
-            'user'      => 'x',
-            'password'  => 'x',
+        static $settings = null;
+        if ($settings === null) {
+                $cnf = self::_getMySQLloginFromFile();
+                $settings = array(
+                    // Database
+                    'user' => $cnf['user'],
+                    'password' => $cnf['password'],
 
 
-            // Components
-            'components' => array(
-                'guc',
-                'wikicontribs',
-                'exception',
-            ),
+                    // Components
+                    'components' => array(
+                        'guc',
+                        'wikicontribs',
+                        'exception',
+                    ),
 
-            // Paths
-            'cacheFile' => 'cache/namespaces.json',
-        );
+                    // Paths
+                    'cacheFile' => 'cache/namespaces.json',
+            );
+        }
         return $settings[$setting];
     }
 
 
     private static function _getMySQLloginFromFile() {
-        // TODO: Fix
-        $path = '../replica.my.cnf';
-
-        $raw = file($path);
-        $return = new stdClass();
-        foreach ($raw as $line) {
-            preg_match('/^([a-zA-Z0-9]+)\=\'([a-zA-Z0-9]+)\'$/', $line, 
$result);
-            if ($result[1]) {
-                $return->$result[1] = $result[2];
+        static $cnf = null;
+        if ($cnf === null) {
+            $uinfo = posix_getpwuid(posix_geteuid());
+            $cnf = parse_ini_file($uinfo['dir'] . '/replica.my.cnf');
+            if (!$cnf || !$cnf['user'] || !$cnf['password']) {
+                throw new Exception("MySQL login data not found at " . 
$uinfo['dir']);
             }
         }
-        if (!$return->username || $return->password) {
-            throw new Exception("Got no MySQL login data. I'm at" . 
$_SERVER['CONTEXT_DOCUMENT_ROOT']);
-        }
-        return $return;
+        return $cnf;
     }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I26da65203c064e5cc87760a6847dbe18e91ccc96
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/guc
Gerrit-Branch: master
Gerrit-Owner: Krinkle <krinklem...@gmail.com>

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

Reply via email to