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


PHP Configuration::getMigrations方法代码示例

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


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

示例1: indexAction

 public function indexAction()
 {
     $container = $this->container;
     $conn = $this->get('doctrine')->getConnection();
     $dir = $container->getParameter('doctrine_migrations.dir_name');
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     $configuration = new Configuration($conn);
     $configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace'));
     $configuration->setMigrationsDirectory($dir);
     $configuration->registerMigrationsFromDirectory($dir);
     $configuration->setName($container->getParameter('doctrine_migrations.name'));
     $configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
     $versions = $configuration->getMigrations();
     foreach ($versions as $version) {
         $migration = $version->getMigration();
         if ($migration instanceof ContainerAwareInterface) {
             $migration->setContainer($container);
         }
     }
     $migration = new Migration($configuration);
     $migrated = $migration->migrate();
     // ...
 }
开发者ID:ssone,项目名称:cms-bundle,代码行数:25,代码来源:MigrationController.php

示例2: migrate

 /**
  * Run a migration to the current version or the given target version.
  *
  * @param string  $to             The version to migrate to.
  * @param boolean $dryRun         Whether or not to make this a dry run and not execute anything.
  * @param boolean $timeAllQueries Measuring or not the execution time of each SQL query.
  * @param callable|null $confirm A callback to confirm whether the migrations should be executed.
  *
  * @return array An array of migration sql statements. This will be empty if the the $confirm callback declines to execute the migration
  *
  * @throws MigrationException
  */
 public function migrate($to = null, $dryRun = false, $timeAllQueries = false, callable $confirm = null)
 {
     /**
      * If no version to migrate to is given we default to the last available one.
      */
     if ($to === null) {
         $to = $this->configuration->getLatestVersion();
     }
     $from = (string) $this->configuration->getCurrentVersion();
     $to = (string) $to;
     /**
      * Throw an error if we can't find the migration to migrate to in the registered
      * migrations.
      */
     $migrations = $this->configuration->getMigrations();
     if (!isset($migrations[$to]) && $to > 0) {
         throw MigrationException::unknownMigrationVersion($to);
     }
     $direction = $from > $to ? Version::DIRECTION_DOWN : Version::DIRECTION_UP;
     $migrationsToExecute = $this->configuration->getMigrationsToExecute($direction, $to);
     /**
      * If
      *  there are no migrations to execute
      *  and there are migrations,
      *  and the migration from and to are the same
      * means we are already at the destination return an empty array()
      * to signify that there is nothing left to do.
      */
     if ($from === $to && empty($migrationsToExecute) && !empty($migrations)) {
         return $this->noMigrations();
     }
     if (!$dryRun && false === $this->migrationsCanExecute($confirm)) {
         return [];
     }
     $output = $dryRun ? 'Executing dry run of migration' : 'Migrating';
     $output .= ' <info>%s</info> to <comment>%s</comment> from <comment>%s</comment>';
     $this->outputWriter->write(sprintf($output, $direction, $to, $from));
     /**
      * If there are no migrations to execute throw an exception.
      */
     if (empty($migrationsToExecute) && !$this->noMigrationException) {
         throw MigrationException::noMigrationsToExecute();
     } elseif (empty($migrationsToExecute)) {
         return $this->noMigrations();
     }
     $sql = [];
     $time = 0;
     foreach ($migrationsToExecute as $version) {
         $versionSql = $version->execute($direction, $dryRun, $timeAllQueries);
         $sql[$version->getVersion()] = $versionSql;
         $time += $version->getTime();
     }
     $this->outputWriter->write("\n  <comment>------------------------</comment>\n");
     $this->outputWriter->write(sprintf("  <info>++</info> finished in %ss", $time));
     $this->outputWriter->write(sprintf("  <info>++</info> %s migrations executed", count($migrationsToExecute)));
     $this->outputWriter->write(sprintf("  <info>++</info> %s sql queries", count($sql, true) - count($sql)));
     return $sql;
 }
开发者ID:doctrine,项目名称:migrations,代码行数:70,代码来源:Migration.php

示例3: configureMigrations

 public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
 {
     if (!$configuration->getMigrationsDirectory()) {
         $dir = $container->getParameter('doctrine_migrations.dir_name');
         if (!file_exists($dir)) {
             mkdir($dir, 0777, true);
         }
         $configuration->setMigrationsDirectory($dir);
     } else {
         $dir = $configuration->getMigrationsDirectory();
         // class Kernel has method getKernelParameters with some of the important path parameters
         $pathPlaceholderArray = array('kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir');
         foreach ($pathPlaceholderArray as $pathPlaceholder) {
             if ($container->hasParameter($pathPlaceholder) && preg_match('/\\%' . $pathPlaceholder . '\\%/', $dir)) {
                 $dir = str_replace('%' . $pathPlaceholder . '%', $container->getParameter($pathPlaceholder), $dir);
             }
         }
         if (!file_exists($dir)) {
             mkdir($dir, 0777, true);
         }
         $configuration->setMigrationsDirectory($dir);
     }
     if (!$configuration->getMigrationsNamespace()) {
         $configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace'));
     }
     if (!$configuration->getName()) {
         $configuration->setName($container->getParameter('doctrine_migrations.name'));
     }
     // For backward compatibility, need use a table from parameters for overwrite the default configuration
     if (!$configuration->getMigrationsTableName() || !$configuration instanceof AbstractFileConfiguration) {
         $configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
     }
     // Migrations is not register from configuration loader
     if (!$configuration instanceof AbstractFileConfiguration) {
         $configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
     }
     if ($container->hasParameter('doctrine_migrations.organize_migrations')) {
         $organizeMigrations = $container->getParameter('doctrine_migrations.organize_migrations');
         switch ($organizeMigrations) {
             case Configuration::VERSIONS_ORGANIZATION_BY_YEAR:
                 $configuration->setMigrationsAreOrganizedByYear(true);
                 break;
             case Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH:
                 $configuration->setMigrationsAreOrganizedByYearAndMonth(true);
                 break;
             case false:
                 break;
             default:
                 throw new InvalidConfigurationException('Unrecognized option "' . $organizeMigrations . '" under "organize_migrations"');
         }
     }
     self::injectContainerToMigrations($container, $configuration->getMigrations());
 }
开发者ID:dextervip,项目名称:DoctrineMigrationsBundle,代码行数:53,代码来源:DoctrineCommand.php

示例4: configureMigrations

 protected function configureMigrations(ContainerInterface $container, Configuration $configuration)
 {
     $dir = $container->getParameter('ezpublish_migrations.dir_name');
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     $configuration->setMigrationsNamespace($container->getParameter('ezpublish_migrations.namespace'));
     $configuration->setMigrationsDirectory($dir);
     $configuration->registerMigrationsFromDirectory($dir);
     $configuration->setName($container->getParameter('ezpublish_migrations.name'));
     $configuration->setMigrationsTableName($container->getParameter('ezpublish_migrations.table_name'));
     self::injectContainerToMigrations($container, $configuration->getMigrations());
 }
开发者ID:xrowgmbh,项目名称:ezpublish-migrations-bundle,代码行数:13,代码来源:CommandTrait.php

示例5: migrate

    /**
     * Run a migration to the current version or the given target version.
     *
     * @param string $to      The version to migrate to.
     * @param string $dryRun  Whether or not to make this a dry run and not execute anything.
     * @return array $sql     The array of migration sql statements
     * @throws MigrationException
     */
    public function migrate($to = null, $dryRun = false)
    {
        if ($to === null) {
            $to = $this->configuration->getLatestVersion();
        }

        $from = $this->configuration->getCurrentVersion();
        $from = (string) $from;
        $to = (string) $to;

        $migrations = $this->configuration->getMigrations();
        if ( ! isset($migrations[$to]) && $to > 0) {
            throw MigrationException::unknownMigrationVersion($to);
        }

        if ($from === $to) {
            throw MigrationException::alreadyAtVersion($to);
        }

        $direction = $from > $to ? 'down' : 'up';
        $migrations = $this->configuration->getMigrationsToExecute($direction, $to);

        if ($dryRun === false) {
            $this->outputWriter->write(sprintf('Migrating <info>%s</info> to <comment>%s</comment> from <comment>%s</comment>', $direction, $to, $from));
        } else {
            $this->outputWriter->write(sprintf('Executing dry run of migration <info>%s</info> to <comment>%s</comment> from <comment>%s</comment>', $direction, $to, $from));
        }

        if (empty($migrations)) {
            throw MigrationException::noMigrationsToExecute();
        }

        $sql = array();
        $time = 0;
        foreach ($migrations as $version) {
            $versionSql = $version->execute($direction, $dryRun);
            $sql[$version->getVersion()] = $versionSql;
            $time += $version->getTime();
        }

        $this->outputWriter->write("\n  <comment>------------------------</comment>\n");
        $this->outputWriter->write(sprintf("  <info>++</info> finished in %s", $time));
        $this->outputWriter->write(sprintf("  <info>++</info> %s migrations executed", count($migrations)));
        $this->outputWriter->write(sprintf("  <info>++</info> %s sql queries", count($sql, true) - count($sql)));

        return $sql;
    }
开发者ID:nresni,项目名称:symfony-sandbox,代码行数:55,代码来源:Migration.php

示例6: testAddSql

 public function testAddSql()
 {
     $this->config->registerMigration(1, 'Doctrine\\DBAL\\Migrations\\Tests\\Functional\\MigrateAddSqlTest');
     $migration = new \Doctrine\DBAL\Migrations\Migration($this->config);
     $migration->migrate(1);
     $migrations = $this->config->getMigrations();
     $this->assertTrue($migrations[1]->isMigrated());
     $schema = $this->config->getConnection()->getSchemaManager()->createSchema();
     $this->assertTrue($schema->hasTable('test_add_sql_table'));
     $check = $this->config->getConnection()->fetchAll('select * from test_add_sql_table');
     $this->assertNotEmpty($check);
     $this->assertEquals('test', $check[0]['test']);
     $migration->migrate(0);
     $this->assertFalse($migrations[1]->isMigrated());
     $schema = $this->config->getConnection()->getSchemaManager()->createSchema();
     $this->assertFalse($schema->hasTable('test_add_sql_table'));
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:17,代码来源:FunctionalTest.php

示例7: migrate

 public function migrate()
 {
     $container = $this->container;
     $conn = $this->entityManager->getConnection();
     $SSoneCMSbundle = new SSoneCMSBundle();
     $dir = $SSoneCMSbundle->getPath() . "/Migrations";
     $configuration = new Configuration($conn);
     $configuration->setMigrationsNamespace('SSone\\CMSBundle\\Migrations');
     $configuration->setMigrationsDirectory($dir);
     $configuration->registerMigrationsFromDirectory($dir);
     $configuration->setName('One CMS Migrations');
     $configuration->setMigrationsTableName('cms_migrations');
     $versions = $configuration->getMigrations();
     foreach ($versions as $version) {
         $migration = $version->getMigration();
         if ($migration instanceof ContainerAwareInterface) {
             $migration->setContainer($container);
         }
     }
     $migration = new Migration($configuration);
     $migrated = $migration->migrate();
 }
开发者ID:ssone,项目名称:cms-bundle,代码行数:22,代码来源:MigrationService.php

示例8: configureMigrations

 public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
 {
     if (!$configuration->getMigrationsDirectory()) {
         $dir = $container->getParameter('doctrine_migrations.dir_name');
         if (!file_exists($dir)) {
             mkdir($dir, 0777, true);
         }
         $configuration->setMigrationsDirectory($dir);
     } else {
         $dir = $configuration->getMigrationsDirectory();
         // class Kernel has method getKernelParameters with some of the important path parameters
         $pathPlaceholderArray = array('kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir');
         foreach ($pathPlaceholderArray as $pathPlaceholder) {
             if ($container->hasParameter($pathPlaceholder) && preg_match('/\\%' . $pathPlaceholder . '\\%/', $dir)) {
                 $dir = str_replace('%' . $pathPlaceholder . '%', $container->getParameter($pathPlaceholder), $dir);
             }
         }
         if (!file_exists($dir)) {
             mkdir($dir, 0777, true);
         }
         $configuration->setMigrationsDirectory($dir);
     }
     if (!$configuration->getMigrationsNamespace()) {
         $configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace'));
     }
     if (!$configuration->getName()) {
         $configuration->setName($container->getParameter('doctrine_migrations.name'));
     }
     // For backward compatibility, need use a table from parameters for overwrite the default configuration
     if (!$configuration->getMigrationsTableName() || !$configuration instanceof AbstractFileConfiguration) {
         $configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
     }
     // Migrations is not register from configuration loader
     if (!$configuration instanceof AbstractFileConfiguration) {
         $configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
     }
     self::injectContainerToMigrations($container, $configuration->getMigrations());
 }
开发者ID:Dren-x,项目名称:mobitnew,代码行数:38,代码来源:DoctrineCommand.php

示例9: testInterweavedMigrationsAreExecuted

 public function testInterweavedMigrationsAreExecuted()
 {
     $this->config->registerMigration(1, 'Doctrine\\DBAL\\Migrations\\Tests\\Functional\\MigrateAddSqlTest');
     $this->config->registerMigration(3, 'Doctrine\\DBAL\\Migrations\\Tests\\Functional\\MigrationMigrateFurther');
     $migration = new \Doctrine\DBAL\Migrations\Migration($this->config);
     $migration->migrate();
     $migrations = $this->config->getMigrations();
     $this->assertTrue($migrations[1]->isMigrated());
     $this->assertTrue($migrations[3]->isMigrated());
     $this->assertEquals(3, $this->config->getCurrentVersion());
     $config = new Configuration($this->connection);
     $config->setMigrationsNamespace('Doctrine\\DBAL\\Migrations\\Tests\\Functional');
     $config->setMigrationsDirectory('.');
     $config->registerMigration(1, 'Doctrine\\DBAL\\Migrations\\Tests\\Functional\\MigrateAddSqlTest');
     $config->registerMigration(2, 'Doctrine\\DBAL\\Migrations\\Tests\\Functional\\MigrationMigrateUp');
     $config->registerMigration(3, 'Doctrine\\DBAL\\Migrations\\Tests\\Functional\\MigrationMigrateFurther');
     $this->assertEquals(1, count($config->getMigrationsToExecute('up', 3)));
     $migrations = $config->getMigrationsToExecute('up', 3);
     $this->assertTrue(isset($migrations[2]));
     $this->assertEquals(2, $migrations[2]->getVersion());
     $migration = new \Doctrine\DBAL\Migrations\Migration($config);
     $migration->migrate();
     $migrations = $config->getMigrations();
     $this->assertTrue($migrations[1]->isMigrated());
     $this->assertTrue($migrations[2]->isMigrated());
     $this->assertTrue($migrations[3]->isMigrated());
     $this->assertEquals(3, $config->getCurrentVersion());
 }
开发者ID:comporu,项目名称:migrations,代码行数:28,代码来源:FunctionalTest.php

示例10: getMigrations

 public function getMigrations()
 {
     $this->doRegister();
     return parent::getMigrations();
 }
开发者ID:librette,项目名称:doctrine-migrations,代码行数:5,代码来源:Configuration.php


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