Commit 15f305be authored by metzlerd's avatar metzlerd
Browse files

Add support for multiple drupal database connections.

parent 48059e78
......@@ -884,6 +884,7 @@ function forena_data_settings() {
}
function forena_data_settings_edit($form, &$form_state, $source=-1) {
global $databases;
$adding = ($source === -1);
if (!@$form_state['storage']) {
if ($adding) {
......@@ -894,6 +895,7 @@ function forena_data_settings_edit($form, &$form_state, $source=-1) {
'config' => array(
'source' => 'user',
'data provider' => 'FrxDrupal',
'database' => 'default',
'access callback' => 'user_access',
'user callback' => 'forena_current_user_id'
),
......@@ -1080,10 +1082,13 @@ function forena_data_settings_edit($form, &$form_state, $source=-1) {
switch ($data_provider) {
case 'FrxDrupal':
$form['connection']['uri'] = array(
'#type' => 'item',
'#title' => t('URI'),
$db_list = array_combine(array_keys($databases), array_keys($databases));
$form['connection']['database'] = array(
'#type' => 'select',
'#title' => t('Database'),
'#disabled' => $locked,
'#default_value' => @$config['database'],
'#options' => $db_list,
'#markup' => 'Determined by Drupal settings.php file',
);
break;
......
......@@ -10,7 +10,7 @@ class FrxDrupal extends FrxDataSource {
* Implements hooks into the drupal applications
*/
private $db;
private $database = 'default';
/**
* Object constructor
......@@ -20,7 +20,9 @@ class FrxDrupal extends FrxDataSource {
*/
public function __construct($conf, $repos_path, $name) {
parent::__construct($conf, $repos_path, $name);
if (@$conf['database'] != 'default') {
$this->database = $conf['database'];
}
// Set up the stuff required to translate.
$this->te = new FrxSyntaxEngine(FRX_SQL_TOKEN, ':', $this);
}
......@@ -32,6 +34,9 @@ class FrxDrupal extends FrxDataSource {
* @param Query $subQuery
*/
public function sqlData($sql) {
if ($this->database != 'default') {
db_set_active($this->database);
}
// Load the block from the file
$xml ='';
$sql = $this->te->replace($sql);
......@@ -46,6 +51,9 @@ class FrxDrupal extends FrxDataSource {
//$row_node->$key = $value;
}
}
if ($this->database != 'default') {
db_set_active();
}
return $xml;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment