Files
luos/workflow/engine/config/databases.php

104 lines
3.6 KiB
PHP
Raw Normal View History

2010-12-02 23:34:41 +00:00
<?php
2017-10-10 12:33:25 -04:00
if (defined('PATH_DB') && !empty(config("system.workspace"))) {
2017-12-04 13:25:35 +00:00
if (!file_exists(PATH_DB . config("system.workspace") . '/db.php')) {
2017-10-10 12:33:25 -04:00
throw new Exception("Could not find db.php in current workspace " . config("system.workspace"));
2017-12-04 13:25:35 +00:00
}
//These constants must not exist, they will be created by "db.php".
$constants = [
'DB_ADAPTER',
'DB_HOST',
'DB_NAME',
'DB_USER',
'DB_PASS',
'DB_RBAC_HOST',
'DB_RBAC_NAME',
'DB_RBAC_USER',
'DB_RBAC_PASS' ,
'DB_REPORT_HOST',
'DB_REPORT_NAME',
'DB_REPORT_USER',
'DB_REPORT_PASS',
];
$load = true;
foreach ($constants as $value) {
if (defined($value)) {
$load = false;
break;
}
}
if ($load === true) {
require_once(PATH_DB . config("system.workspace") . '/db.php');
}
2010-12-02 23:34:41 +00:00
//to do: enable for other databases
$dbType = DB_ADAPTER;
$dsn = DB_ADAPTER . '://' . DB_USER . ':' . urlencode(DB_PASS) . '@' . DB_HOST . '/' . DB_NAME;
2010-12-02 23:34:41 +00:00
//to do: enable a mechanism to select RBAC Database
$dsnRbac = DB_ADAPTER . '://' . DB_RBAC_USER . ':' . urlencode(DB_RBAC_PASS) . '@' . DB_RBAC_HOST . '/' . DB_RBAC_NAME;
2010-12-02 23:34:41 +00:00
//to do: enable a mechanism to select report Database
$dsnReport = DB_ADAPTER . '://' . DB_REPORT_USER . ':' . urlencode(DB_REPORT_PASS) . '@' . DB_REPORT_HOST . '/' . DB_REPORT_NAME;
2010-12-02 23:34:41 +00:00
switch (DB_ADAPTER) {
2014-07-03 09:45:15 -04:00
case 'mysql':
$dsn .= '?encoding=utf8';
$dsnRbac .= '?encoding=utf8';
2014-07-03 09:45:15 -04:00
$dsnReport .= '?encoding=utf8';
break;
case 'mssql':
case 'sqlsrv':
break;
default:
break;
}
2010-12-02 23:34:41 +00:00
$pro ['datasources']['workflow']['connection'] = $dsn;
$pro ['datasources']['workflow']['adapter'] = DB_ADAPTER;
2010-12-02 23:34:41 +00:00
$pro ['datasources']['rbac']['connection'] = $dsnRbac;
$pro ['datasources']['rbac']['adapter'] = DB_ADAPTER;
2010-12-02 23:34:41 +00:00
$pro ['datasources']['rp']['connection'] = $dsnReport;
$pro ['datasources']['rp']['adapter'] = DB_ADAPTER;
2020-07-24 15:35:12 +00:00
// "workflow" connection
$dbHost = explode(':', DB_HOST);
config(['database.connections.workflow.host' => $dbHost[0]]);
config(['database.connections.workflow.database' => DB_NAME]);
config(['database.connections.workflow.username' => DB_USER]);
config(['database.connections.workflow.password' => DB_PASS]);
if (count($dbHost) > 1) {
config(['database.connections.workflow.port' => $dbHost[1]]);
}
2020-07-24 15:35:12 +00:00
// "rbac" connection
$dbRbacHost = explode(':', DB_RBAC_HOST);
config(['database.connections.rbac.driver' => DB_ADAPTER]);
config(['database.connections.rbac.host' => $dbRbacHost[0]]);
config(['database.connections.rbac.database' => DB_RBAC_NAME]);
config(['database.connections.rbac.username' => DB_RBAC_USER]);
config(['database.connections.rbac.password' => DB_RBAC_PASS]);
if (count($dbRbacHost) > 1) {
config(['database.connections.rbac.port' => $dbRbacHost[1]]);
}
2020-07-27 19:54:47 +00:00
// "rp" connection
2020-07-24 15:35:12 +00:00
$dbReportHost = explode(':', DB_REPORT_HOST);
2020-07-27 19:54:47 +00:00
config(['database.connections.rp.driver' => DB_ADAPTER]);
config(['database.connections.rp.host' => $dbReportHost[0]]);
config(['database.connections.rp.database' => DB_REPORT_NAME]);
config(['database.connections.rp.username' => DB_REPORT_USER]);
config(['database.connections.rp.password' => DB_REPORT_PASS]);
2020-07-24 15:35:12 +00:00
if (count($dbReportHost) > 1) {
2020-07-27 19:54:47 +00:00
config(['database.connections.rp.port' => $dbReportHost[1]]);
2020-07-24 15:35:12 +00:00
}
2014-07-03 09:45:15 -04:00
}
2014-07-03 09:45:15 -04:00
$pro ['datasources']['dbarray']['connection'] = 'dbarray://user:pass@localhost/pm_os';
$pro ['datasources']['dbarray']['adapter'] = 'dbarray';
2010-12-02 23:34:41 +00:00
2014-07-03 09:45:15 -04:00
return $pro;