Merge pull request #2408 from MPOS/shared-db-update

[UPDATE] Shared DB Behavior
This commit is contained in:
Sebastian Grewe 2015-04-28 17:47:57 +02:00
commit 993972a3ec
7 changed files with 35 additions and 7 deletions

View File

@ -2,8 +2,11 @@
--------------------- ---------------------
* Allow SSO accross MPOS pools * Allow SSO accross MPOS pools
* Added a new config option `$config['db']['shared']['name']`, defaults to `$config['db']['name']` * Added a new config options
* Will access `accounts` and `pool_workers` on shared table * `$config['db']['shared']['acounts']`, defaults to `$config['db']['name']`
* `$config['db']['shared']['workers']`, defaults to `$config['db']['name']`
* `$config['db']['shared']['news']`, defaults to `$config['db']['name']`
* Will access `accounts`, `pool_workers` and `news` on shared table
* Does not allow splitting `accounts` and `pool_woker` across database hosts * Does not allow splitting `accounts` and `pool_woker` across database hosts
* Required `$config['cookie']['domain']` to be set * Required `$config['cookie']['domain']` to be set
* You need to use the top domain shared between hosts as the setting * You need to use the top domain shared between hosts as the setting

View File

@ -14,6 +14,16 @@ $quickstartlink = "<a href='https://github.com/MPOS/php-mpos/wiki/Quick-Start-Gu
if (!include_once(INCLUDE_DIR . '/config/global.inc.dist.php')) die('Unable to load base global config from ['.INCLUDE_DIR. '/config/global.inc.dist.php' . '] - '.$quickstartlink); if (!include_once(INCLUDE_DIR . '/config/global.inc.dist.php')) die('Unable to load base global config from ['.INCLUDE_DIR. '/config/global.inc.dist.php' . '] - '.$quickstartlink);
if (!@include_once(INCLUDE_DIR . '/config/global.inc.php')) die('Unable to load your global config from ['.INCLUDE_DIR. '/config/global.inc.php' . '] - '.$quickstartlink); if (!@include_once(INCLUDE_DIR . '/config/global.inc.php')) die('Unable to load your global config from ['.INCLUDE_DIR. '/config/global.inc.php' . '] - '.$quickstartlink);
// Check for a shared account database and set to default DB if unset
if (!isset($config['db']['shared']['accounts']))
$config['db']['shared']['accounts'] = $config['db']['name'];
// Check for a shared worker database and set to default DB if unset
if (!isset($config['db']['shared']['workers']))
$config['db']['shared']['workers'] = $config['db']['name'];
// Check for a shared news database and set to default DB if unset
if (!isset($config['db']['shared']['news']))
$config['db']['shared']['news'] = $config['db']['name'];
// load our security configs // load our security configs
if (!include_once(INCLUDE_DIR . '/config/security.inc.dist.php')) die('Unable to load base security config from ['.INCLUDE_DIR. '/config/security.inc.dist.php' . '] - '.$quickstartlink); if (!include_once(INCLUDE_DIR . '/config/security.inc.dist.php')) die('Unable to load base security config from ['.INCLUDE_DIR. '/config/security.inc.dist.php' . '] - '.$quickstartlink);
if (@file_exists(INCLUDE_DIR . '/config/security.inc.php')) include_once(INCLUDE_DIR . '/config/security.inc.php'); if (@file_exists(INCLUDE_DIR . '/config/security.inc.php')) include_once(INCLUDE_DIR . '/config/security.inc.php');

View File

@ -12,7 +12,7 @@ class CoinAddress extends Base {
**/ **/
public function __construct($config) { public function __construct($config) {
$this->setConfig($config); $this->setConfig($config);
$this->table = $this->config['db']['shared']['name'] . '.' . $this->table; $this->table = $this->config['db']['shared']['accounts'] . '.' . $this->table;
} }
/** /**

View File

@ -4,6 +4,17 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
class News extends Base { class News extends Base {
protected $table = 'news'; 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 * Get activation status of post
* @param id int News ID * @param id int News ID
@ -96,7 +107,7 @@ class News extends Base {
} }
} }
$news = new News(); $news = new News($config);
$news->setDebug($debug); $news->setDebug($debug);
$news->setMysql($mysqli); $news->setMysql($mysqli);
$news->setUser($user); $news->setUser($user);

View File

@ -14,7 +14,7 @@ class User extends Base {
**/ **/
public function __construct($config) { public function __construct($config) {
$this->setConfig($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 // get and set methods

View File

@ -12,7 +12,7 @@ class Worker extends Base {
**/ **/
public function __construct($config) { public function __construct($config) {
$this->setConfig($config); $this->setConfig($config);
$this->table = $this->config['db']['shared']['name'] . '.' . $this->table; $this->table = $this->config['db']['shared']['workers'] . '.' . $this->table;
} }
/** /**

View File

@ -54,7 +54,11 @@ $config['db']['user'] = 'someuser';
$config['db']['pass'] = 'somepass'; $config['db']['pass'] = 'somepass';
$config['db']['port'] = 3306; $config['db']['port'] = 3306;
$config['db']['name'] = 'mpos'; $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 * Local wallet RPC