Krinkle has submitted this change and it was merged. 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(-) Approvals: Krinkle: Verified; Looks good to me, approved 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: merged Gerrit-Change-Id: I26da65203c064e5cc87760a6847dbe18e91ccc96 Gerrit-PatchSet: 9 Gerrit-Project: labs/tools/guc Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Luxo <luxo...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits