getDateTime() public method

Returns the datetime of a migration
public getDateTime ( $version ) : string
$version
return string
コード例 #1
0
 private function getFormattedVersionAlias($alias)
 {
     $version = $this->configuration->resolveVersionAlias($alias);
     //No version found
     if ($version === null) {
         if ($alias == 'next') {
             return 'Already at latest version';
         } elseif ($alias == 'prev') {
             return 'Already at first version';
         }
     }
     //Before first version "virtual" version number
     if ($version === '0') {
         return '<comment>0</comment>';
     }
     //Show normal version number
     return $this->configuration->getDateTime($version) . ' (<comment>' . $version . '</comment>)';
 }
コード例 #2
0
 public function getMigrationsInfos()
 {
     $formattedVersions = [];
     foreach (['prev', 'current', 'next', 'latest'] as $alias) {
         $version = $this->configuration->resolveVersionAlias($alias);
         if ($version === null) {
             if ($alias == 'next') {
                 $formattedVersions[$alias] = 'Already at latest version';
             } elseif ($alias == 'prev') {
                 $formattedVersions[$alias] = 'Already at first version';
             }
         } elseif ($version === '0') {
             $formattedVersions[$alias] = '<comment>0</comment>';
         } else {
             $formattedVersions[$alias] = $this->configuration->getDateTime($version) . ' (<comment>' . $version . '</comment>)';
         }
     }
     $numExecutedUnavailableMigrations = count($this->executedUnavailableMigrations);
     $numNewMigrations = count(array_diff($this->availableMigrations, $this->executedMigrations));
     $infos = ['Name' => $this->configuration->getName() ? $this->configuration->getName() : 'Doctrine Database Migrations', 'Database Driver' => $this->configuration->getConnection()->getDriver()->getName(), 'Database Name' => $this->configuration->getConnection()->getDatabase(), 'Configuration Source' => $this->configuration instanceof AbstractFileConfiguration ? $this->configuration->getFile() : 'manually configured', 'Version Table Name' => $this->configuration->getMigrationsTableName(), 'Version Column Name' => $this->configuration->getMigrationsColumnName(), 'Migrations Namespace' => $this->configuration->getMigrationsNamespace(), 'Migrations Directory' => $this->configuration->getMigrationsDirectory(), 'Previous Version' => $formattedVersions['prev'], 'Current Version' => $formattedVersions['current'], 'Next Version' => $formattedVersions['next'], 'Latest Version' => $formattedVersions['latest'], 'Executed Migrations' => count($this->executedMigrations), 'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations, 'Available Migrations' => count($this->availableMigrations), 'New Migrations' => $numNewMigrations];
     return $infos;
 }
コード例 #3
0
 /**
  * @Route("/{connectionName}/")
  */
 public function viewAction($connectionName)
 {
     $connection = $this->getDoctrine()->getConnection($connectionName);
     $outputWriter = new MemoryOutputWriter();
     $configuration = new Configuration($connection);
     $configuration->setName($this->container->getParameter('doctrine_migrations.name'));
     $configuration->setOutputWriter($outputWriter);
     $configuration->setMigrationsTableName($this->container->getParameter('doctrine_migrations.table_name'));
     $configuration->setMigrationsDirectory($this->container->getParameter('doctrine_migrations.dir_name'));
     $configuration->setMigrationsNamespace($this->container->getParameter('doctrine_migrations.namespace'));
     $migration = new Migration($configuration);
     $executedMigrations = $configuration->getMigratedVersions();
     $availableMigrations = $configuration->getAvailableVersions();
     $executedUnavailableMigrations = array_diff($executedMigrations, $availableMigrations);
     foreach ($executedUnavailableMigrations as $i => $executedUnavailableMigration) {
         $executedUnavailableMigrations[$i] = $executedUnavailableMigration . ' (' . $configuration->getDateTime($executedUnavailableMigration) . ')';
     }
     $dryRun = true;
     $migration->setNoMigrationException(true);
     $sql = $migration->migrate(null, $dryRun);
     return $this->render('MarkeiDoctrineMigrationWebBundle:Migrate:view.html.twig', ['connectionName' => $connectionName, 'executedUnavailableMigrations' => $executedUnavailableMigrations, 'to' => $configuration->getLatestVersion(), 'from' => $configuration->getCurrentVersion(), 'migrations' => $sql, 'name' => $this->container->getParameter('doctrine_migrations.name')]);
 }
コード例 #4
0
 private function showVersions($migrations, Configuration $configuration, $output)
 {
     $migratedVersions = $configuration->getMigratedVersions();
     foreach ($migrations as $version) {
         $isMigrated = in_array($version->getVersion(), $migratedVersions);
         $status = $isMigrated ? '<info>migrated</info>' : '<error>not migrated</error>';
         $migrationDescription = '';
         if ($version->getMigration()->getDescription()) {
             $migrationDescription = str_repeat(' ', 5) . $version->getMigration()->getDescription();
         }
         $formattedVersion = $configuration->getDateTime($version->getVersion());
         $output->writeln('    <comment>>></comment> ' . $formattedVersion . ' (<comment>' . $version->getVersion() . '</comment>)' . str_repeat(' ', 49 - strlen($formattedVersion) - strlen($version->getVersion())) . $status . $migrationDescription);
     }
 }
コード例 #5
0
 /**
  * Returns a formatted version string for the alias.
  *
  * @param string $alias
  * @param Configuration $configuration
  * @return string
  */
 protected function getFormattedVersionAlias($alias, Configuration $configuration)
 {
     $version = $configuration->resolveVersionAlias($alias);
     if ($version === null) {
         if ($alias == 'next') {
             return 'Already at latest version';
         } elseif ($alias == 'prev') {
             return 'Already at first version';
         }
     }
     if ($version === '0') {
         return '<comment>0</comment>';
     }
     return $configuration->getDateTime($version) . ' (<comment>' . $version . '</comment>)';
 }