getMigrationsDirectory() public méthode

Returns the new migrations directory where new migration classes are generated
public getMigrationsDirectory ( ) : string
Résultat string $migrationsDirectory The new migrations directory
 public function getMigrationsInfos()
 {
     $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' => $this->getFormattedVersionAlias('prev'), 'Current Version' => $this->getFormattedVersionAlias('current'), 'Next Version' => $this->getFormattedVersionAlias('next'), 'Latest Version' => $this->getFormattedVersionAlias('latest'), 'Executed Migrations' => count($this->executedMigrations), 'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations, 'Available Migrations' => count($this->availableMigrations), 'New Migrations' => $numNewMigrations];
     return $infos;
 }
 public function registerMigrations(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!$this->isMigrationCommand($command)) {
         return;
     }
     $this->configuration->registerMigrationsFromDirectory($this->configuration->getMigrationsDirectory());
 }
 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());
 }
 public function getMigrationDirectory()
 {
     $dir = $this->configuration->getMigrationsDirectory();
     $dir = $dir ? $dir : getcwd();
     $dir = rtrim($dir, '/');
     if (!file_exists($dir)) {
         throw new \InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir));
     }
     if ($this->configuration->areMigrationsOrganizedByYear()) {
         $dir .= $this->appendDir(date('Y'));
     }
     if ($this->configuration->areMigrationsOrganizedByYearAndMonth()) {
         $dir .= $this->appendDir(date('m'));
     }
     $this->createDirIfNotExists($dir);
     return $dir;
 }
 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;
 }
