当前位置: 首页>>代码示例>>PHP>>正文


PHP Doctrine_Migration::getCurrentVersion方法代码示例

本文整理汇总了PHP中Doctrine_Migration::getCurrentVersion方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Migration::getCurrentVersion方法的具体用法?PHP Doctrine_Migration::getCurrentVersion怎么用?PHP Doctrine_Migration::getCurrentVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine_Migration的用法示例。


在下文中一共展示了Doctrine_Migration::getCurrentVersion方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testMigration

 public function testMigration()
 {
     $migration = new Doctrine_Migration('migration_classes');
     $this->assertFalse($migration->hasMigrated());
     $migration->setCurrentVersion(3);
     $migration->migrate(0);
     $this->assertEqual($migration->getCurrentVersion(), 0);
     $this->assertEqual($migration->getLatestVersion(), 4);
     $this->assertEqual($migration->getNextVersion(), 5);
     $current = $migration->getCurrentVersion();
     $migration->setCurrentVersion(100);
     $this->assertEqual($migration->getCurrentVersion(), 100);
     $migration->setCurrentVersion($current);
     $migration->migrate(3);
     $this->assertTrue($migration->hasMigrated());
     $this->assertEqual($migration->getCurrentVersion(), 3);
     $this->assertTrue($this->conn->import->tableExists('migration_phonenumber'));
     $this->assertTrue($this->conn->import->tableExists('migration_user'));
     $this->assertTrue($this->conn->import->tableExists('migration_profile'));
     $migration->migrate(4);
     $this->assertFalse($this->conn->import->tableExists('migration_profile'));
     $migration->migrate(0);
     $this->assertEqual($migration->getCurrentVersion(), 0);
     $this->assertTrue($migration->getMigrationClass(1) instanceof AddPhonenumber);
     $this->assertTrue($migration->getMigrationClass(2) instanceof AddUser);
     $this->assertTrue($migration->getMigrationClass(3) instanceof AddProfile);
     $this->assertTrue($migration->getMigrationClass(4) instanceof DropProfile);
     $this->assertFalse($this->conn->import->tableExists('migration_phonenumber'));
     $this->assertFalse($this->conn->import->tableExists('migration_user'));
     $this->assertFalse($this->conn->import->tableExists('migration_profile'));
 }
开发者ID:skoop,项目名称:doctrine1,代码行数:31,代码来源:MigrationTestCase.php

示例2: testMigration

 public function testMigration()
 {
     $migration = new Doctrine_Migration('migration_classes');
     $this->assertFalse($migration->hasMigrated());
     $migration->setCurrentVersion(3);
     $migration->migrate(0);
     $this->assertEqual($migration->getCurrentVersion(), 0);
     $this->assertEqual($migration->getLatestVersion(), 11);
     $this->assertEqual($migration->getNextVersion(), 12);
     $current = $migration->getCurrentVersion();
     $migration->setCurrentVersion(100);
     $this->assertEqual($migration->getCurrentVersion(), 100);
     $migration->setCurrentVersion($current);
     $migration->migrate(3);
     $this->assertTrue($migration->hasMigrated());
     $this->assertEqual($migration->getCurrentVersion(), 3);
     $this->assertTrue($this->conn->import->tableExists('migration_phonenumber'));
     $this->assertTrue($this->conn->import->tableExists('migration_user'));
     $this->assertTrue($this->conn->import->tableExists('migration_profile'));
     $migration->migrate(4);
     $this->assertFalse($this->conn->import->tableExists('migration_profile'));
     $migration->migrate(0);
     $this->assertEqual($migration->getCurrentVersion(), 0);
     $this->assertTrue($migration->getMigrationClass(1) instanceof AddPhonenumber);
     $this->assertTrue($migration->getMigrationClass(2) instanceof AddUser);
     $this->assertTrue($migration->getMigrationClass(3) instanceof AddProfile);
     $this->assertTrue($migration->getMigrationClass(4) instanceof DropProfile);
     $this->assertFalse($this->conn->import->tableExists('migration_phonenumber'));
     $this->assertFalse($this->conn->import->tableExists('migration_user'));
     $this->assertFalse($this->conn->import->tableExists('migration_profile'));
     $this->assertEqual(array(1 => 'AddPhonenumber', 2 => 'AddUser', 3 => 'AddProfile', 4 => 'DropProfile', 5 => 'Test5', 6 => 'Test6', 7 => 'Test7', 8 => 'Test8', 9 => 'Test9', 10 => 'Test10', 11 => 'Test11'), $migration->getMigrationClasses());
 }
开发者ID:dennybrandes,项目名称:doctrine1,代码行数:32,代码来源:MigrationTestCase.php

示例3: 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

示例4: 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

示例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: 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

示例8: getCurrentMigrationVersion

 protected function getCurrentMigrationVersion()
 {
     $migratePath = $this->_getMigrationsDirectoryPath();
     $migration = new Doctrine_Migration($migratePath);
     return $migration->getCurrentVersion();
 }
开发者ID:nabdoulm,项目名称:zf-doctrine,代码行数:6,代码来源:DoctrineProvider.php

示例9: preDispatch

 /**
  * (non-PHPdoc)
  * @see Zend_Controller_Plugin_Abstract::preDispatch()
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $dayssincefirstsetup = 0;
     $migration = new Doctrine_Migration(APPLICATION_PATH . '/configs/migrations');
     $LatestVersion = $migration->getLatestVersion();
     $CurrentVersion = $migration->getCurrentVersion();
     try {
         // Check if the config file has been created
         $isReady = Shineisp_Main::isReady();
         if ($isReady) {
             // Execute the migration
             if ($CurrentVersion < $LatestVersion) {
                 // write a log message
                 Shineisp_Commons_Utilities::log("Upgrade: Current Version is {$CurrentVersion} and the latest available version is {$LatestVersion}");
                 $dbconfig = Shineisp_Main::databaseConfig();
                 // Update the version in the config.xml file previously created
                 Settings::saveConfig($dbconfig, $LatestVersion);
                 if ($CurrentVersion > 0) {
                     Shineisp_Commons_Utilities::log("Upgrade: Migrate ShineISP version from {$CurrentVersion} to {$LatestVersion}");
                     $migration->migrate();
                 }
             }
             $db = Doctrine_Manager::getInstance()->getCurrentConnection();
             // Read and execute all the sql files saved in the /application/configs/data/sql directory
             $path = PROJECT_PATH . "/application/configs/data/sql";
             if (is_dir($path)) {
                 $directory_iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
                 try {
                     // get the first setup date
                     $setupdate = Settings::getConfigSetupDate();
                     if (empty($setupdate)) {
                         throw new Exception('Setup date is not set in the config.xml file');
                     }
                     // for each sql file do ...
                     foreach ($directory_iterator as $filename => $path_object) {
                         // get the sql file information
                         $info = pathinfo($filename);
                         if (!empty($info['extension']) && $info['extension'] == "sql") {
                             $name = $info['filename'];
                             // get the first part of the name with the filename that contains the date: YYYYMMddHis-NAME.sql
                             $arrName = explode("-", $name);
                             // if the string is a valid date get the days betweeen the sql file name and the day of the setup of shineisp
                             if (!empty($arrName[0]) && Zend_Date::isdate($arrName[0], 'YYYYMMddHis')) {
                                 $sqldate = new Zend_Date($arrName[0], 'YYYYMMddHis');
                                 $mysetupdate = new Zend_Date($setupdate, 'YYYYMMddHis');
                                 // get the difference of the two dates
                                 $diff = $sqldate->sub($mysetupdate)->toValue();
                                 $dayssincefirstsetup = floor($diff / 60 / 60 / 24);
                                 unset($sqldate);
                                 unset($mysetupdate);
                             }
                             // SQL files post installation will be executed
                             if ($dayssincefirstsetup >= 0) {
                                 // read the sql
                                 $sql = Shineisp_Commons_Utilities::readfile($info['dirname'] . "/" . $info['basename']);
                                 if (!empty($sql)) {
                                     // execute the sql strings
                                     $result = $db->execute($sql);
                                     // close the db connection
                                     $db->close();
                                     if ($result) {
                                         // write a log message
                                         Shineisp_Commons_Utilities::log($info['filename'] . ".sql has been executed.");
                                         // rename the sql
                                         rename($info['dirname'] . "/" . $info['basename'], $info['dirname'] . "/" . $info['filename'] . ".sql.old");
                                     }
                                 }
                             } else {
                                 // rename the sql
                                 rename($info['dirname'] . "/" . $info['basename'], $info['dirname'] . "/" . $info['filename'] . ".sql.old");
                                 // write a log message
                                 Shineisp_Commons_Utilities::log($info['filename'] . ".sql has been skipped because already set in the doctrine data setup.");
                             }
                         }
                     }
                 } catch (Exception $e) {
                     die($e->getMessage());
                 }
             }
         }
         // Execute the migration
         if ($CurrentVersion < $LatestVersion) {
             $dbconfig = Shineisp_Main::databaseConfig();
             // Update the version in the config.xml file previously created
             Settings::saveConfig($dbconfig, $LatestVersion);
             if ($CurrentVersion > 0) {
                 $migration->migrate();
             }
         }
     } catch (Exception $e) {
         Zend_Debug::dump($e->getMessage());
         die;
     }
 }
开发者ID:kokkez,项目名称:shineisp,代码行数:98,代码来源:Migrate.php

示例10: intval

 $conn = Doctrine_Manager::connection($db);
 if (isset($google_user)) {
     echo 'user: ' . $google_user->getNickname() . '<br>';
 }
 $migration = new Doctrine_Migration(__DIR__ . '/classes', $conn);
 $migration->setTableName('doctrine_migration_version');
 if (isset($_REQUEST['ver']) && (!isset($google_user) || $google_user->getNickname() == 'piotr.podstawski@gammanet.pl')) {
     $version = 0 + intval($_REQUEST['ver']);
 } else {
     $classesKeys = array_keys($migration->getMigrationClasses());
     $version = 0 + array_pop($classesKeys);
 }
 if (isset($_SERVER['HTTP_HOST'])) {
     echo '<h1>';
 }
 if ($migration->getCurrentVersion() == $version) {
     echo 'Database at version ' . $version . PHP_EOL;
 } else {
     $migration->migrate($version);
     echo 'Migrated succesfully to version ' . $migration->getCurrentVersion() . PHP_EOL;
 }
 if (isset($_SERVER['HTTP_HOST'])) {
     echo '</h1>';
 }
 if (isset($_SERVER['SERVER_SOFTWARE']) && strstr(strtolower($_SERVER['SERVER_SOFTWARE']), 'engine')) {
     require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
     $path = 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName() . '/sql';
     if (file_exists($path)) {
         foreach (scandir($path) as $file) {
             $f = $path . '/' . $file;
             echo 'Execute ' . $file . PHP_EOL;
开发者ID:podstawski,项目名称:papu,代码行数:31,代码来源:index.php

示例11: getCurrentVersion

 /**
  * Get the current version of the database
  *
  * @return integer $version
  */
 public function getCurrentVersion()
 {
     return $this->_migration->getCurrentVersion();
 }
开发者ID:KasaiDot,项目名称:FansubCMS,代码行数:9,代码来源:Migration.php

示例12: Version

 public function Version()
 {
     $migration = new Doctrine_Migration(APPLICATION_PATH . '/configs/migrations');
     return $migration->getCurrentVersion();
 }
开发者ID:kokkez,项目名称:shineisp,代码行数:5,代码来源:Version.php

示例13: 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();
     $to = $this->getMigrationVersion($migration, $arguments, $options);
     $noConfirmation = $options['no-confirmation'];
     $environment = $this->configuration instanceof sfApplicationConfiguration ? $this->configuration->getEnvironment() : 'all';
     // check if a migration is needed
     if ($from == $to) {
         $this->logSection('doctrine', sprintf('Already at migration version %s', $to));
         return;
     }
     // check connection is mysql
     if (!$migration->getConnection() instanceof Doctrine_Connection_Mysql) {
         $this->logSection('doctrine', 'Database connection must be MySQL', null, 'ERROR');
         return;
     }
     if ($options['disable-env']) {
         $result = $this->enableDisableEnv($options['env'], false);
         if (!$result) {
             $this->logSection('disable', 'Disabling failed task aborting', null, 'ERROR');
             return 1;
         }
     }
     // check if it's a dry run
     if ($options['dry-run'] && !$noConfirmation) {
         $confirmation = $this->askConfirmation(array('As MySQL auto commits on an alter table the database will be backed
       up prior to attempting migration and the backup restored once
       complete', 'There is the posibility of data loss during this process, It is
       set to run in the ' . $environment . ' environment', '', 'Are you sure you want to proceed? (y/N)'), 'QUESTION_LARGE', false);
         // allow user to abort
         if (!$confirmation) {
             $this->cleanUp($options);
             $this->logSection('doctrine', 'Task aborted');
             return 1;
         }
         $noConfirmation = true;
     }
     // do database backup
     $backupPath = $this->getBackupPath($arguments, $options, $environment . (!$options['keep-backup'] ? '.tmp' : ''));
     $this->logSection('mysql', 'Dumping database to ' . $backupPath);
     try {
         $this->backupDatabase($migration->getConnection(), $backupPath);
     } catch (Exception $e) {
         $this->cleanUp($options);
         $this->logBlock(array('Dumping MySQL database failed:', '', $e->getMessage()), 'ERROR_LARGE');
         return 1;
     }
     $this->logSection('mysql', 'Database dump completed');
     $this->logSection('doctrine', sprintf('Migrating from version %s to %s%s', $from, $to, $options['dry-run'] ? ' (dry run)' : ''));
     // perform migration
     try {
         $migration->migrate($to, $options['dry-run']);
     } catch (Exception $e) {
     }
     // do clean up if database needs to be restored
     if ($migration->hasErrors() || $options['dry-run']) {
         // check if we need to confirm database drop
         if (!$noConfirmation) {
             $confirmation = $this->askConfirmation(array('An error has occurred with the migration and the database can be' . ' restored to its previous state', 'To complete the restore the database in the ' . $environment . ' environment will be dropped and the  backup file (located at ' . $backupPath . ') will be used to restore the database.', '', 'Are you sure you want to proceed? (Y/n)'), 'QUESTION_LARGE', true);
             if (!$confirmation) {
                 $this->cleanUp($options);
                 $this->logSection('mysql', 'Database restore task aborted');
                 $this->logSection('mysql', 'Database backup at ' . $backupPath . 'has not been deleted');
                 $this->outputMigrationErrors($migration);
                 $this->logSection('doctrine', 'Task aborted');
                 return 1;
             }
         }
         // restore database
         try {
             $this->restoreBackup($migration->getConnection(), $backupPath);
         } catch (Exception $e) {
             $this->cleanUp($options);
             $this->outputMigrationErrors($migration);
             $this->logBlock(array('Database restore failed:', '', $e->getMessage()), 'ERROR_LARGE');
             $this->logSection('mysql', 'Database backup at ' . $backupPath . 'has not been deleted');
             return 1;
         }
         $this->logSection('mysql', 'Database restored successfully');
     }
     // delete backup if needed
     if (!$options['keep-backup']) {
         $this->logSection('mysql', 'Deleting backup file');
         $this->getFilesystem()->remove($backupPath);
     }
     if ($migration->hasErrors()) {
         $this->cleanUp($options);
         $this->outputMigrationErrors($migration);
         return 1;
     }
     $this->cleanUp($options);
     $this->logSection('doctrine', 'Migration complete');
 }
开发者ID:kevindew,项目名称:sfDoctrineMysqlSafeMigratePlugin,代码行数:99,代码来源:sfDoctrineMysqlSafeMigrateTask.class.php


注:本文中的Doctrine_Migration::getCurrentVersion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。