mirror of https://github.com/MISP/MISP
chg: [AppController] move the database connection setup to a dedicated function on the AppComponent
This removes a bit of clutter from the already large beforeFilter method and allows other views to resuse the logic without having to duplicate it.pull/5187/head
parent
013b3ac619
commit
96311ef480
|
@ -124,17 +124,8 @@ class AppController extends Controller
|
||||||
if (!empty($this->params['named']['sql'])) {
|
if (!empty($this->params['named']['sql'])) {
|
||||||
$this->sql_dump = 1;
|
$this->sql_dump = 1;
|
||||||
}
|
}
|
||||||
// check for a supported datasource configuration
|
|
||||||
$dataSourceConfig = ConnectionManager::getDataSource('default')->config;
|
$this->_setupDatabaseConnection();
|
||||||
if (!isset($dataSourceConfig['encoding'])) {
|
|
||||||
$db = ConnectionManager::getDataSource('default');
|
|
||||||
$db->setConfig(array('encoding' => 'utf8'));
|
|
||||||
ConnectionManager::create('default', $db->config);
|
|
||||||
}
|
|
||||||
$dataSource = $dataSourceConfig['datasource'];
|
|
||||||
if ($dataSource != 'Database/Mysql' && $dataSource != 'Database/Postgres') {
|
|
||||||
throw new Exception('datasource not supported: ' . $dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->set('ajax', $this->request->is('ajax'));
|
$this->set('ajax', $this->request->is('ajax'));
|
||||||
$this->set('queryVersion', $this->__queryVersion);
|
$this->set('queryVersion', $this->__queryVersion);
|
||||||
|
@ -506,6 +497,24 @@ class AppController extends Controller
|
||||||
$this->render('/Servers/json/simple');
|
$this->render('/Servers/json/simple');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Setup & validate the database connection configuration
|
||||||
|
* @throws Exception if the configured database is not supported.
|
||||||
|
*/
|
||||||
|
protected function _setupDatabaseConnection() {
|
||||||
|
// check for a supported datasource configuration
|
||||||
|
$dataSourceConfig = ConnectionManager::getDataSource('default')->config;
|
||||||
|
if (!isset($dataSourceConfig['encoding'])) {
|
||||||
|
$db = ConnectionManager::getDataSource('default');
|
||||||
|
$db->setConfig(array('encoding' => 'utf8'));
|
||||||
|
ConnectionManager::create('default', $db->config);
|
||||||
|
}
|
||||||
|
$dataSource = $dataSourceConfig['datasource'];
|
||||||
|
if ($dataSource != 'Database/Mysql' && $dataSource != 'Database/Postgres') {
|
||||||
|
throw new Exception('datasource not supported: ' . $dataSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sanitize the configured `MISP.baseurl` and expose it to the view as `baseurl`.
|
* Sanitize the configured `MISP.baseurl` and expose it to the view as `baseurl`.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue