Skip to content

Commit 993972a

Browse files
committed
Merge pull request #2408 from MPOS/shared-db-update
[UPDATE] Shared DB Behavior
2 parents da8b3cc + 9437746 commit 993972a

File tree

7 files changed

+35
-7
lines changed

7 files changed

+35
-7
lines changed

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
---------------------
33

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

include/bootstrap.php

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
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);
1515
if (!@include_once(INCLUDE_DIR . '/config/global.inc.php')) die('Unable to load your global config from ['.INCLUDE_DIR. '/config/global.inc.php' . '] - '.$quickstartlink);
1616

17+
// Check for a shared account database and set to default DB if unset
18+
if (!isset($config['db']['shared']['accounts']))
19+
$config['db']['shared']['accounts'] = $config['db']['name'];
20+
// Check for a shared worker database and set to default DB if unset
21+
if (!isset($config['db']['shared']['workers']))
22+
$config['db']['shared']['workers'] = $config['db']['name'];
23+
// Check for a shared news database and set to default DB if unset
24+
if (!isset($config['db']['shared']['news']))
25+
$config['db']['shared']['news'] = $config['db']['name'];
26+
1727
// load our security configs
1828
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);
1929
if (@file_exists(INCLUDE_DIR . '/config/security.inc.php')) include_once(INCLUDE_DIR . '/config/security.inc.php');

include/classes/coin_address.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class CoinAddress extends Base {
1212
**/
1313
public function __construct($config) {
1414
$this->setConfig($config);
15-
$this->table = $this->config['db']['shared']['name'] . '.' . $this->table;
15+
$this->table = $this->config['db']['shared']['accounts'] . '.' . $this->table;
1616
}
1717

1818
/**

include/classes/news.class.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
class News extends Base {
55
protected $table = 'news';
66

7+
/**
8+
* We allow changing the database for shared accounts across pools
9+
* Load the config on construct so we can assign the DB name
10+
* @param config array MPOS configuration
11+
* @return none
12+
**/
13+
public function __construct($config) {
14+
$this->setConfig($config);
15+
$this->table = $this->config['db']['shared']['news'] . '.' . $this->table;
16+
}
17+
718
/**
819
* Get activation status of post
920
* @param id int News ID
@@ -96,7 +107,7 @@ public function addNews($account_id, $aData, $active=false) {
96107
}
97108
}
98109

99-
$news = new News();
110+
$news = new News($config);
100111
$news->setDebug($debug);
101112
$news->setMysql($mysqli);
102113
$news->setUser($user);

include/classes/user.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class User extends Base {
1414
**/
1515
public function __construct($config) {
1616
$this->setConfig($config);
17-
$this->table = $this->config['db']['shared']['name'] . '.' . $this->table;
17+
$this->table = $this->config['db']['shared']['accounts'] . '.' . $this->table;
1818
}
1919

2020
// get and set methods

include/classes/worker.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Worker extends Base {
1212
**/
1313
public function __construct($config) {
1414
$this->setConfig($config);
15-
$this->table = $this->config['db']['shared']['name'] . '.' . $this->table;
15+
$this->table = $this->config['db']['shared']['workers'] . '.' . $this->table;
1616
}
1717

1818
/**

include/config/global.inc.dist.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@
5454
$config['db']['pass'] = 'somepass';
5555
$config['db']['port'] = 3306;
5656
$config['db']['name'] = 'mpos';
57-
$config['db']['shared']['name'] = $config['db']['name'];
57+
// Disabled by default and set in bootstrap if unset, but left in here so
58+
// people know it exists
59+
// $config['db']['shared']['accounts'] = $config['db']['name'];
60+
// $config['db']['shared']['workers'] = $config['db']['name'];
61+
// $config['db']['shared']['news'] = $config['db']['name'];
5862

5963
/**
6064
* Local wallet RPC

0 commit comments

Comments
 (0)