本文整理汇总了PHP中Doctrine_Core::createTablesFromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Core::createTablesFromArray方法的具体用法?PHP Doctrine_Core::createTablesFromArray怎么用?PHP Doctrine_Core::createTablesFromArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Core
的用法示例。
在下文中一共展示了Doctrine_Core::createTablesFromArray方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
if (!$options['skip-build']) {
$buildModel = new sfDoctrineBuildModelTask($this->dispatcher, $this->formatter);
$buildModel->setCommandApplication($this->commandApplication);
$buildModel->setConfiguration($this->configuration);
$buildModel->run();
}
$connections = array();
$models = $arguments['models'];
foreach ($models as $key => $model) {
$model = trim($model);
$conn = Doctrine_Core::getTable($model)->getConnection();
$connections[$conn->getName()][] = $model;
}
foreach ($connections as $name => $models) {
$this->logSection('doctrine', 'dropping model tables for connection "' . $name . '"');
$conn = Doctrine_Manager::getInstance()->getConnection($name);
$models = $conn->unitOfWork->buildFlushTree($models);
$models = array_reverse($models);
foreach ($models as $model) {
$tableName = Doctrine_Core::getTable($model)->getOption('tableName');
$this->logSection('doctrine', 'dropping table "' . $tableName . '"');
try {
$conn->export->dropTable($tableName);
} catch (Exception $e) {
$this->logSection('doctrine', 'dropping table failed: ' . $e->getMessage());
}
}
$this->logSection('doctrine', 'recreating tables for models');
Doctrine_Core::createTablesFromArray($models);
}
}
示例2: testCachedResultsAreSpecificToDsn
public function testCachedResultsAreSpecificToDsn()
{
$cacheDriver = new Doctrine_Cache_Array();
$conn1 = Doctrine_Manager::connection('sqlite::memory:', 'conn_1');
$conn1->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, $cacheDriver);
$conn2 = Doctrine_Manager::connection('sqlite::memory:', 'conn_2');
$conn2->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, $cacheDriver);
$this->assertNotEqual($conn1, $conn2);
$manager = Doctrine_Manager::getInstance();
$manager->setCurrentConnection('conn_1');
$this->assertEqual($conn1, Doctrine_Manager::connection());
Doctrine_Core::createTablesFromArray(array('Ticket_1706_User'));
$user = new Ticket_1706_User();
$user->name = 'Allen';
$user->save();
$manager->setCurrentConnection('conn_2');
$this->assertEqual($conn2, Doctrine_Manager::connection());
Doctrine_Core::createTablesFromArray(array('Ticket_1706_User'));
$user = new Ticket_1706_User();
$user->name = 'Bob';
$user->save();
$manager->setCurrentConnection('conn_1');
$u1 = Doctrine_Query::create()->from('Ticket_1706_User u')->useResultCache()->execute();
$this->assertEqual(1, count($u1));
$this->assertEqual('Allen', $u1[0]->name);
$manager->setCurrentConnection('conn_2');
$u2 = Doctrine_Query::create()->from('Ticket_1706_User u')->useResultCache()->execute();
$this->assertEqual(1, count($u2));
$this->assertEqual('Bob', $u2[0]->name);
}
示例3: execute
/**
* @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());
}
示例4: flushDatabase
/** 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;
}
示例5: run
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);
}
}
示例6: setUp
protected function setUp()
{
$conn = Doctrine_Manager::connection('sqlite://memory', 'doctrine');
Doctrine_Manager::getInstance()->setCurrentConnection('doctrine');
try {
Doctrine_Manager::getInstance()->dropDatabases('doctrine');
} catch (Doctrine_Export_Exception $e) {
/* database did not exist so ignore.. */
}
Doctrine_Manager::getInstance()->createDatabases('doctrine');
Doctrine_Core::createTablesFromArray(array('sfGuardUser', 'UserLoginHistory'));
$sfGuardUser = new sfGuardUser();
$sfGuardUser->username = 'caefer';
$sfGuardUser->first_name = 'Christian';
$sfGuardUser->last_name = 'Schaefer';
$sfGuardUser->email_address = 'caefer@ical.ly';
$sfGuardUser->save();
}
示例7: testGeneratorComponentBinding
public function testGeneratorComponentBinding()
{
Doctrine_Manager::connection('sqlite::memory:', 'test_tmp_conn', false);
Doctrine_Manager::getInstance()->bindComponent('I18nGeneratorComponentBinding', 'test_tmp_conn');
Doctrine_Core::createTablesFromArray(array('I18nGeneratorComponentBinding'));
try {
$i = new I18nGeneratorComponentBinding();
$i->name = 'test';
$i->Translation['EN']->title = 'en test';
$i->Translation['FR']->title = 'fr test';
$i->save();
$this->pass();
$this->assertTrue($i->id > 0);
$this->assertEqual($i->Translation['EN']->title, 'en test');
$this->assertEqual($i->Translation['FR']->title, 'fr test');
$this->assertEqual($i->getTable()->getConnection()->getName(), $i->Translation->getTable()->getConnection()->getName());
} catch (Exception $e) {
$this->fail($e->getMessage());
}
}
示例8: upgrade
/**
* Upgrade the module from an old version.
*
* This function must consider all the released versions of the module!
* If the upgrade fails at some point, it returns the last upgraded version.
*
* @param string $oldVersion Version number string to upgrade from.
*
* @return boolean|string True on success, last valid version string or false if fails.
*/
public function upgrade($oldversion)
{
// Upgrade dependent on old version number
switch ($oldversion) {
case '3.6':
case '3.7':
// legacy is no longer supported
System::delVar('loadlegacy');
DBUtil::changeTable('modules');
case '3.7.4':
case '3.7.5':
case '3.7.6':
case '3.7.8':
// create the new hooks tables
Doctrine_Core::createTablesFromArray(array('Zikula_Doctrine_Model_HookArea', 'Zikula_Doctrine_Model_HookProvider', 'Zikula_Doctrine_Model_HookSubscriber', 'Zikula_Doctrine_Model_HookBinding', 'Zikula_Doctrine_Model_HookRuntime'));
EventUtil::registerPersistentModuleHandler('Extensions', 'controller.method_not_found', array('Extensions_HookUI', 'hooks'));
EventUtil::registerPersistentModuleHandler('Extensions', 'controller.method_not_found', array('Extensions_HookUI', 'moduleservices'));
case '3.7.9':
// increase length of some hook table fields from 60 to 100
$commands = array();
$commands[] = "ALTER TABLE hook_area CHANGE areaname areaname VARCHAR(100) NOT NULL";
$commands[] = "ALTER TABLE hook_runtime CHANGE eventname eventname VARCHAR(100) NOT NULL";
$commands[] = "ALTER TABLE hook_subscriber CHANGE eventname eventname VARCHAR(100) NOT NULL";
// Load DB connection
$dbEvent = new Zikula_Event('doctrine.init_connection');
$connection = $this->eventManager->notify($dbEvent)->getData();
foreach ($commands as $sql) {
$stmt = $connection->prepare($sql);
$stmt->execute();
}
case '3.7.10':
// future upgrade routines
}
// Update successful
return true;
}
示例9: array
// Signal that upgrade is running.
$GLOBALS['_ZikulaUpgrader'] = array();
// include config file for retrieving name of temporary directory
$GLOBALS['ZConfig']['System']['multilingual'] = true;
$GLOBALS['ZConfig']['System']['Z_CONFIG_USE_OBJECT_ATTRIBUTION'] = false;
$GLOBALS['ZConfig']['System']['Z_CONFIG_USE_OBJECT_LOGGING'] = false;
$GLOBALS['ZConfig']['System']['Z_CONFIG_USE_OBJECT_META'] = false;
// Lazy load DB connection to avoid testing DSNs that are not yet valid (e.g. no DB created yet)
$dbEvent = new Zikula_Event('doctrine.init_connection', null, array('lazy' => true));
$connection = $eventManager->notify($dbEvent)->getData();
$columns = upgrade_getColumnsForTable($connection, 'modules');
if (in_array('pn_id', array_keys($columns))) {
upgrade_columns($connection);
}
if (!isset($columns['capabilities'])) {
Doctrine_Core::createTablesFromArray(array('Zikula_Doctrine_Model_HookArea', 'Zikula_Doctrine_Model_HookProvider', 'Zikula_Doctrine_Model_HookSubscriber', 'Zikula_Doctrine_Model_HookBinding', 'Zikula_Doctrine_Model_HookRuntime'));
ModUtil::dbInfoLoad('Extensions', 'Extensions', true);
DBUtil::changeTable('modules');
ModUtil::dbInfoLoad('Blocks', 'Blocks', true);
DBUtil::changeTable('blocks');
}
$installedVersion = upgrade_getCurrentInstalledCoreVersion($connection);
if (version_compare($installedVersion, '1.3.0-dev') === -1) {
$GLOBALS['_ZikulaUpgrader']['_ZikulaUpgradeFrom12x'] = true;
}
$core->init(Zikula_Core::STAGE_ALL);
$action = FormUtil::getPassedValue('action', false, 'GETPOST');
// login to supplied admin credentials for action the following actions
if ($action === 'upgrademodules' || $action === 'convertdb' || $action === 'sanitycheck') {
$username = FormUtil::getPassedValue('username', null, 'POST');
$password = FormUtil::getPassedValue('password', null, 'POST');
示例10: setTableDefinition
{
public function setTableDefinition()
{
$this->hasColumn('title', 'string', 255);
$this->hasColumn('content', 'string', null);
}
public function setUp()
{
parent::setUp();
$search = new rtSearchTemplate(array('fields' => array('title', 'content')));
$this->actAs($search);
}
}
Doctrine_Core::dropDatabases();
Doctrine_Core::createDatabases();
Doctrine_Core::createTablesFromArray(array('Tester', 'rtIndex'));
$tester = new Tester();
$tester['title'] = 'Hello, this is a test object, a balloon is great!';
$tester['content'] = 'Balloons really are great. Infact, ninety-nine of them make a wonderful song.';
$tester->save();
$table = Doctrine::getTable('rtIndex');
$t->is($table->getSearchResultsAsArray('19283hd'), false, '->getSearchResultsAsArray() returns false for a search on something which isn\'t in the index.');
$r = $table->getSearchResultsAsArray('balloon');
$t->is(is_array($r), true, '->getSearchResultsAsArray() returns an array for a valid search.');
$t->is(count($r), 1, '->getSearchResultsAsArray() returns correct no. of rows.');
$row_comparison = array('id' => '4', 'model' => 'Tester', 'model_id' => '1', 'lang' => 'en', 'relevance' => '2');
$t->is($r[0], $row_comparison, '->getSearchResultsAsArray() rows are the correct structure.');
$tester2 = new Tester();
$tester2['title'] = 'Colours';
$tester2['content'] = 'Red, green, blue and yellow are just a few of the colours.';
$tester2->save();
示例11: gentablesAction
public function gentablesAction()
{
Doctrine_Core::createTablesFromArray(array('Model_Resource'));
$this->render('friend');
}
示例12: rtSearchTemplate
parent::setUp();
$search = new rtSearchTemplate(array('fields' => array('title', 'content')));
$i18n = new Doctrine_Template_I18N(array('fields' => array('title', 'content')));
$i18n->addChild($search);
$this->actAs(new rtSearchTemplate());
$this->actAs($i18n);
}
public function delete(Doctrine_Connection $conn = null)
{
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true);
sfContext::createInstance($configuration)->getLogger()->err('{I18NTester} delete() called!');
parent::delete($conn);
}
}
$t->diag('Test a more complex I18N object.');
Doctrine_Core::createTablesFromArray(array('I18NTester'));
$i18n_tester = new I18NTester();
$title = 'Hello, balloons are green blue and sometime red!';
$content = 'It really doesn\'t do too much. Just a little bit of text to hold and save for testing.';
$i18n_tester->Translation['en']->title = $title;
$i18n_tester->Translation['en']->content = $content;
$t->is($i18n_tester->Translation['en']->getSearchBlob(), $title . ' ' . $content, '->getSearchBlob() returns a combined string');
$t->is($i18n_tester->Translation['en']->getLang(), 'en', '->getLang() returns the correct value for en Translation');
$title = 'Bon jour, ca va?';
$content = "Les mots vides (ou stop words, en anglais) sont des mots qui sont tellement communs qu'il est inutile de les indexer ou de les utiliser dans une recherche.";
$i18n_tester->Translation['fr']->title = $title;
$i18n_tester->Translation['fr']->content = $content;
$t->is($i18n_tester->Translation['fr']->getSearchBlob(), $title . ' ' . $content, '->getSearchBlob() returns a combined string');
$t->is($i18n_tester->Translation['fr']->getLang(), 'fr', '->getLang() returns the correct value for fr Translation');
$i18n_tester->save();
$i18n_tester_id = $i18n_tester->Translation['fr']->id;