[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']`
This commit is contained in:
Sebastian Grewe 2015-04-24 09:25:14 +02:00
parent bb3fa99530
commit b7b3103c49
6 changed files with 30 additions and 5 deletions

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.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
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');

View File

@ -12,7 +12,7 @@ class CoinAddress 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;
}
/**

View File

@ -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);

View File

@ -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

View File

@ -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;
}
/**

View File

@ -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