當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Doctrine_Migration類代碼示例

本文整理匯總了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');
     }
 }
開發者ID:hunde,項目名稱:bsc,代碼行數:26,代碼來源:GenerateMigrationsDb.php

示例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');
     }
 }
開發者ID:hasanozgan,項目名稱:kissabe,代碼行數:25,代碼來源:GenerateMigrationsModels.php

示例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);
    }
}
開發者ID:reTHINK-project,項目名稱:dev-IdPServer-phpOIDC,代碼行數:25,代碼來源:migration.php

示例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']);
 }
開發者ID:bshaffer,項目名稱:Symplist,代碼行數:12,代碼來源:sfDoctrineMigrationSetTask.class.php

示例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');
 }
開發者ID:Phennim,項目名稱:symfony1,代碼行數:56,代碼來源:sfDoctrineMigrateTask.class.php

示例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);
 }
開發者ID:hidenorigoto,項目名稱:sfjp-cms2,代碼行數:14,代碼來源:doctrineSetmigrationversionnumberTask.class.php

示例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;
     }
 }
開發者ID:atikahmed,項目名稱:joomla-probid,代碼行數:36,代碼來源:Builder.php

示例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);
     }
 }
開發者ID:KnpLabs,項目名稱:knpDoctrineVersionPlugin,代碼行數:20,代碼來源:knpDoctrineVersionTask.class.php

示例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()));
     }
 }
開發者ID:solutema,項目名稱:siwapp-sf1,代碼行數:16,代碼來源:actions.class.php

示例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);
    }
開發者ID:prismhdd,項目名稱:victorioussecret,代碼行數:19,代碼來源:MigrationTestCase.php

示例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());
 }
開發者ID:skoop,項目名稱:doctrine1,代碼行數:20,代碼來源:MigrationTestCase.php

示例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());
 }
開發者ID:kaakshay,項目名稱:audience-insight-repository,代碼行數:6,代碼來源:DC221TestCase.php

示例13: getCurrentMigrationVersion

 protected function getCurrentMigrationVersion()
 {
     $migratePath = $this->_getMigrationsDirectoryPath();
     $migration = new Doctrine_Migration($migratePath);
     return $migration->getCurrentVersion();
 }
開發者ID:nabdoulm,項目名稱:zf-doctrine,代碼行數:6,代碼來源:DoctrineProvider.php

示例14: migrate

 public function migrate($version = null)
 {
     $migration = new Doctrine_Migration('application/migrations');
     $migration->migrate($version);
 }
開發者ID:chileindica,項目名稱:SIMPLE,代碼行數:5,代碼來源:migration.php

示例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);
     }
 }
開發者ID:kirvin,項目名稱:the-nerdery,代碼行數:21,代碼來源:Builder.php


注:本文中的Doctrine_Migration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。