/** * Initializes database confiigurations */ protected function initializeDatabaseConfiguration() { $params = $this->database->getParameterHolder()->getAll(); unset($params['classname']); $doctrine = new sfDoctrineDatabase($params); $this->connection = $doctrine->getDoctrineConnection(); $this->connection->getManager()->setAttribute(Doctrine::ATTR_IDXNAME_FORMAT, '%s'); $this->connection->getManager()->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true); $this->doctrineProcess = new opDoctrineMigrationProcess($this->connection); }
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ include dirname(__FILE__) . '/../bootstrap/unit.php'; $t = new lime_test(1); $parameters = array('name' => 'doctrine', 'dsn' => 'sqlite::memory'); class ProjectConfiguration extends sfProjectConfiguration { } $configuration = new ProjectConfiguration(dirname(__FILE__) . '/../../lib', new sfEventDispatcher()); $p = new sfDoctrineDatabase($parameters); $t->is($p->getDoctrineConnection()->getName(), 'doctrine', 'initialize() - creates a valid doctrine configuration from parameters');
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ include dirname(__FILE__) . '/../bootstrap/unit.php'; $t = new lime_test(4); class ProjectConfiguration extends sfProjectConfiguration { } $configuration = new ProjectConfiguration(dirname(__FILE__) . '/../../lib', new sfEventDispatcher()); $parameters = array('name' => 'doctrine', 'dsn' => 'sqlite::memory', 'attributes' => array('use_native_enum' => true, 'validate' => 'all', 'tblname_format' => 'test_%s')); $p = new sfDoctrineDatabase($parameters); $t->is($p->getDoctrineConnection()->getName(), 'doctrine', 'initialize() - creates a valid doctrine configuration from parameters'); $t->is($p->getDoctrineConnection()->getAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM), true, 'initialize() - setups doctrine attributes - attribute value is not a string'); $t->is($p->getDoctrineConnection()->getAttribute(Doctrine_Core::ATTR_VALIDATE), Doctrine_Core::VALIDATE_ALL, 'initialize() - setups doctrine attributes - attribute value is a string and constant exists'); $t->is($p->getDoctrineConnection()->getAttribute(Doctrine_Core::ATTR_TBLNAME_FORMAT), $parameters['attributes']['tblname_format'], 'initialize() - setups doctrine attributes - attribute value is a string and constant not exists');
function run_doctrine_build_sql($task, $args) { if (count($args) < 1) { throw new Exception('You must provide your app name.'); } $sf_root_dir = sfConfig::get('sf_root_dir'); define('SF_APP', $args[0]); $connection = isset($args[1]) ? $args[1] : 'all'; simpleAutoloader::registerCallable(array('Doctrine', 'autoload')); sfConfig::set('sf_app_module_dir', $sf_root_dir . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR); $doctrineSchemaPathScheme = DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR; $doctrineModelDir = sfConfig::get('sf_lib_dir') . $doctrineSchemaPathScheme; $generatedDir = $doctrineModelDir . 'generated' . DIRECTORY_SEPARATOR; $tmp_dir = $sf_root_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)); $db_connections = sfYaml::load($sf_root_dir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'databases.yml'); if (!isset($db_connections[$connection])) { throw new sfException('Unable to find connection: ' . $connection); } $connection = current($db_connections[$connection]); $db = new sfDoctrineDatabase(); $db->initialize($connection['param']); $directories = sfFinder::type('dir')->maxdepth(0)->ignore_version_control()->in(sfConfig::get('sf_model_lib_dir') . '/doctrine'); foreach ($directories as $directory) { $basename = basename($directory); $name = $basename == 'generated' ? 'doctrine' : 'doctrine-' . $basename; pake_echo_action("Building SQL", $name); $sql = implode(";\n\n", Doctrine::exportSql($directory)) . ";\n"; $sql = str_replace(array(" (", ") ", ","), array("(\n ", ")\n", ",\n"), $sql); if (!is_dir($sf_root_dir . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'sql')) { mkdir($sf_root_dir . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'sql'); } $fd = fopen($sf_root_dir . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . $name . '.model.sql', 'w+'); fwrite($fd, $sql); fclose($fd); } return; }