Exemple #6
0
 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());
 }
 protected function _generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
 {
     $placeHolders = array('<namespace>', '<version>', '<up>', '<down>');
     $replacements = array($configuration->getMigrationsNamespace(), $version, $up ? "        " . implode("\n        ", explode("\n", $up)) : null, $down ? "        " . implode("\n        ", explode("\n", $down)) : null);
     $code = str_replace($placeHolders, $replacements, self::$_template);
     $dir = $configuration->getMigrationsDirectory();
     $dir = $dir ? $dir : getcwd();
     $dir = rtrim($dir, '/');
     $path = $dir . '/Version' . $version . '.php';
     file_put_contents($path, $code);
     if ($editorCmd = $input->getOption('editor-cmd')) {
         shell_exec($editorCmd . ' ' . escapeshellarg($path));
     }
     return $path;
 }
 public function register(Application $app)
 {
     if (!isset($app['migration.outputwriter'])) {
         $app['migration.outputwriter'] = null;
     }
     $app['migration'] = $app->share(function () use($app) {
         return new Migration($app['migration.configuration']);
     });
     $app['migration.configuration'] = $app->share(function () use($app) {
         $configuration = new Configuration($app['db'], $app['migration.outputwriter']);
         if (isset($app['migration.table'])) {
             $configuration->setMigrationsTableName($app['migration.table']);
         }
         $configuration->setMigrationsNamespace($app['migration.namespace']);
         $configuration->setMigrationsDirectory($app['migration.directory']);
         $configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
         return $configuration;
     });
 }
 protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
 {
     $placeHolders = ['<namespace>', '<version>', '<up>', '<down>'];
     $replacements = [$configuration->getMigrationsNamespace(), $version, $up ? '        ' . implode("\n        ", explode("\n", $up)) : null, $down ? '        ' . implode("\n        ", explode("\n", $down)) : null];
     $code = str_replace($placeHolders, $replacements, $this->template);
     $dir = $configuration->getMigrationsDirectory();
     $dir = $dir ? $dir : getcwd();
     $dir = rtrim($dir, '/');
     $path = $dir . '/Version' . $version . '.php';
     if (!file_exists($dir)) {
         // @codeCoverageIgnoreStart
         throw new \InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir));
         // @codeCoverageIgnoreEnd
     }
     file_put_contents($path, $code);
     if ($editorCmd = $input->getOption('editor-cmd')) {
         shell_exec($editorCmd . ' ' . escapeshellarg($path));
     }
     return $path;
 }
    /**
     * @param \Doctrine\DBAL\Migrations\Configuration\Configuration $configuration
     * @param string $up
     * @param string $down
     * @return string
     * @throws \RuntimeException
     */
    protected function writeMigrationClassToFile(\Doctrine\DBAL\Migrations\Configuration\Configuration $configuration, $up, $down)
    {
        $namespace = $configuration->getMigrationsNamespace();
        $className = 'Version' . date('YmdHis');
        $up = $up === null ? '' : "\n\t\t" . implode("\n\t\t", explode("\n", $up));
        $down = $down === null ? '' : "\n\t\t" . implode("\n\t\t", explode("\n", $down));
        $path = \TYPO3\Flow\Utility\Files::concatenatePaths(array($configuration->getMigrationsDirectory(), $className . '.php'));
        try {
            \TYPO3\Flow\Utility\Files::createDirectoryRecursively(dirname($path));
        } catch (\TYPO3\Flow\Utility\Exception $exception) {
            throw new \RuntimeException(sprintf('Migration target directory "%s" does not exist.', dirname($path)), 1303298536, $exception);
        }
        $code = <<<EOT
<?php
namespace {$namespace};

use Doctrine\\DBAL\\Migrations\\AbstractMigration,
\tDoctrine\\DBAL\\Schema\\Schema;

/**
 * Auto-generated Migration: Please modify to your need!
 */
class {$className} extends AbstractMigration {

\t/**
\t * @param Schema \$schema
\t * @return void
\t */
\tpublic function up(Schema \$schema) {
\t\t// this up() migration is autogenerated, please modify it to your needs{$up}
\t}

\t/**
\t * @param Schema \$schema
\t * @return void
\t */
\tpublic function down(Schema \$schema) {
\t\t// this down() migration is autogenerated, please modify it to your needs{$down}
\t}
}
EOT;
        file_put_contents($path, $code);
        return $path;
    }
    /**
     * @param Configuration $configuration
     * @param string $up
     * @param string $down
     * @return string
     * @throws \RuntimeException
     */
    protected function writeMigrationClassToFile(Configuration $configuration, $up, $down)
    {
        $namespace = $configuration->getMigrationsNamespace();
        $className = 'Version' . date('YmdHis');
        $up = $up === null ? '' : "\n        " . implode("\n        ", explode("\n", $up));
        $down = $down === null ? '' : "\n        " . implode("\n        ", explode("\n", $down));
        $path = Files::concatenatePaths(array($configuration->getMigrationsDirectory(), $className . '.php'));
        try {
            Files::createDirectoryRecursively(dirname($path));
        } catch (Exception $exception) {
            throw new \RuntimeException(sprintf('Migration target directory "%s" does not exist.', dirname($path)), 1303298536, $exception);
        }
        $code = <<<EOT
<?php
namespace {$namespace};

use Doctrine\\DBAL\\Migrations\\AbstractMigration;
use Doctrine\\DBAL\\Schema\\Schema;

/**
 * Auto-generated Migration: Please modify to your needs! This block will be used as the migration description if getDescription() is not used.
 */
class {$className} extends AbstractMigration
{

    /**
     * @return string
     */
    public function getDescription() {
        return '';
    }

    /**
     * @param Schema \$schema
     * @return void
     */
    public function up(Schema \$schema)
    {
        // this up() migration is autogenerated, please modify it to your needs{$up}
    }

    /**
     * @param Schema \$schema
     * @return void
     */
    public function down(Schema \$schema)
    {
        // this down() migration is autogenerated, please modify it to your needs{$down}
    }
}
EOT;
        file_put_contents($path, $code);
        return $path;
    }
 protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
 {
     $placeHolders = ['<namespace>', '<version>', '<up>', '<down>'];
     $replacements = [$configuration->getMigrationsNamespace(), $version, $up ? "        " . implode("\n        ", explode("\n", $up)) : null, $down ? "        " . implode("\n        ", explode("\n", $down)) : null];
     $code = str_replace($placeHolders, $replacements, self::$_template);
     $code = preg_replace('/^ +$/m', '', $code);
     $dir = $configuration->getMigrationsDirectory();
     $dir = $dir ? $dir : getcwd();
     $dir = rtrim($dir, '/');
     $path = $dir . '/Version' . $version . '.php';
     if (!file_exists($dir)) {
         throw new \InvalidArgumentException(sprintf('Migrations directory "%s" does not exist.', $dir));
     }
     file_put_contents($path, $code);
     if ($editorCmd = $input->getOption('editor-cmd')) {
         proc_open($editorCmd . ' ' . escapeshellarg($path), [], $pipes);
     }
     return $path;
 }
 /**
  * @param string $version
  * @return string
  */
 private function getMigrationFileByVersion($version)
 {
     return $this->configuration->getMigrationsDirectory() . '/Version' . $version . '.php';
 }
Exemple #14
0
 /**
  * @return Configuration
  */
 private function getMigrationConfig(array &$errors)
 {
     $connection = $this->container->get('doctrine.dbal.default_connection');
     $config = new Configuration($connection, new OutputWriter(function ($message) use($errors) {
         $matches = [];
         if (preg_match('#<error>(.*)</error>#', $message, $matches)) {
             $errors += $matches;
         }
     }));
     $config->setName($this->container->getParameter('doctrine_migrations.name'));
     $config->setMigrationsTableName($this->container->getParameter('doctrine_migrations.table_name'));
     $config->setMigrationsNamespace($this->container->getParameter('doctrine_migrations.namespace'));
     $config->setMigrationsDirectory($this->container->getParameter('doctrine_migrations.dir_name'));
     // Register Migrations as there are not registered by Configuration
     $config->registerMigrationsFromDirectory($config->getMigrationsDirectory());
     return $config;
 }