Exemple #1
0
 protected function _initDoctrine()
 {
     $config = $this->getOptions();
     $manager = Doctrine_Manager::getInstance();
     $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
     $manager->setAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_CHARSET, 'utf8');
     $manager->setAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_COLLATE, 'utf8_unicode_ci');
     $manager->setAttribute(Doctrine_Core::ATTR_DEFAULT_TABLE_TYPE, 'INNODB');
     $manager->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true);
     $manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, false);
     $manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
     // enable validation on save()
     $manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
     $manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
     if ($config['doctrine']['cache']) {
         $cacheDriver = new Doctrine_Cache_Apc();
         $manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
     }
     $conn = Doctrine_Manager::connection($config['doctrine']['dsn']);
     $conn->setCharset('utf8');
     try {
         Doctrine_Core::createDatabases();
     } catch (Exception $e) {
     }
     $conn = Doctrine_Core::loadModels(APPLICATION_PATH . '/models', Doctrine_Core::MODEL_LOADING_AGGRESSIVE);
     $conn = Doctrine_Core::createTablesFromModels();
     return $manager;
 }
Exemple #2
0
 static function setUp()
 {
     try {
         Doctrine_Core::dropDatabases();
     } catch (Exception $e) {
     }
     Doctrine_Manager::connection()->clear();
     try {
         Doctrine_Core::createDatabases();
     } catch (Exception $e) {
     }
     Doctrine_Core::loadModels(APPLICATION_PATH . '/models', Doctrine_Core::MODEL_LOADING_AGGRESSIVE);
     Doctrine_Core::createTablesFromModels();
 }
<?php

$_test_dir = realpath(dirname(__FILE__) . '/..');
// configuration
require_once dirname(__FILE__) . '/../../../../config/ProjectConfiguration.class.php';
$configuration = ProjectConfiguration::hasActive() ? ProjectConfiguration::getActive() : new ProjectConfiguration(realpath($_test_dir . '/..'));
// autoloader
$autoload = sfSimpleAutoload::getInstance(sfConfig::get('sf_cache_dir') . '/project_autoload.cache');
$autoload->loadConfiguration(sfFinder::type('file')->name('autoload.yml')->in(array(sfConfig::get('sf_symfony_lib_dir') . '/config/config', sfConfig::get('sf_config_dir'))));
$autoload->register();
// lime
include $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true);
//Remove test dirs
$rootdir = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . 'test_root';
if (is_dir($rootdir)) {
    $files = sfFinder::type('any')->maxdepth(4)->in($rootdir);
    array_unshift($files, $rootdir);
    $fs = new sfFileSystem();
    $fs->remove($files);
}
new sfDatabaseManager($configuration);
Doctrine_Core::dropDatabases();
Doctrine_Core::createDatabases();
Doctrine_Core::createTablesFromModels(sfConfig::get('sf_lib_dir') . '/model');
Exemple #4
0
 public static function syncdb($apps = null, $drop_database = false, $append = true)
 {
     if (!self::$inited || !self::$connections) {
         self::init();
     }
     if (!$apps) {
         $apps = ini('base/INSTALLED_APPS');
     }
     if (!$apps) {
         return true;
     }
     if ($drop_database) {
         Doctrine_Core::dropDatabases();
         Doctrine_Core::createDatabases();
     }
     foreach ((array) $apps as $k => $app) {
         $app = str_replace('.', '/', $app);
         try {
             /*
              * Generate the models
              */
             if (isset($_GET['use_yaml'])) {
                 $schemas = Package::get_file(sprintf('applications/%s/%s', $app, 'schemas.yml'));
                 if (!is_file($schemas)) {
                     continue;
                 }
                 Doctrine_Core::generateModelsFromYaml($schemas, Package::get_folder(sprintf('applications/%s/models', $app)), self::$_generate_options);
             } else {
                 try {
                     import(sprintf('applications/%s/models/generated/*', $app));
                 } catch (DoesNotExistsException $e) {
                     continue;
                 }
             }
             /*
              * syncdb
              */
             Doctrine_Core::createTablesFromModels(Package::get_folder(sprintf('applications/%s/models', $app)), self::$_generate_options);
             /*
              * Insert test data
              */
             $dir = Package::get_folder(sprintf('applications/%s/fixtures', $app));
             if (is_dir($dir)) {
                 Doctrine_Core::loadData($dir, $append);
             }
         } catch (PDOException $e) {
             continue;
         }
     }
 }