From b7b3103c492f704295b5359f90327243dfc80f52 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 24 Apr 2015 09:25:14 +0200 Subject: [PATCH] [UPDATE] Shared DB Behavior * Default to standard DB if nothing is set * Separate Accounts and Pool Workers shared DB * Added shared News DB * New config options added * `$config['db']['shared']['accounts']` * `$config['db']['shared']['workers']` * `$config['db']['shared']['news']` --- include/bootstrap.php | 10 ++++++++++ include/classes/coin_address.class.php | 2 +- include/classes/news.class.php | 13 ++++++++++++- include/classes/user.class.php | 2 +- include/classes/worker.class.php | 2 +- include/config/global.inc.dist.php | 6 +++++- 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/include/bootstrap.php b/include/bootstrap.php index 0e286a53..10f18225 100644 --- a/include/bootstrap.php +++ b/include/bootstrap.php @@ -14,6 +14,16 @@ $quickstartlink = "setConfig($config); - $this->table = $this->config['db']['shared']['name'] . '.' . $this->table; + $this->table = $this->config['db']['shared']['accounts'] . '.' . $this->table; } /** diff --git a/include/classes/news.class.php b/include/classes/news.class.php index b4de57e2..f0601f5b 100644 --- a/include/classes/news.class.php +++ b/include/classes/news.class.php @@ -4,6 +4,17 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; class News extends Base { protected $table = 'news'; + /** + * We allow changing the database for shared accounts across pools + * Load the config on construct so we can assign the DB name + * @param config array MPOS configuration + * @return none + **/ + public function __construct($config) { + $this->setConfig($config); + $this->table = $this->config['db']['shared']['news'] . '.' . $this->table; + } + /** * Get activation status of post * @param id int News ID @@ -96,7 +107,7 @@ class News extends Base { } } -$news = new News(); +$news = new News($config); $news->setDebug($debug); $news->setMysql($mysqli); $news->setUser($user); diff --git a/include/classes/user.class.php b/include/classes/user.class.php index c5ab0c34..b7b56da6 100644 --- a/include/classes/user.class.php +++ b/include/classes/user.class.php @@ -14,7 +14,7 @@ class User extends Base { **/ public function __construct($config) { $this->setConfig($config); - $this->table = $this->config['db']['shared']['name'] . '.' . $this->table; + $this->table = $this->config['db']['shared']['accounts'] . '.' . $this->table; } // get and set methods diff --git a/include/classes/worker.class.php b/include/classes/worker.class.php index 3f9569f9..fd0f2c9b 100644 --- a/include/classes/worker.class.php +++ b/include/classes/worker.class.php @@ -12,7 +12,7 @@ class Worker extends Base { **/ public function __construct($config) { $this->setConfig($config); - $this->table = $this->config['db']['shared']['name'] . '.' . $this->table; + $this->table = $this->config['db']['shared']['workers'] . '.' . $this->table; } /** diff --git a/include/config/global.inc.dist.php b/include/config/global.inc.dist.php index 464759a7..456e7791 100644 --- a/include/config/global.inc.dist.php +++ b/include/config/global.inc.dist.php @@ -54,7 +54,11 @@ $config['db']['user'] = 'someuser'; $config['db']['pass'] = 'somepass'; $config['db']['port'] = 3306; $config['db']['name'] = 'mpos'; -$config['db']['shared']['name'] = $config['db']['name']; +// Disabled by default and set in bootstrap if unset, but left in here so +// people know it exists +// $config['db']['shared']['accounts'] = $config['db']['name']; +// $config['db']['shared']['workers'] = $config['db']['name']; +// $config['db']['shared']['news'] = $config['db']['name']; /** * Local wallet RPC