diff --git a/backend/bin/doctrine.php b/backend/bin/doctrine.php index e632ac1..b9bd2d3 100644 --- a/backend/bin/doctrine.php +++ b/backend/bin/doctrine.php @@ -32,7 +32,7 @@ define('VZ_DIR', realpath(__DIR__ . '/../..')); define('VZ_BACKEND_DIR', VZ_DIR . '/backend'); // class autoloading -require VZ_BACKEND_DIR . '/lib/Util/ClassLoader.php'; +require_once VZ_BACKEND_DIR . '/lib/Util/ClassLoader.php'; $classLoaders = array(); $classLoaders[] = new Volkszaehler\Util\ClassLoader('Doctrine', VZ_BACKEND_DIR . '/lib/vendor/Doctrine'); @@ -46,7 +46,7 @@ foreach ($classLoaders as $loader) { // load configuration Util\Configuration::load(VZ_BACKEND_DIR . '/volkszaehler.conf'); -$em = Volkszaehler\Router::createEntityManager(); +$em = Volkszaehler\Router::createEntityManager(TRUE); // get admin credentials $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array( 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), @@ -80,4 +80,4 @@ $cli->addCommands(array( )); $cli->run(); -?> \ No newline at end of file +?> diff --git a/backend/lib/Router.php b/backend/lib/Router.php index b220e60..6b3267d 100644 --- a/backend/lib/Router.php +++ b/backend/lib/Router.php @@ -206,7 +206,7 @@ class Router { * @todo add other caching drivers (memcache, xcache) * @todo put into static class? singleton? function or state class? */ - public static function createEntityManager() { + public static function createEntityManager($admin = FALSE) { $config = new \Doctrine\ORM\Configuration; if (extension_loaded('apc') && Util\Configuration::read('devmode') == FALSE) { @@ -222,7 +222,12 @@ class Router { $config->setProxyNamespace('Volkszaehler\Model\Proxy'); $config->setAutoGenerateProxyClasses(Util\Configuration::read('devmode')); - return \Doctrine\ORM\EntityManager::create(Util\Configuration::read('db'), $config); + $dbConfig = Util\Configuration::read('db'); + if ($admin) { + $dbConfig = array_merge($dbConfig, $dbConfig['admin']); + } + + return \Doctrine\ORM\EntityManager::create($dbConfig, $config); } } diff --git a/backend/volkszaehler.conf.default.php b/backend/volkszaehler.conf.default.php index 09ad23f..bceef5a 100644 --- a/backend/volkszaehler.conf.default.php +++ b/backend/volkszaehler.conf.default.php @@ -52,11 +52,19 @@ $config['db']['user'] = 'vz'; $config['db']['password'] = 'demo'; /** - * @var string name of the database the backend should use + * @var string backend database * @link http://www.doctrine-project.org/projects/dbal/2.0/docs/reference/configuration/en */ $config['db']['dbname'] = 'volkszaehler'; +/* + * For administration tasks (doctrine cli) + * the following $['db']['admin'] settings will be merged with $config['db'] + */ +//$config['db']['admin']['user'] = 'vz_admin'; +//$config['db']['admin']['password'] = 'admin_demo'; + + /** * @var string path of the sqlite database * @link http://www.doctrine-project.org/projects/dbal/2.0/docs/reference/configuration/en