/** * Provides a array with all model names * * @return array */ public function loadModels() { $models = Doctrine::loadModels($this->modelDir, Doctrine::MODEL_LOADING_CONSERVATIVE); $models = Doctrine::initializeModels($models); $this->models = Doctrine::filterInvalidModels($models); return $this->models; }
public function testTest() { $models1 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine::MODEL_LOADING_CONSERVATIVE); $models2 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); $models1 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models1'); $models2 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models1'); $this->assertEqual($models1, $models2); $models1 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine::MODEL_LOADING_CONSERVATIVE); $models2 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); $models1 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine::MODEL_LOADING_CONSERVATIVE); $models2 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); $models1 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models2'); $models2 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models2'); $this->assertEqual($models1, $models2); $models1 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine::MODEL_LOADING_CONSERVATIVE); $models2 = Doctrine::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); $models1 = Doctrine::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2')); $models2 = Doctrine::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2')); $this->assertEqual($models1, $models2); $models1 = Doctrine::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2'), Doctrine::MODEL_LOADING_CONSERVATIVE); $models2 = Doctrine::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2'), Doctrine::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); }
function doctrine_load_models() { if (file_exists(MODELS_DIRECTORY . DS . 'generated')) { Doctrine::loadModels(MODELS_DIRECTORY . DS . 'generated'); Doctrine::loadModels(MODELS_DIRECTORY); } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $this->logSection('doctrine', 'created tables successfully'); $databaseManager = new sfDatabaseManager($this->configuration); Doctrine::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine', Doctrine::MODEL_LOADING_CONSERVATIVE); Doctrine::createTablesFromArray(Doctrine::getLoadedModels()); }
public function init() { $options = $this->getOptions(); if (isset($options['configFile'])) { $config = new Zend_Config_Ini($options['configFile']); $config = $config->toArray(); } else { $config = array(); } require_once 'Doctrine.php'; spl_autoload_register(array('Doctrine', 'autoload')); $manager = Doctrine_Manager::getInstance(); $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE); Zend_Registry::set('db_manager', $manager); if (isset($config['uri'])) { $connection = Doctrine_Manager::connection($config['uri']); } if (isset($config['modelsPath'])) { $this->_modelsPath = $config['modelsPath']; Doctrine::loadModels($this->_modelsPath); } if (isset($config['schemaPath'])) { $this->_schemaPath = $config['schemaPath']; } return $this; }
public function setup() { $db = $this->databasemanager->getDatabase('doctrine'); /* @var $db sfDoctrineDatabase */ // Special Handling for postgre, since droping even when closing the connection, fails with // SQLSTATE[55006]: Object in use: 7 ERROR: database "cs_doctrine_act_as_sortable_test" is being accessed by other users DETAIL: There are 1 other session(s) using the database. if ($db->getDoctrineConnection() instanceof Doctrine_Connection_Pgsql) { try { $db->getDoctrineConnection()->createDatabase(); } catch (Exception $e) { } $export = new Doctrine_Export_Pgsql($db->getDoctrineConnection()); $import = new Doctrine_Import_Pgsql($db->getDoctrineConnection()); $tablenames = array(SortableArticleTable::getInstance()->getTableName(), SortableArticleUniqueByTable::getInstance()->getTableName(), SortableArticleCategoryTable::getInstance()->getTableName()); foreach ($tablenames as $tablename) { if ($import->tableExists($tablename)) { $export->dropTable($tablename); } } } else { try { // ignore error if database does not yet exist (clean CI-env) $db->getDoctrineConnection()->dropDatabase(); } catch (Exception $e) { } $db->getDoctrineConnection()->createDatabase(); } // Using Doctrine instead of Doctrine_Core keeps it symfony 1.2 compatible, which uses Doctrine::loadModels(dirname(__FILE__) . '/../fixtures/project/lib/model/doctrine', Doctrine::MODEL_LOADING_CONSERVATIVE); Doctrine::createTablesFromArray(Doctrine::getLoadedModels()); Doctrine::loadData(dirname(__FILE__) . '/../fixtures/project/data/fixtures/categories.yml'); }
public function testConservativeModelLoading() { $path = realpath('ModelLoadingTest/Conservative'); $models = Doctrine::loadModels($path, Doctrine::MODEL_LOADING_CONSERVATIVE); $this->assertTrue(!class_exists('ConservativeModelLoadingUser', false)); $this->assertTrue(!class_exists('ConservativeModelLoadingProfile', false)); $this->assertTrue(!class_exists('ConservativeModelLoadingContact', false)); $this->assertTrue(!class_exists('BaseConservativeModelLoadingUser', false)); }
public function execute() { Doctrine::loadModels($this->getArgument('models_path')); $dql = $this->getArgument('dql_query'); $query = new Doctrine_Query(); $this->notify('executing: "' . $dql . '"'); $results = $query->query($dql); $this->printResults($results); }
public function execute() { Doctrine::loadModels($this->getArgument('models_path')); $path = $this->getArgument('data_fixtures_path'); if (is_array($path)) { $path = $path[0]; } Doctrine::dumpData($path); $this->dispatcher->notify(sprintf('Dumped data successfully to: %s', $path)); }
public function generateClassFromTable(Doctrine_Table $table) { $definition = array(); $definition['columns'] = $table->getColumns(); $definition['tableName'] = $table->getTableName(); $definition['actAs'] = $table->getTemplates(); $definition['generate_once'] = true; $generatedclass = $this->generateClass($definition); Doctrine::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine/opCommunityTopicPlugin/base/'); return $generatedclass; }
public function execute() { Doctrine::loadModels($this->getArgument('models_path')); $dql = $this->getArgument('dql_query'); $query = new Doctrine_Query(); $params = $this->getArgument('params'); $params = $params ? explode(',', $params) : array(); $this->notify('executing: "' . $dql . '" (' . implode(', ', $params) . ')'); $results = $query->query($dql, $params, Doctrine::HYDRATE_ARRAY); $this->_printResults($results); }
public static function remove(&$metadata) { $package = Doctrine::getTable('Package')->findOneByName($metadata['packageName']); if ($package) { Package_Message::log('debug', 'Remove package entry for ' . $metadata['packageName'] . '@' . $metadata['basedir'] . ' (' . $package['package_id'] . ')'); $package->delete(); } if (!empty($metadata['models'])) { $models = Doctrine::loadModels($metadata['directory'] . '/models', Doctrine::MODEL_LOADING_CONSERVATIVE); self::removeNumberType($models); } }
protected function _initDoctrine() { //Load the autoloader Zend_Loader_Autoloader::getInstance()->registerNamespace('Doctrine')->pushAutoloader(array('Doctrine', 'autoload')); $manager = Doctrine_Manager::getInstance(); foreach ($this->_options['doctrine']['attr'] as $key => $val) { $manager->setAttribute(eval("return Doctrine::{$key};"), $val); } $manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL); $conn = Doctrine_Manager::connection($this->_options['doctrine']['dsn'], 'doctrine'); Doctrine::loadModels($this->_options["doctrine"]["module_directories"]); }
public function execute() { Doctrine::loadModels($this->getArgument('models_path')); $path = $this->getArgument('data_fixtures_path'); if (is_array($path) && count($path) > 0) { $path = $path[0]; Doctrine::dumpData($path); $this->notify(sprintf('Dumped data successfully to: %s', $path)); } else { throw new Doctrine_Task_Exception('Unable to find data fixtures path.'); } }
/** * buildSchema * * Build schema array that can be dumped to file * * @param string $directory * @return void */ public function buildSchema($directory = null, $models = array()) { if ($directory) { $loadedModels = Doctrine::loadModels($directory); } else { $loadedModels = Doctrine::getLoadedModels(); } $array = array(); $parent = new ReflectionClass('Doctrine_Record'); $sql = array(); $fks = array(); // we iterate trhough the diff of previously declared classes // and currently declared classes foreach ($loadedModels as $className) { if (!empty($models) && !in_array($className, $models)) { continue; } $record = new $className(); $recordTable = $record->getTable(); $data = $recordTable->getExportableFormat(); $table = array(); foreach ($data['columns'] as $name => $column) { $data['columns'][$name]['type'] = $column['type'] . '(' . $column['length'] . ')'; unset($data['columns'][$name]['length']); } $table['columns'] = $data['columns']; $relations = $recordTable->getRelations(); foreach ($relations as $key => $relation) { $relationData = $relation->toArray(); $relationKey = $relationData['alias']; if (isset($relationData['refTable']) && $relationData['refTable']) { $table['relations'][$relationKey]['refClass'] = $relationData['refTable']->getComponentName(); } if (isset($relationData['class']) && $relationData['class'] && $relation['class'] != $relationKey) { $table['relations'][$relationKey]['class'] = $relationData['class']; } $table['relations'][$relationKey]['local'] = $relationData['local']; $table['relations'][$relationKey]['foreign'] = $relationData['foreign']; if ($relationData['type'] === Doctrine_Relation::ONE) { $table['relations'][$relationKey]['type'] = 'one'; } else { if ($relationData['type'] === Doctrine_Relation::MANY) { $table['relations'][$relationKey]['type'] = 'many'; } else { $table['relations'][$relationKey]['type'] = 'one'; } } } $array[$className] = $table; } return $array; }
protected function _initDoctrine() { $this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine', 'autoload')); spl_autoload_register(array('Doctrine', 'modelsAutoload')); $doctrineConfig = $this->getOption('doctrine'); $manager = Doctrine_Manager::getInstance(); $manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true); $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, $doctrineConfig['model_autoloading']); Doctrine::loadModels($doctrineConfig['models_path']); $conn = Doctrine_Manager::connection($doctrineConfig['dsn'], 'doctrine'); $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true); return $conn; }
protected function execute($arguments = array(), $options = array()) { $configuration = ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env'], true); $databaseManager = new sfDatabaseManager($configuration); $databaseManager->initialize($configuration); $dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures'; $excludedModels = array('Modification', 'ModificationField'); Doctrine::loadModels(sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . 'doctrine'); $loadedModels = Doctrine::getLoadedModels(); $models = array_diff($loadedModels, $excludedModels); $data = new Doctrine_Data(); $data->exportData($dir, 'yml', $models, false); }
public function main() { Doctrine_Manager::connection($this->dsn, self::DB_NAME); Doctrine::loadModels($this->modelPath . "/generated/"); Doctrine::setModelsDirectory($this->modelPath . "/"); if ($this->action == 'dropDB') { $this->dropDB(); } else { if ($this->action = "truncateTable" && $this->targetTable) { Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh()->query("truncate table " . $this->targetTable . ";"); } } }
protected function _diff($from, $to) { $fromModels = Doctrine::initializeModels(Doctrine::loadModels($from, Doctrine::MODEL_LOADING_AGGRESSIVE)); $toModels = Doctrine::initializeModels(Doctrine::loadModels($to, Doctrine::MODEL_LOADING_AGGRESSIVE)); // Build schema information for the models $fromInfo = $this->_buildModelInformation($fromModels); $toInfo = $this->_buildModelInformation($toModels); $this->_decreaseInformations($fromInfo, $toInfo); // Build array of changes between the from and to information $changes = $this->_buildChanges($fromInfo, $toInfo); $this->_cleanup(); return $changes; }
public function __construct(Koch\Config $config, Koch\User\User $user) { $this->config = $config; $this->curTimestamp = time(); $this->curDate = date('d.m.Y', $this->curTimestamp); $this->user = $user; // Load Models Doctrine::loadModels(APPLICATION_MODULES_PATH . 'statistics/model/records/generated/'); Doctrine::loadModels(APPLICATION_MODULES_PATH . 'statistics/model/records/'); $cfg = $config->readModuleConfig('statistics'); $this->statsWhoDeleteTime = $cfg['statistics']['deleteTimeWho']; $this->statsWhoTimeout = $cfg['statistics']['timoutWho']; }
public function setUp() { parent::setUp(); if (isset($GLOBALS['DOCTRINE_DSN']) && strlen($GLOBALS['DOCTRINE_DSN'])) { Doctrine_Manager::connection($GLOBALS['DOCTRINE_DSN']); } else { Doctrine_Manager::connection('sqlite::memory:'); } Doctrine::loadModels(dirname(__FILE__) . '/_files/models'); try { Doctrine::createTablesFromModels(); } catch (Doctrine_Export_Exception $e) { } }
/** * Rebuilds a db as described by the doctrine models * */ public function buildDBFromModels() { $icinga = $this->project->getUserProperty("PATH_Icinga"); $modelPath = $icinga . "/app/modules/" . $this->project->getUserProperty("MODULE_Name") . "/lib/"; $appKitPath = $this->project->getUserProperty("PATH_AppKit"); Doctrine::loadModels($icinga . "/" . $appKitPath . "database/models/generated/"); Doctrine::loadModel($icinga . "/" . $appKitPath . "database/models/"); $tables = Doctrine::getLoadedModels(); $tableList = array(); foreach ($tables as $table) { $tableList[] = Doctrine::getTable($table)->getTableName(); } Doctrine::createTablesFromModels(array($this->models . '/generated', $this->models)); file_put_contents($modelPath . "/.models.cfg", implode(",", $tableList)); }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $this->runTask('doctrine:drop-db', '--no-confirmation'); $this->runTask('doctrine:create-db'); // ATTENTION: HACK TO MAKE THIS WORK UNDER UBUNTU LINUX Doctrine::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine'); $this->runTask('doctrine:insert-sql'); $this->runTask('doctrine:data-load', 'data/fixtures/user.yml'); $this->runTask('doctrine:data-load', 'data/fixtures/templates.yml'); $this->runTask('doctrine:data-load', 'data/fixtures/test'); $this->runTask('siwapp:calculate-totals', '--all'); $this->logSection('siwapp', 'Test data succesfully loaded'); }
function model_boostrap() { require_library("/vendor/doctrine/Doctrine.php"); spl_autoload_register(array('doctrine', 'autoload')); $conn = Doctrine_Manager::connection(dsn); $conn->setCollate('utf8_general_ci'); $conn->setCharset('utf8'); $conn->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true); $conn->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true); $servers = array('host' => 'localhost', 'port' => 11211, 'persistent' => true); $cacheDriver = new Doctrine_Cache_Memcache(array('servers' => $servers, 'compression' => false)); $conn->setAttribute(Doctrine::ATTR_QUERY_CACHE, $cacheDriver); Doctrine::loadModels(library_root . '/models/dal'); Doctrine::loadModels(library_root . '/models'); }
public function clearData() { Doctrine::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine'); $models = Doctrine::getLoadedModels(); foreach ($models as $model) { try { Doctrine::getTable($model)->createQuery()->delete()->execute(); } catch (Doctrine_Connection_Exception $e) { // if couldn't delete the first time, try it again at the end $models[] = $model; unset($models[array_search($model, $models)]); } } return $this; }
public function testImportOfHieriarchyOfPluginGeneration() { $yml = <<<END --- WikiTest: actAs: I18n: fields: [title, content] actAs: Versionable: fields: [title, content] Searchable: fields: [title, content] Sluggable: fields: [title] columns: title: string(255) content: string END; file_put_contents('wiki.yml', $yml); $path = dirname(__FILE__) . '/tmp/import_builder_test'; $import = new Doctrine_Import_Schema(); $import->setOption('generateTableClasses', true); $import->importSchema('wiki.yml', 'yml', $path); // check that the plugin hierarchy will produce the right sql statements // this is almost an end-to-end testing :-) $models = Doctrine::loadModels($path, Doctrine::MODEL_LOADING_CONSERVATIVE); $sql = $this->conn->export->exportClassesSql(array('WikiTest')); $result = array( 0 => 'CREATE TABLE wiki_test_translation_version (id INTEGER, lang CHAR(2), title VARCHAR(255), content VARCHAR(2147483647), version INTEGER, PRIMARY KEY(id, lang, version))', 1 => 'CREATE TABLE wiki_test_translation_index (id INTEGER, lang CHAR(2), keyword VARCHAR(200), field VARCHAR(50), position INTEGER, PRIMARY KEY(id, lang, keyword, field, position))', 2 => 'CREATE TABLE wiki_test_translation (id INTEGER, title VARCHAR(255), content VARCHAR(2147483647), lang CHAR(2), version INTEGER, slug VARCHAR(255), PRIMARY KEY(id, lang))', 3 => 'CREATE TABLE wiki_test (id INTEGER PRIMARY KEY AUTOINCREMENT)', 4 => 'CREATE INDEX sluggable_idx ON wiki_test_translation (slug)', ); foreach($sql as $idx => $req) { $this->assertEqual($req, $result[$idx]); } Doctrine_Lib::removeDirectories($path); unlink('wiki.yml'); }
/** * Initialize Doctrine paths * * @param array $options * @return void */ protected function _initPaths($options = array()) { $this->_resources['paths'] = $options; // set default options $paths =& $this->_resources['paths']; // apply default paths if not set in application.ini $defaults = array('data_fixtures_path' => APPLICATION_PATH . '/../doctrine/data/fixtures/', 'models_path' => APPLICATION_PATH . '/models/', 'generated_models_path' => APPLICATION_PATH . '/models/generated/', 'migrations_path' => APPLICATION_PATH . '/../doctrine/migrations/', 'sql_path' => APPLICATION_PATH . '/../doctrine/data/sql/', 'yaml_schema_path' => APPLICATION_PATH . '/../doctrine/schema/'); foreach ($defaults as $key => $path) { if (!isset($paths[$key])) { $paths[$key] = $path; } } $application = $this->getBootstrap()->getApplication(); $application->setOptions(array('doctrine' => $paths)); Doctrine::loadModels($paths['models_path']); }
public function __get($key) { try { return Doctrine::GetTable($key); } catch (Doctrine_Connection_Exception $ex) { $models = $this->config->application->get("folders/model"); var_dump($models); Doctrine::loadModels("{$models}/dal"); Doctrine::loadModels($models); return Doctrine::GetTable($key); } catch (Joy_Exception_NotFound_Class $ex) { $models = $this->config->application->get("folders/model"); Doctrine::loadModels("{$models}/dal"); Doctrine::loadModels($models); return Doctrine::GetTable($key); } }
public function init() { //pull in options from config file $options = $this->getOptions(); //require doctrine core require_once 'Doctrine/lib/Doctrine.php'; //setup autoloading for doctrine core and models $loader = Zend_Loader_Autoloader::getInstance(); $loader->pushAutoLoader(array('Doctrine', 'autoload')); $loader->pushAutoLoader(array('Doctrine', 'modelsAutoLoad')); //tell doctrine to load the models but load them conservatively $manager = Doctrine_Manager::getInstance(); $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE); $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true); Doctrine::loadModels($options["modelPath"]); $manager->openConnection($options["connectionString"], 'db'); //return doctrine manager as the resource that was bootstrapped return $manager; }
public function changeDBConfig($config = 'default', $dirYml = null) { $load = $dirYml; if ($dirYml == null) { $load = realpath(dirname(__FILE__) . 'config/database.yml'); } $data = Spyc::YAMLLoad($load); $db[$config] = $data['db']['default']; $db[$config]['cachedir'] = ""; $db[$config]['dsn'] = $db[$config]['dbdriver'] . '://' . $db[$config]['username'] . ':' . $db[$config]['password'] . '@' . $db[$config]['hostname'] . '/' . $db[$config]['database']; // Set the autoloader spl_autoload_register(array('Doctrine', 'autoload')); // Load the Doctrine connection Doctrine_Manager::connection($db[$config]['dsn'], $db[$config]['database']); //Doctrine_Manager::connection()->setCharset($db[$config]['char_set']); // Load the models for the autoloader Doctrine::loadModels(APPPATH . '/models/generated'); Doctrine::loadModels(APPPATH . '/models'); }