added support for database administration user (closes #24)

This commit is contained in:
Steffen Vogel 2010-11-01 11:53:17 +01:00
parent 8a1e0a0e7f
commit 48346c160d
3 changed files with 19 additions and 6 deletions

View file

@ -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();
?>
?>

View file

@ -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);
}
}

View file

@ -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