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; }
public function testTest() { $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1'); $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1'); $this->assertEqual($models1, $models2); $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models1', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2'); $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2'); $this->assertEqual($models1, $models2); $models1 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $models2 = Doctrine_Core::loadModels(dirname(__FILE__) . '/1727/models2', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); $models1 = Doctrine_Core::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2')); $models2 = Doctrine_Core::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2')); $this->assertEqual($models1, $models2); $models1 = Doctrine_Core::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2'), Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $models2 = Doctrine_Core::loadModels(array(dirname(__FILE__) . '/1727/models1', dirname(__FILE__) . '/1727/models2'), Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $this->assertEqual($models1, $models2); }
/** * Loads all model classes and returns an array of model names. * * @return array An array of model names */ protected function loadModels() { Doctrine_Core::loadModels($this->configuration->getModelDirs()); $models = Doctrine_Core::getLoadedModels(); $models = Doctrine_Core::initializeModels($models); $models = Doctrine_Core::filterInvalidModels($models); return $models; }
/** * Constructor * * Initialize things. * */ function __construct() { if (null == self::$_appInstance) { self::$_appInstance = Slim::getInstance(); } Doctrine_Core::loadModels(MODELS_PATH); DoctrineAdapter::getInstance(); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $this->logSection('doctrine', 'created tables successfully'); $databaseManager = new sfDatabaseManager($this->configuration); $config = $this->getCliConfig(); Doctrine_Core::loadModels($config['models_path'], Doctrine_Core::MODEL_LOADING_CONSERVATIVE); Doctrine_Core::createTablesFromArray(Doctrine_Core::getLoadedModels()); }
public function testConservativeModelLoading() { $path = realpath('ModelLoadingTest/Conservative'); $models = Doctrine_Core::loadModels($path, Doctrine_Core::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_Core::loadModels($this->getArgument('models_path')); $dql = $this->getArgument('dql_query'); $query = Doctrine_Query::create(); $params = $this->getArgument('params'); $params = $params ? explode(',', $params) : array(); $this->notify('executing: "' . $dql . '" (' . implode(', ', $params) . ')'); $results = $query->query($dql, $params, Doctrine_Core::HYDRATE_ARRAY); $this->_printResults($results); }
/** * @param array|string $directories * @return array */ public static function loadModels($directories, $modelLoading = null, $classPrefix = null) { $manager = Doctrine_Manager::getInstance(); $modelLoading = $modelLoading != null ? $manager->getAttribute(Doctrine_Core::ATTR_MODEL_LOADING) : $modelLoading; $zendStyles = array(self::MODEL_LOADING_ZEND, self::MODEL_LOADING_ZEND_SINGLE_LIBRARY, self::MODEL_LOADING_ZEND_MODULE_LIBRARY); if (in_array($modelLoading, $zendStyles)) { return self::loadAllZendModels(); } else { return parent::loadModels($directories, $modelLoading, $classPrefix); } }
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_Core::loadModels($doctrineConfig['models_path']); $conn = Doctrine_Manager::connection($doctrineConfig['dsn'], 'doctrine'); $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true); return $conn; }
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(); }
public function _initDoctrine() { require_once 'Doctrine.php'; $loader = Zend_Loader_Autoloader::getInstance(); $loader->pushAutoloader(array('Doctrine', 'autoload')); $doctrineConfig = $this->getOption('doctrine'); $manager = Doctrine_Manager::getInstance(); $manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true); $manager->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true); $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true); Doctrine_Core::loadModels($doctrineConfig['models_path'] . '/generated'); Doctrine_Core::loadModels($doctrineConfig['models_path']); $conn = Doctrine_Manager::connection($doctrineConfig['connection_string'], 'doctrine'); return $manager; }
public function testTest() { $models1Dir = dirname(__FILE__) . '/2375/models1'; $models2Dir = dirname(__FILE__) . '/2375/models2'; // try loading a couple initial models $models1 = Doctrine_Core::loadModels($models1Dir); //$models2 = Doctrine_Core::loadModels($models2Dir); // make sure two models were loaded $this->assertEqual(2, count($models1)); // make sure the right models were loaded $this->assertTrue(key_exists('Ticket_2375_Model1', $models1)); $this->assertTrue(key_exists('Ticket_2375_Model2', $models1)); // get a list of all models that have been loaded $loadedModels = Doctrine_Core::getLoadedModelFiles(); // make sure the paths are correct $this->assertEqual($loadedModels['Ticket_2375_Model1'], $models1Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model1.php'); $this->assertEqual($loadedModels['Ticket_2375_Model2'], $models1Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model2.php'); // try loading a few more models $models2 = Doctrine_Core::loadModels($models2Dir); // make sure the right models were loaded $this->assertTrue(key_exists('Ticket_2375_Model3', $models2)); $this->assertTrue(key_exists('Ticket_2375_Model4', $models2)); $this->assertTrue(key_exists('Ticket_2375_Model5', $models2)); $this->assertTrue(key_exists('Ticket_2375_Model6', $models2)); // get a list of all models that have been loaded $loadedModels = Doctrine_Core::getLoadedModelFiles(); // make sure the paths are correct $this->assertEqual($loadedModels['Ticket_2375_Model1'], $models1Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model1.php'); $this->assertEqual($loadedModels['Ticket_2375_Model2'], $models1Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model2.php'); $this->assertEqual($loadedModels['Ticket_2375_Model3'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model3.php'); $this->assertEqual($loadedModels['Ticket_2375_Model4'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model4.php'); $this->assertEqual($loadedModels['Ticket_2375_Model5'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model5.php'); $this->assertEqual($loadedModels['Ticket_2375_Model6'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model5.php'); // try loading the first models again $models1 = Doctrine_Core::loadModels($models1Dir); // make sure the right models were loaded $this->assertTrue(key_exists('Ticket_2375_Model1', $models1)); $this->assertTrue(key_exists('Ticket_2375_Model2', $models1)); // get a list of all models that have been loaded $loadedModels = Doctrine_Core::getLoadedModelFiles(); // make sure the paths are correct $this->assertEqual($loadedModels['Ticket_2375_Model1'], $models1Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model1.php'); $this->assertEqual($loadedModels['Ticket_2375_Model2'], $models1Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model2.php'); $this->assertEqual($loadedModels['Ticket_2375_Model3'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model3.php'); $this->assertEqual($loadedModels['Ticket_2375_Model4'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model4.php'); $this->assertEqual($loadedModels['Ticket_2375_Model5'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model5.php'); $this->assertEqual($loadedModels['Ticket_2375_Model6'], $models2Dir . DIRECTORY_SEPARATOR . 'Ticket_2375_Model5.php'); }
protected function _initDoctrine() { $this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine', 'autoload')); spl_autoload_register(array('Doctrine', 'modelsAutoload')); // with the help of it generate sql and write in it. $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']); $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true); Doctrine_Core::loadModels($doctrineConfig['models_path']); // this loads all model classes. $conn = Doctrine_Manager::connection($doctrineConfig['dsn'], 'doctrine'); $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true); return $conn; }
/** * Aggressively load models. * * This helper is required because we are using PEAR naming standards with * our own autoloading. Doctrine's model loading doesn't take this into * account in non agressive modes. * * In general, this method is NOT required. * * @param string $modname Module name to load models for. * * @return void */ public static function loadModels($modname) { $modname = isset($modname) ? strtolower((string) $modname) : ''; $modinfo = ModUtil::getInfoFromName($modname); $osdir = DataUtil::formatForOS($modinfo['directory']); $base = $modinfo['type'] == ModUtil::TYPE_MODULE ? 'modules' : 'system'; $dm = Doctrine_Manager::getInstance(); $save = $dm->getAttribute(Doctrine_Core::ATTR_MODEL_LOADING); $dm->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_AGGRESSIVE); $path = "{$base}/{$osdir}/lib/{$osdir}/Model"; // prevent exception when model folder does not exist if (file_exists($path)) { Doctrine_Core::loadModels(realpath($path)); } $dm->setAttribute(Doctrine::ATTR_MODEL_LOADING, $save); }
/** Flush the database and reload base fixtures. * * @param bool $rebuild * true: The database will be dropped and rebuilt. * false: The method will try just to flush the data. * * Note that the first time flushDatabase() is called (per execution), the * database will be rebuilt regardless of $rebuild. * * @return static */ public function flushDatabase($rebuild = false) { if ($this->_connection) { /* The first time we run a test case, drop and rebuild the database. * * After that, we can simply truncate all tables for speed. */ if (empty(self::$_dbRebuilt) or $rebuild) { /* Don't try to drop the database unless it exists. */ $name = $this->getDatabaseName(); /** @noinspection PhpUndefinedFieldInspection */ if ($name and $this->_connection->import->databaseExists($name)) { $this->_connection->dropDatabase(); } $this->_connection->createDatabase(); Doctrine_Core::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine', Doctrine_Core::MODEL_LOADING_CONSERVATIVE); Doctrine_Core::createTablesFromArray(Doctrine_Core::getLoadedModels()); self::$_dbRebuilt = true; } else { /* Determine the order we need to load models. */ if (!isset(self::$_dbFlushTree)) { /** @noinspection PhpUndefinedFieldInspection */ $models = $this->_connection->unitOfWork->buildFlushTree(Doctrine_Core::getLoadedModels()); self::$_dbFlushTree = array_reverse($models); } $this->_doPreFlush(); /* Delete records, paying special attention to SoftDelete. */ foreach (self::$_dbFlushTree as $model) { $table = Doctrine_Core::getTable($model); if ($table->hasTemplate('SoftDelete')) { /** @var $record Doctrine_Template_SoftDelete */ foreach ($table->createQuery()->execute() as $record) { $record->hardDelete(); } } $table->createQuery()->delete()->execute(); $table->clear(); } $this->_doPostFlush(); /** Clear all Doctrine table repositories to prevent memory leaks * between tests. */ $this->_connection->clear(); } } return $this; }
public function execute() { $models = Doctrine_Core::loadModels($this->getArgument('models_path')); if (empty($models)) { throw new Doctrine_Task_Exception('No models were loaded'); } $path = $this->getArgument('data_fixtures_path'); if (is_array($path) && count($path) > 0) { $path = $path[0]; } if (!empty($path)) { Doctrine_Core::dumpData($path); $this->notify(sprintf('Dumped data successfully to: %s', $path)); } else { throw new Doctrine_Task_Exception('Unable to find data fixtures path.'); } }
public function run() { $this->getDatabaseManager(); // build all tables for models if (!$this->getOption('models')) { sfOpenPNEApplicationConfiguration::unregisterZend(); $path = sfConfig::get('sf_lib_dir') . '/model/doctrine'; Doctrine_Core::loadModels($path, Doctrine_Core::MODEL_LOADING_CONSERVATIVE); Doctrine_Core::createTablesFromArray(Doctrine_Core::getLoadedModels()); sfOpenPNEApplicationConfiguration::registerZend(); return true; } foreach ($this->getQueries() as $query) { $db = $this->getDatabaseManager()->getDatabase('doctrine'); $db->getDoctrineConnection()->execute($query); } }
public function setup() { parent::setup(); $plugins = $this->getSympalContext()->getSympalConfiguration()->getContentTypePlugins(); $plugins = array_combine($plugins, $plugins); $plugins = array_merge(array('' => ''), $plugins); $this->widgetSchema['plugin_name'] = new sfWidgetFormChoice(array('choices' => $plugins)); $this->widgetSchema['plugin_name']->setLabel('Plugin'); $this->widgetSchema['name']->setLabel('Model name'); $models = Doctrine_Core::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine'); foreach ($models as $model) { $table = Doctrine_Core::getTable($model); if (!$table->hasTemplate('sfSympalContentTypeTemplate')) { unset($models[$model]); } } $models = array_merge(array('' => ''), $models); $this->widgetSchema['name'] = new sfWidgetFormChoice(array('choices' => $models)); }
protected function _initDoctrine() { $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace(array('Doctrine', 'sfYaml'))->pushAutoloader(array('Doctrine', 'autoload'), array('Doctrine', 'sfYaml')); $doctrineConfig = $this->getOption('doctrine'); $manager = Doctrine_Manager::getInstance(); $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true); $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_AGGRESSIVE); $manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true); $manager->setAttribute(Doctrine_Core::ATTR_EXPORT, Doctrine_Core::EXPORT_ALL); $manager->setCharset('utf8'); $manager->setCollate('utf8_unicode_ci'); if (function_exists('apc_add')) { $cacheDriver = new Doctrine_Cache_Apc(); $manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver); } $manager->openConnection($doctrineConfig['connection_string']); Doctrine_Core::loadModels($doctrineConfig['models_path']); return $manager; }
public function setup() { parent::setup(); $field = sfApplicationConfiguration::getActive()->getPluginConfiguration('sfThemePlugin')->getThemeToolkit()->getThemeWidgetAndValidator(); $this->widgetSchema['theme'] = $field['widget']; $this->validatorSchema['theme'] = $field['validator']; $this->widgetSchema['name']->setLabel('Model name'); $models = Doctrine_Core::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine'); // Sets up the template widget sfSympalFormToolkit::changeTemplateWidget($this); // Sets up the module widget sfSympalFormToolkit::changeModuleWidget($this); foreach ($models as $model) { $table = Doctrine_Core::getTable($model); if (!$table->hasTemplate('sfSympalContentTypeTemplate')) { unset($models[$model]); } } $models = array_merge(array('' => ''), $models); $this->widgetSchema['name'] = new sfWidgetFormChoice(array('choices' => $models)); }
public function register(Application $app) { $app['doctrine.database'] = $app->share(function ($app) { require_once $app['doctrine.options']['doctrine_path']; spl_autoload_register(array('Doctrine', 'autoload')); $app['doctrine.manager'] = \Doctrine_Manager::getInstance(); // configuration $dsn = $app['doctrine.options']['dsn']; $username = $app['doctrine.options']['username']; $password = $app['doctrine.options']['password']; // connexion $dbh = new \PDO($dsn, $username, $password); $app['doctrine.connexion'] = \Doctrine_Manager::connection($dbh, 'doctrine'); // retain username and password for Doctrine $app['doctrine.connexion']->setOption('username', $username); $app['doctrine.connexion']->setOption('password', $password); // charset $app['doctrine.connexion']->setCharset($app['doctrine.options']['charset']); // add quotes $app['doctrine.connexion']->setAttribute(\Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true); if (!empty($app['doctrine.options']['prefix'])) { $app['doctrine.manager']->setAttribute(\Doctrine_Core::ATTR_TBLNAME_FORMAT, $app['doctrine.options']['prefix'] . '_%s'); } $app['doctrine.manager']->setAttribute(\Doctrine_Core::ATTR_EXPORT, \Doctrine_Core::EXPORT_ALL); $app['doctrine.manager']->setAttribute(\Doctrine_Core::ATTR_MODEL_LOADING, \Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $app['doctrine.manager']->setAttribute(\Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true); // enable overide accessor methods $app['doctrine.manager']->setAttribute(\Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true); $app['doctrine.manager']->setAttribute(\Doctrine_Core::ATTR_VALIDATE, \Doctrine_Core::VALIDATE_NONE); // model loading \Doctrine_Core::loadModels($app['doctrine.options']['model_dir']); spl_autoload_register(array('Doctrine_Core', 'modelsAutoload')); // triggers the connection to be created (instantiate connection) $app['doctrine.connexion']->execute('SHOW TABLES'); return $app['doctrine.connexion']; }); $app['doctrine'] = $app->share(function ($app) { return $app['doctrine.database']; }); }
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_Core::loadModels($path, Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $sql = $this->conn->export->exportSortedClassesSql(array('WikiTest')); $sql = current($sql); $result = array(0 => 'CREATE TABLE wiki_test_translation_version (id INTEGER, lang CHAR(2), title VARCHAR(255), content TEXT, version INTEGER, PRIMARY KEY(id, lang, version))', 1 => 'CREATE TABLE wiki_test_translation_index (keyword VARCHAR(200), field VARCHAR(50), position INTEGER, id INTEGER, lang CHAR(2), PRIMARY KEY(keyword, field, position, id, lang))', 2 => 'CREATE TABLE wiki_test_translation (id INTEGER, title VARCHAR(255), content TEXT, lang CHAR(2), version INTEGER, slug VARCHAR(255), PRIMARY KEY(id, lang))', 3 => 'CREATE TABLE wiki_test (id INTEGER PRIMARY KEY AUTOINCREMENT)', 4 => 'CREATE UNIQUE 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'); }
/** * exportSql * returns the sql for exporting Doctrine_Record classes to a schema * * if the directory parameter is given this method first iterates * recursively trhough the given directory in order to find any model classes * * Then it iterates through all declared classes and creates tables for the ones * that extend Doctrine_Record and are not abstract classes * * @throws Doctrine_Connection_Exception if some error other than Doctrine_Core::ERR_ALREADY_EXISTS * occurred during the create table operation * @param string $directory optional directory parameter * @return void */ public function exportSql($directory = null) { if ($directory !== null) { $models = Doctrine_Core::filterInvalidModels(Doctrine_Core::loadModels($directory)); } else { $models = Doctrine_Core::getLoadedModels(); } return $this->exportSortedClassesSql($models, false); }
<?php /** * Bootstrap Doctrine.php, register autoloader specify * configuration attributes and load models. */ require_once dirname(__FILE__) . '/lib/vendor/doctrine/Doctrine.php'; spl_autoload_register(array('Doctrine', 'autoload')); Doctrine_Core::loadModels(dirname(__FILE__) . '/models'); $manager = Doctrine_Manager::getInstance(); $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true); $manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true); $manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE); spl_autoload_register(array('Doctrine_Core', 'modelsAutoload')); $logins = parse_ini_file("settings/bootstrap.ini"); if ($logins === false || !$logins['login'] || !$logins['password']) { $dsn = 'sqlite:///' . dirname(__FILE__) . '/db/wpt_monitor.sqlite'; } else { $dsn = 'mysql://' . $logins['login'] . ':' . $logins['password'] . '@' . $logins['dbhost'] . '/' . $logins['dbname']; } $dataConn = Doctrine_Manager::connection($dsn, 'data'); // // $configDsn= 'sqlite:///'.dirname(__FILE__).'/db/config.sqlite'; // $configConn = Doctrine_Manager::connection($configDsn, 'config');
/** * Generate a diff between the from and to schema information * * @param string $from Path to set of models to migrate from * @param string $to Path to set of models to migrate to * @return array $changes */ protected function _diff($from, $to) { // Load the from and to models $fromModels = Doctrine_Core::initializeModels(Doctrine_Core::loadModels($from)); $toModels = Doctrine_Core::initializeModels(Doctrine_Core::loadModels($to)); // Build schema information for the models $fromInfo = $this->_buildModelInformation($fromModels); $toInfo = $this->_buildModelInformation($toModels); // Build array of changes between the from and to information $changes = $this->_buildChanges($fromInfo, $toInfo); $this->_cleanup(); return $changes; }
/** * Loads all Doctrine builders. */ protected function loadModels() { Doctrine_Core::loadModels($this->generatorManager->getConfiguration()->getModelDirs()); $models = Doctrine_Core::getLoadedModels(); $models = Doctrine_Core::initializeModels($models); $models = Doctrine_Core::filterInvalidModels($models); $this->models = $this->filterModels($models); return $this->models; }
<?php require('plugins/doctrine/lib/Doctrine.php'); spl_autoload_register(array('Doctrine', 'autoload')); spl_autoload_register(array('Doctrine_Core', 'modelsAutoload')); $manager = Doctrine_Manager::getInstance(); $manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE); $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true); Doctrine_Core::loadModels(__DIR__.'/orm/models'); $conn = Doctrine_Manager::connection($config["db"]["dsn"]); ?>
<?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require_once 'config.php'; $models = Doctrine_Core::loadModels('models'); $idHouses = isset($_POST['id']) && $_POST['id'] > 0 ? $_POST['id'] : null; if (isset($_POST['name']) && isset($_POST['city']) && isset($_POST['zipCode']) && isset($_POST['street'])) { $houseTable = Doctrine_Core::getTable('House'); if ($idHouses === null) { $house = new House(); } else { $house = $houseTable->find($idHouses); } //$house->merge($_REQUEST['user']); $house->name = $_POST['name']; $house->city = $_POST['city']; $house->zipCode = $_POST['zipCode']; $house->street = $_POST['street']; $house->tel = $_POST['tel']; $house->email = $_POST['email']; $house->www = $_POST['www']; $house->target = $_POST['target']; $house->save(); // //echo($house->idhouses); header('location: contacts/contacts.html'); }
/** * Generate a set of migrations from a set of models * * @param string $modelsPath Path to models * @param string $modelLoading What type of model loading to use when loading the models * @return boolean */ public function generateMigrationsFromModels($modelsPath = null, $modelLoading = null) { if ($modelsPath !== null) { $models = Doctrine_Core::filterInvalidModels(Doctrine_Core::loadModels($modelsPath, $modelLoading)); } else { $models = Doctrine_Core::getLoadedModels(); } $models = Doctrine_Core::initializeModels($models); $foreignKeys = array(); foreach ($models as $model) { $table = Doctrine_Core::getTable($model); if ($table->getTableName() !== $this->migration->getTableName()) { $export = $table->getExportableFormat(); $foreignKeys[$export['tableName']] = $export['options']['foreignKeys']; $up = $this->buildCreateTable($export); $down = $this->buildDropTable($export); $className = 'Add' . Doctrine_Inflector::classify($export['tableName']); $this->generateMigrationClass($className, array(), $up, $down); } } if (!empty($foreignKeys)) { $className = 'AddFks'; $up = array(); $down = array(); foreach ($foreignKeys as $tableName => $definitions) { $tableForeignKeyNames[$tableName] = array(); foreach ($definitions as $definition) { $up[] = $this->buildCreateForeignKey($tableName, $definition); $down[] = $this->buildDropForeignKey($tableName, $definition); } } $up = implode("\n", $up); $down = implode("\n", $down); if ($up || $down) { $this->generateMigrationClass($className, array(), $up, $down); } } return true; }
public function execute() { Doctrine_Core::loadModels($this->getArgument('models_path')); Doctrine_Core::loadData($this->getArgument('data_fixtures_path'), $this->getArgument('append', false)); $this->notify('Data was successfully loaded'); }