本文整理汇总了PHP中Doctrine_Migration类的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Migration类的具体用法?PHP Doctrine_Migration怎么用?PHP Doctrine_Migration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Doctrine_Migration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
try {
$migrationsPath = $this->getArgument('migrations_path');
$yamlSchemaPath = $this->getArgument('yaml_schema_path');
$migration = new Doctrine_Migration($migrationsPath);
$result1 = false;
if (!count($migration->getMigrationClasses())) {
$result1 = Doctrine_Core::generateMigrationsFromDb($migrationsPath);
}
$connections = array();
foreach (Doctrine_Manager::getInstance() as $connection) {
$connections[] = $connection->getName();
}
$changes = Doctrine_Core::generateMigrationsFromDiff($migrationsPath, $connections, $yamlSchemaPath);
$numChanges = count($changes, true) - count($changes);
$result = $result1 || $numChanges ? true : false;
} catch (Exception $e) {
$result = false;
}
if (!$result) {
throw new Doctrine_Task_Exception('Could not generate migration classes from database');
} else {
$this->notify('Generated migration classes successfully from database');
}
}
示例2: execute
public function execute()
{
try {
$migrationsPath = $this->getArgument('migrations_path');
$modelsPath = $this->getArgument('models_path');
$yamlSchemaPath = $this->getArgument('yaml_schema_path');
$migration = new Doctrine_Migration($migrationsPath);
$result1 = false;
if (!count($migration->getMigrationClasses())) {
$builder = new Doctrine_Migration_Builder($migration);
$result1 = $builder->generateMigrationsFromModels($modelsPath);
}
$diff = new Doctrine_Migration_Diff($modelsPath, $yamlSchemaPath, $migration);
$changes = $diff->generateMigrationClasses();
$numChanges = count($changes, true) - count($changes);
$result = $result1 || $numChanges ? true : false;
} catch (Exception $e) {
$result = false;
}
if (!$result) {
throw new Doctrine_Task_Exception('Could not generate migration classes from models' . (isset($e) ? ': ' . $e->getMessage() : null));
} else {
$this->notify('Generated migration classes successfully from models');
}
}
示例3: migrate_db
function migrate_db()
{
try {
$path = makeMigrationsDir();
$migration = new Doctrine_Migration($path);
$migration->migrate();
$account = db_get_account('alice');
if (!$account) {
$account = array('login' => 'alice', 'crypted_password' => 'b6263bb14858294c08e4bdfceba90363e10d72b4', 'name' => 'Alice Yamada', 'name_ja_kana_jp' => 'ヤマダアリサ', 'name_ja_hani_jp' => '山田亜理紗', 'given_name' => 'Alice', 'given_name_ja_kana_jp' => 'アリサ', 'given_name_ja_hani_jp' => '亜理紗', 'family_name' => 'Yamada', 'family_name_ja_kana_jp' => 'ヤマダ', 'family_name_ja_hani_jp' => '山田', 'nickname' => 'Alice Nickname', 'preferred_username' => 'AlicePreferred', 'profile' => 'http://www.wonderland.com/alice', 'picture' => 'smiling_woman.jpg', 'website' => 'http://www.wonderland.com', 'email' => 'alice@wonderland.com', 'email_verified' => 1, 'gender' => 'Female', 'birthdate' => '2000-01-01', 'zoneinfo' => 'america/Los Angeles', 'locale' => 'en', 'phone_number' => '123-456-7890', 'phone_number_verified' => 1, 'address' => '123 Wonderland Way', 'updated_at' => time());
db_save_account('alice', $account);
}
$account = db_get_account('bob');
if (!$account) {
$account = array('login' => 'bob', 'crypted_password' => 'cc8684eed2b6544e89242558df73a7208c9391b4', 'name' => 'Bob Ikeda', 'name_ja_kana_jp' => 'イケダボブ', 'name_ja_hani_jp' => '池田保夫', 'given_name' => 'Bob', 'given_name_ja_kana_jp' => 'ボブ', 'given_name_ja_hani_jp' => '保夫', 'family_name' => 'Ikeda', 'family_name_ja_kana_jp' => 'イケダ', 'family_name_ja_hani_jp' => '池田', 'nickname' => 'Bob Nickname', 'preferred_username' => 'BobPreferred', 'profile' => 'http://www.underland.com/bob', 'picture' => 'smiling_man.jpg', 'website' => 'http://www.underland.com', 'email' => 'bob@underland.com', 'email_verified' => 1, 'gender' => 'Male', 'birthdate' => '1980-02-09', 'zoneinfo' => 'France/Paris', 'locale' => 'fr', 'phone_number' => '987-234-1234', 'phone_number_verified' => 1, 'address' => '456 Underland Ct.', 'updated_at' => time());
db_save_account('bob', $account);
}
} catch (Doctrine_Migration_Exception $e) {
if (strstr($e->getMessage(), "Already at version") === false) {
throw $e;
}
} catch (Doctrine_Connection_Exception $e) {
printf("migration exception %s\n", $e);
die(2);
}
}
示例4: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$config = $this->getCliConfig();
$migration = new Doctrine_Migration($config['migrations_path']);
$intValidator = new sfValidatorInteger();
$migration->setCurrentVersion($arguments['version']);
$this->logSection('doctrine', 'Migration version set to ' . $arguments['version']);
}
示例5: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$config = $this->getCliConfig();
$migration = new Doctrine_Migration($config['migrations_path']);
$from = $migration->getCurrentVersion();
if (is_numeric($arguments['version'])) {
$version = $arguments['version'];
} else {
if ($options['up']) {
$version = $from + 1;
} else {
if ($options['down']) {
$version = $from - 1;
} else {
$version = $migration->getLatestVersion();
}
}
}
if ($from == $version) {
$this->logSection('doctrine', sprintf('Already at migration version %s', $version));
return;
}
$this->logSection('doctrine', sprintf('Migrating from version %s to %s%s', $from, $version, $options['dry-run'] ? ' (dry run)' : ''));
try {
$migration_classes = $migration->getMigrationClasses();
if ($version < $from) {
for ($i = (int) $from - 1; $i >= (int) $version; $i--) {
$this->logSection('doctrine', 'executing migration : ' . $i . ', class: ' . $migration_classes[$i]);
$migration->migrate($i, $options['dry-run']);
}
} else {
for ($i = (int) $from + 1; $i <= (int) $version; $i++) {
$this->logSection('doctrine', 'executing migration : ' . $i . ', class: ' . $migration_classes[$i]);
$migration->migrate($i, $options['dry-run']);
}
}
} catch (Exception $e) {
}
// render errors
if ($migration->hasErrors()) {
if ($this->commandApplication && $this->commandApplication->withTrace()) {
$this->logSection('doctrine', 'The following errors occurred:');
foreach ($migration->getErrors() as $error) {
$this->commandApplication->renderException($error);
}
} else {
$this->logBlock(array_merge(array('The following errors occurred:', ''), array_map(create_function('$e', 'return \' - \'.$e->getMessage();'), $migration->getErrors())), 'ERROR_LARGE');
}
return 1;
}
$this->logSection('doctrine', 'Migration complete');
}
示例6: execute
protected function execute($arguments = array(), $options = array())
{
// initialize the database connection
$databaseManager = new sfDatabaseManager($this->configuration);
$connection = $databaseManager->getDatabase($options['connection'])->getConnection();
$config = $this->getCliConfig();
$migration = new Doctrine_Migration($config['migrations_path']);
$from = $migration->getCurrentVersion();
$new_version = $arguments['new_version'];
if ($new_version !== $from) {
$migration->setCurrentVersion($new_version);
}
$this->log('Current migration version is ' . $new_version);
}
示例7: generateMigrationClass
/**
* Generate a migration class
*
* @param string $className Class name to generate
* @param array $options Options for the migration class
* @param string $up The code for the up function
* @param string $down The code for the down function
* @param boolean $return Whether or not to return the code.
* If true return and false it writes the class to disk.
* @return mixed
*/
public function generateMigrationClass($className, $options = array(), $up = null, $down = null, $return = false)
{
$className = Doctrine_Inflector::urlize($className);
$className = str_replace('-', '_', $className);
$className = Doctrine_Inflector::classify($className);
if ($return || !$this->getMigrationsPath()) {
return $this->buildMigrationClass($className, null, $options, $up, $down);
} else {
if (!$this->getMigrationsPath()) {
throw new Doctrine_Migration_Exception('You must specify the path to your migrations.');
}
$next = time() + $this->migration->getNextMigrationClassVersion();
$fileName = $next . '_' . Doctrine_Inflector::tableize($className) . $this->suffix;
$class = $this->buildMigrationClass($className, $fileName, $options, $up, $down);
$path = $this->getMigrationsPath() . DIRECTORY_SEPARATOR . $fileName;
if (class_exists($className) || file_exists($path)) {
$this->migration->loadMigrationClass($className);
return false;
}
file_put_contents($path, $class);
require_once $path;
$this->migration->loadMigrationClass($className);
return true;
}
}
示例8: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$migration = new Doctrine_Migration();
$currentVersion = $migration->getCurrentVersion();
if (!isset($arguments['version'])) {
$this->logSection('doctrine', 'Current migration version is ' . $currentVersion);
} else {
$version = $arguments['version'];
if (!is_numeric($version)) {
$this->logSection('doctrine', 'Unknown version ' . $version, null, 'ERROR');
return;
}
$migration->setCurrentVersion($version);
$this->logSection('doctrine', 'Current migration version was forced to ' . $version);
}
}
示例9: executeIndex
/**
* Executes index action
*
* @param sfRequest $request A request object
*/
public function executeIndex(sfWebRequest $request)
{
$migration = new Doctrine_Migration(sfConfig::get('sf_lib_dir') . '/migration/doctrine');
if ($migration->getCurrentVersion() < $migration->getLatestVersion()) {
try {
$migration->migrate($migration->getLatestVersion());
} catch (Exception $e) {
}
$this->errors = array_merge(array_map(create_function('$e', 'return \' - \'.$e->getMessage();'), $migration->getErrors()));
}
}
示例10: testMigration
public function testMigration()
{
// New migration for the 'migration_classes' directory
$migration = new Doctrine_Migration('migration_classes');
// Make sure the current version is 0
$this->assertEqual($migration->getCurrentVersion(), 0);
// migrate to version latest version
$migration->migrate($migration->getLatestVersion());
// Make sure the current version is latest version
$this->assertEqual($migration->getCurrentVersion(), $migration->getLatestVersion());
// now migrate back to original version
$migration->migrate(0);
// Make sure the current version is 0
$this->assertEqual($migration->getCurrentVersion(), 0);
}
示例11: testMigrateClearsErrors
public function testMigrateClearsErrors()
{
$migration = new Doctrine_Migration('migration_classes');
$migration->setCurrentVersion(3);
try {
$migration->migrate(3);
} catch (Doctrine_Migration_Exception $e) {
$this->assertTrue($migration->hasErrors());
$this->assertEqual(1, $migration->getNumErrors());
}
try {
$migration->migrate(3);
} catch (Doctrine_Migration_Exception $e) {
$this->assertTrue($migration->hasErrors());
$this->assertEqual(1, $migration->getNumErrors());
}
$migration->clearErrors();
$this->assertFalse($migration->hasErrors());
$this->assertEqual(0, $migration->getNumErrors());
}
示例12: testTest
public function testTest()
{
$migration1 = new Doctrine_Migration(dirname(__FILE__) . '/DC221');
$migration2 = new Doctrine_Migration(dirname(__FILE__) . '/DC221');
$this->assertEqual($migration1->getMigrationClasses(), $migration2->getMigrationClasses());
}
示例13: getCurrentMigrationVersion
protected function getCurrentMigrationVersion()
{
$migratePath = $this->_getMigrationsDirectoryPath();
$migration = new Doctrine_Migration($migratePath);
return $migration->getCurrentVersion();
}
示例14: migrate
public function migrate($version = null)
{
$migration = new Doctrine_Migration('application/migrations');
$migration->migrate($version);
}
示例15: generateMigrationClass
/**
* generateMigrationClass
*
* @return void
*/
public function generateMigrationClass($className, $options = array(), $up = null, $down = null, $return = false)
{
if ($return || !$this->getMigrationsPath()) {
return $this->buildMigrationClass($className, null, $options, $up, $down);
} else {
if (!$this->getMigrationsPath()) {
throw new Doctrine_Migration_Exception('You must specify the path to your migrations.');
}
$migration = new Doctrine_Migration($this->getMigrationsPath());
$next = (string) $migration->getNextVersion();
$fileName = str_repeat('0', 3 - strlen($next)) . $next . '_' . Doctrine::tableize($className) . $this->suffix;
$class = $this->buildMigrationClass($className, $fileName, $options, $up, $down);
$path = $this->getMigrationsPath() . DIRECTORY_SEPARATOR . $fileName;
file_put_contents($path, $class);
}
}