setName() public method

Set the name of this set of migrations
public setName ( string $name )
$name string The name of this set of migrations
Example #1
1
 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();
     // ...
 }
Example #2
0
 public function generateMigrationSql($return, &$hasMigrations)
 {
     $config = \Config::getInstance();
     $modules = $config->getActiveModules();
     $connection = $GLOBALS['container']['doctrine.connection.default'];
     $output = new OutputWriter();
     foreach ($modules as $module) {
         $path = sprintf('%s/system/modules/%s/migrations', TL_ROOT, $module);
         if (is_dir($path)) {
             $namespace = preg_split('~[\\-_]~', $module);
             $namespace = array_map('ucfirst', $namespace);
             $namespace = implode('', $namespace);
             $configuration = new Configuration($connection, $output);
             $configuration->setName($module);
             $configuration->setMigrationsNamespace('DoctrineMigrations\\' . $namespace);
             $configuration->setMigrationsDirectory($path);
             $configuration->registerMigrationsFromDirectory($path);
             $migration = new Migration($configuration);
             $versions = $migration->getSql();
             if (count($versions)) {
                 foreach ($versions as $version => $queries) {
                     if (count($queries)) {
                         $_SESSION['TL_CONFIRM'][] = sprintf($GLOBALS['TL_LANG']['doctrine']['migration'], $module, $version);
                         $hasMigrations = true;
                         $return = $this->appendQueries($return, $queries);
                     }
                 }
             }
         }
     }
     return $return;
 }
Example #3
0
 /**
  * @param Connection $connection
  * @param AppKernel  $kernel
  *
  * @throws \Claroline\MigrationBundle\Migrator\InvalidDirectionException
  * @throws \Claroline\MigrationBundle\Migrator\InvalidVersionException
  * @throws \Doctrine\DBAL\Migrations\MigrationException
  */
 protected function migrateBadgeTables(Connection $connection, AppKernel $kernel)
 {
     $portfolioBundle = $this->container->get('claroline.persistence.object_manager')->getRepository('ClarolineCoreBundle:Plugin')->findBy(array('vendorName' => 'Icap', 'bundleName' => 'PortfolioBundle'));
     $portfolioBundle = count($portfolioBundle) === 1 ? true : false;
     if (!$portfolioBundle && $connection->getSchemaManager()->tablesExist(['icap__portfolio_widget_badges'])) {
         $this->log('Deleting portfolios badges tables...');
         $connection->getSchemaManager()->dropTable('icap__portfolio_widget_badges_badge');
         $connection->getSchemaManager()->dropTable('icap__portfolio_widget_badges');
         $this->log('Portfolios badges tables deleted.');
     }
     if ($portfolioBundle && !$connection->getSchemaManager()->tablesExist(['icap__portfolio_widget_badges'])) {
         $badgeBundle = $kernel->getBundle('IcapBadgeBundle');
         $this->log('Executing migrations for portfolio interaction');
         $migrationsDir = "{$badgeBundle->getPath()}/Installation/Migrations";
         $migrationsName = "{$badgeBundle->getName()} migration";
         $migrationsNamespace = "{$badgeBundle->getNamespace()}\\Installation\\Migrations";
         $migrationsTableName = 'doctrine_' . strtolower($badgeBundle->getName()) . '_versions';
         $config = new Configuration($connection);
         $config->setName($migrationsName);
         $config->setMigrationsDirectory($migrationsDir);
         $config->setMigrationsNamespace($migrationsNamespace);
         $config->setMigrationsTableName($migrationsTableName);
         $config->registerMigrationsFromDirectory($migrationsDir);
         $migration = new Migration($config);
         $executedQueriesNumber = $migration->migrate('20150929141509');
         $this->log(sprintf('%d queries executed', $executedQueriesNumber));
     }
 }
 public function boot(Application $app)
 {
     $app['dispatcher']->addListener(ConsoleEvents::INIT, function (ConsoleEvent $event) use($app) {
         $console = $event->getConsole();
         $helpers = ['dialog' => new QuestionHelper()];
         if (isset($app['orm.em'])) {
             $helpers['em'] = new EntityManagerHelper($app['orm.em']);
         }
         $helperSet = new HelperSet($helpers);
         $console->setHelperSet($helperSet);
         $config = new Configuration($app['db']);
         $config->setMigrationsNamespace($app['db.migrations.namespace']);
         if ($app['db.migrations.path']) {
             $config->setMigrationsDirectory($app['db.migrations.path']);
             $config->registerMigrationsFromDirectory($app['db.migrations.path']);
         }
         if ($app['db.migrations.name']) {
             $config->setName($app['db.migrations.name']);
         }
         if ($app['db.migrations.table_name']) {
             $config->setMigrationsTableName($app['db.migrations.table_name']);
         }
         $commands = [new Command\DiffCommand(), new Command\ExecuteCommand(), new Command\GenerateCommand(), new Command\MigrateCommand(), new Command\StatusCommand(), new Command\VersionCommand()];
         foreach ($commands as $command) {
             /** @var \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand $command */
             $command->setMigrationConfiguration($config);
             $console->add($command);
         }
     });
 }
 public static function configureMigrationsForBundle(Application $application, $bundle, Configuration $configuration)
 {
     $bundle = $application->getKernel()->getBundle($bundle);
     $dir = $bundle->getPath() . '/DoctrineMigrations';
     $configuration->setMigrationsNamespace($bundle->getNamespace() . '\\DoctrineMigrations');
     $configuration->setMigrationsDirectory($dir);
     $configuration->registerMigrationsFromDirectory($dir);
     $configuration->setName($bundle->getName() . ' Migrations');
     $configuration->setMigrationsTableName(Inflector::tableize($bundle->getName()) . '_migration_versions');
 }
Example #6
0
 /**
  * @param string   $dir
  * @param \Closure $outputWriter
  *
  * @return Configuration
  */
 private function getConfiguration($dir, \Closure $outputWriter = null)
 {
     $connection = $this->container->get('database_connection');
     $configuration = new Configuration($connection, new OutputWriter($outputWriter));
     $configuration->setMigrationsNamespace($this->container->getParameter('doctrine_migrations.namespace'));
     $configuration->setMigrationsDirectory($dir);
     $configuration->registerMigrationsFromDirectory($dir);
     $configuration->setName($this->container->getParameter('doctrine_migrations.name'));
     $configuration->setMigrationsTableName($this->container->getParameter('doctrine_migrations.table_name'));
     return $configuration;
 }
 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());
 }
 protected function configureMigrations(Container $container, Configuration $config)
 {
     $dir = $container['doctrine.migrations.dir_name'];
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     $config->setMigrationsNamespace($container['doctrine.migrations.namespace']);
     $config->setMigrationsDirectory($dir);
     $config->registerMigrationsFromDirectory($dir);
     $config->setName($container['doctrine.migrations.name']);
     $config->setMigrationsTableName($container['doctrine.migrations.table_name']);
 }
Example #9
0
 public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
 {
     $dir = $container->getParameter('doctrine_migrations.dir_name');
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     $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'));
 }
Example #10
0
 public static function configureMigrationsForBundle(Application $application, $bundle, Configuration $configuration)
 {
     $configuration->setMigrationsNamespace($bundle . '\\DoctrineMigrations');
     $dirs = $application->getKernel()->getBundleDirs();
     $tmp = str_replace('\\', '/', $bundle);
     $namespace = str_replace('/', '\\', dirname($tmp));
     $bundle = basename($tmp);
     $dir = $dirs[$namespace] . '/' . $bundle . '/DoctrineMigrations';
     $configuration->setMigrationsDirectory($dir);
     $configuration->registerMigrationsFromDirectory($dir);
     $configuration->setName($bundle . ' Migrations');
     $configuration->setMigrationsTableName(Inflector::tableize($bundle) . '_migration_versions');
 }
 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());
 }
 /**
  * {@inheritDoc}
  *
  * @return \Doctrine\DBAL\Migrations\Configuration\Configuration
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $name = $this->getName();
     /* @var $connection \Doctrine\DBAL\Connection */
     $connection = $serviceLocator->get('doctrine.connection.' . $name);
     $appConfig = $serviceLocator->get('Config');
     $migrationsConfig = $appConfig['doctrine']['migrations_configuration'][$name];
     $configuration = new Configuration($connection);
     $configuration->setName($migrationsConfig['name']);
     $configuration->setMigrationsDirectory($migrationsConfig['directory']);
     $configuration->setMigrationsNamespace($migrationsConfig['namespace']);
     $configuration->setMigrationsTableName($migrationsConfig['table']);
     $configuration->registerMigrationsFromDirectory($migrationsConfig['directory']);
     return $configuration;
 }
Example #13
0
 public function loadProviders(Application $app)
 {
     $app->register(new Provider\MonologServiceProvider(), $app['monolog.config']);
     $app->register(new Provider\DoctrineServiceProvider());
     // connect to db
     //        \SimpleRecord\Record::connection($app['db']);
     $models = ['post.model' => 'App\\Model\\Post', 'tag.model' => 'App\\Model\\Tag', 'post_tags.model' => 'App\\Model\\PostTags'];
     foreach ($models as $name => $class) {
         if (is_callable($class)) {
             $callable = $class;
         } else {
             $callable = function () use($class, $app) {
                 return new $class($app);
             };
         }
         $app[$name] = $app->factory($callable);
     }
     $app['migrations.output_writer'] = new OutputWriter(function ($message) {
         $output = new ConsoleOutput();
         $output->writeln($message);
     });
     $app['migrations.configuration'] = function () use($app) {
         $configuration = new Configuration($app['db'], $app['migrations.output_writer']);
         $configuration->setMigrationsDirectory($app['migrations']['directory']);
         $configuration->setName($app['migrations']['name']);
         $configuration->setMigrationsNamespace($app['migrations']['namespace']);
         $configuration->setMigrationsTableName($app['migrations']['table_name']);
         $configuration->registerMigrationsFromDirectory($app['migrations']['directory']);
         return $configuration;
     };
     $app->register(new Provider\TwigServiceProvider(), ['twig.path' => $app['root.path'] . '/templates/', 'twig.form.templates' => ['bootstrap_3_horizontal_layout.html.twig'], 'twig.options' => ['cache' => $app['cache.path'] . '/twig']]);
     $app->register(new Provider\AssetServiceProvider(), ['assets.named_packages' => ['css' => ['version' => 'v1', 'base_path' => '/asset/css'], 'js' => ['version' => 'v1', 'base_path' => '/asset/js']]]);
     $app->register(new Provider\SecurityServiceProvider());
     $app->register(new Provider\RoutingServiceProvider());
     //        $app->register(new Silex\Provider\HttpCacheServiceProvider(), [
     //            'http_cache.cache_dir' => $app['cache.path'] . '/http',
     //        ]);
     //        $app->register(new Silex\Provider\HttpFragmentServiceProvider());
     $app->register(new Provider\ValidatorServiceProvider());
     $app->register(new Provider\LocaleServiceProvider());
     $app->register(new Provider\TranslationServiceProvider());
     $app->register(new Provider\CsrfServiceProvider());
     $app->register(new Provider\FormServiceProvider());
     $app->register(new Provider\ServiceControllerServiceProvider());
     $app->register(new Provider\SessionServiceProvider());
     $app->register(new \Paginator\Provider\PaginatorServiceProvider());
     //        $app->register(new \Sorien\Provider\PimpleDumpProvider(), ['dump.path' => $app['root.path']]);
 }
 /**
  * @Route("/{connectionName}/execute/{version}")
  * @Method("POST")
  */
 public function executeAction($connectionName, $version)
 {
     $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);
     $currentVersion = $configuration->getCurrentVersion();
     $dryRun = false;
     $migration->setNoMigrationException(true);
     $sql = $migration->migrate($version, $dryRun, true);
     return $this->render('MarkeiDoctrineMigrationWebBundle:Migrate:execute.html.twig', ['connectionName' => $connectionName, 'to' => $version, 'from' => $currentVersion, 'output' => $outputWriter->getMemory(), 'name' => $this->container->getParameter('doctrine_migrations.name')]);
 }
 /**
  * {@inheritDoc}
  *
  * @return \Doctrine\DBAL\Migrations\Configuration\Configuration
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $name = $this->getName();
     /* @var $connection \Doctrine\DBAL\Connection */
     $connection = $container->get('doctrine.connection.' . $name);
     $appConfig = $container->get('Config');
     $migrationsConfig = $appConfig['doctrine']['migrations_configuration'][$name];
     $configuration = new Configuration($connection);
     $configuration->setName($migrationsConfig['name']);
     $configuration->setMigrationsDirectory($migrationsConfig['directory']);
     $configuration->setMigrationsNamespace($migrationsConfig['namespace']);
     $configuration->setMigrationsTableName($migrationsConfig['table']);
     $configuration->registerMigrationsFromDirectory($migrationsConfig['directory']);
     if (method_exists($configuration, 'setMigrationsColumnName')) {
         $configuration->setMigrationsColumnName($migrationsConfig['column']);
     }
     return $configuration;
 }
Example #16
0
 /**
  * creates and returns the configuration for doctrine migrations
  * @return Doctrine\DBAL\Migrations\Configuration\Configuration
  */
 private function getMigrationsConfiguration()
 {
     //get instances
     $scriptBaseDir = realpath(dirname(__FILE__));
     $ormController = OrmController::create();
     $connection = $ormController->getEntityManager()->getConnection();
     //fix to handle enum types for migrating old yourCMDB versions
     $connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
     //migration configuration
     $migrationConfig = new Configuration($connection);
     $migrationConfig->setName("yourCMDB datastore migrations");
     $migrationConfig->setMigrationsTableName(self::MIGRATIONS_TABLE_NAME);
     $migrationConfig->setMigrationsDirectory("{$scriptBaseDir}/DatastoreMigrations");
     $migrationConfig->setMigrationsNamespace(self::MIGRATIONS_NAMESPACE);
     $migrationConfig->registerMigrationsFromDirectory("{$scriptBaseDir}/DatastoreMigrations");
     //return migrations configuration
     return $migrationConfig;
 }
Example #17
0
 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();
 }
 public static function createMigrationsCommands(ContainerInterface $container) : array
 {
     $config = self::getConfig($container, 'migrations', []);
     $doctrineConfig = new Configuration($container->get(Connection::class));
     $doctrineConfig->setMigrationsNamespace($config['namespace']);
     if (isset($config['path'])) {
         $doctrineConfig->setMigrationsDirectory($config['path']);
         $doctrineConfig->registerMigrationsFromDirectory($config['path']);
     }
     if (isset($config['name'])) {
         $doctrineConfig->setName($config['name']);
     }
     if (isset($config['table_name'])) {
         $doctrineConfig->setMigrationsTableName($config['table_name']);
     }
     $commands = [new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()];
     foreach ($commands as $key => $command) {
         $command->setMigrationConfiguration($doctrineConfig);
         $commands[$key] = $command;
     }
     return $commands;
 }
Example #19
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());
 }
Example #20
0
 public function loadProviders(Application $app)
 {
     //        $app['dump.path'] = $app['root.path'];
     //        $app->register(new \Sorien\Provider\PimpleDumpProvider());
     //        $app->register(new Provider\MonologServiceProvider(), $app['monolog.config']);
     $app->register(new Provider\DoctrineServiceProvider());
     $app->register(new \App\Provider\DoctrineORMServiceProvider());
     $app['migrations.output_writer'] = new OutputWriter(function ($message) {
         $output = new ConsoleOutput();
         $output->writeln($message);
     });
     $app['migrations.configuration'] = function () use($app) {
         $configuration = new Configuration($app['db'], $app['migrations.output_writer']);
         $configuration->setMigrationsDirectory($app['migrations']['directory']);
         $configuration->setName($app['migrations']['name']);
         $configuration->setMigrationsNamespace($app['migrations']['namespace']);
         $configuration->setMigrationsTableName($app['migrations']['table_name']);
         $configuration->registerMigrationsFromDirectory($app['migrations']['directory']);
         return $configuration;
     };
     $app->register(new Provider\ValidatorServiceProvider());
     $app->register(new Provider\ServiceControllerServiceProvider());
 }
 public function register(Container $app)
 {
     if (!isset($app['db'])) {
         throw new \LogicException('You must register the DoctrineServiceProvider to use the DoctrineMigrationsServiceProvider.');
     }
     if (!isset($app['console'])) {
         throw new \LogicException('You must register the ConsoleServiceProvider to use the DoctrineMigrationsServiceProvider.');
     }
     $app['migrations.configuration'] = function () use($app) {
         $options = $app['migrations.options'];
         $config = new Configuration($app['db']);
         $config->setName($options['name']);
         $config->setMigrationsTableName($options['table_name']);
         $config->setMigrationsDirectory($options['directory']);
         $config->setMigrationsNamespace($options['namespace']);
         $config->registerMigrationsFromDirectory($options['directory']);
         return $config;
     };
     $app['console'] = $app->extend('console', function ($console) use($app) {
         $console->getHelperSet()->set(new QuestionHelper());
         $console->add(new ExecuteCommand());
         $console->add(new GenerateCommand());
         $console->add(new MigrateCommand());
         $console->add(new StatusCommand());
         $console->add(new VersionCommand());
         if ($console->getHelperSet()->has('em')) {
             $console->add(new DiffCommand());
         }
         $commands = $console->all('migrations');
         foreach ($commands as $command) {
             $command->setMigrationConfiguration($app['migrations.configuration']);
         }
         return $console;
     });
     $app['migrations.options'] = ['name' => null, 'namespace' => 'DoctrineMigrations', 'table_name' => 'doctrine_migration_versions', 'directory' => null];
 }
$app = new SilexApplication();
$app['debug'] = Environment::get('APP_DEBUG');
$doctrine = (require CONFIG_PATH . DS . 'doctrine.php');
$migrations = (require CONFIG_PATH . DS . 'migrations.php');
$app->register(new DoctrineServiceProvider(), $doctrine['dbal']);
$app->register(new DoctrineOrmServiceProvider(), $doctrine['orm']);
$app->register(new DoctrineExtensionsServiceProvider());
$em = $app['orm.em'];
$helperSet = new HelperSet(array('db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em), 'dialog' => new DialogHelper()));
$cli = new Application('Silex Command Line Interface', Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);
// Doctrine Migration Configuration
$config = new Configuration($em->getConnection());
$config->setMigrationsDirectory($migrations['migrations.directory']);
$config->setName($migrations['migrations.name']);
$config->setMigrationsNamespace($migrations['migrations.namespace']);
$config->setMigrationsTableName($migrations['migrations.table_name']);
$config->registerMigrationsFromDirectory($migrations['migrations.directory']);
$commands = [];
$commands[] = new DiffCommand();
end($commands)->setMigrationConfiguration($config);
$commands[] = new ExecuteCommand();
end($commands)->setMigrationConfiguration($config);
$commands[] = new GenerateCommand();
end($commands)->setMigrationConfiguration($config);
$commands[] = new MigrateCommand();
end($commands)->setMigrationConfiguration($config);
$commands[] = new StatusCommand();
end($commands)->setMigrationConfiguration($config);
$commands[] = new VersionCommand();
 */
use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Helper\HelperSet;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand;
use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand;
require __DIR__ . '/../../../../bootstrap/autoload.php';
$app = (require_once __DIR__ . '/../../../../bootstrap/app.php');
$app->make('Illuminate\\Contracts\\Console\\Kernel')->bootstrap();
$config = $app->make('config');
$em = $app->make('Doctrine\\ORM\\EntityManager');
$helperSet = new HelperSet(array('db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em), 'dialog' => new DialogHelper()));
$migrations_config = new Configuration($em->getConnection());
$migrations_config->setName($config->get('doctrine.migrations.name', 'Doctrine Sandbox Migrations'));
$migrations_config->setMigrationsNamespace($config->get('doctrine.migrations.namespace', 'DoctrineMigrations'));
$migrations_config->setMigrationsTableName($config->get('doctrine.migrations.table_name', 'doctrine_migration_versions'));
$migrations_directory = base_path($config->get('doctrine.migrations.directory', 'database/doctrine-migrations'));
$migrations_config->setMigrationsDirectory($migrations_directory);
$migrations_config->registerMigrationsFromDirectory($migrations_directory);
$commands = array(new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand());
foreach ($commands as $command) {
    $command->setMigrationConfiguration($migrations_config);
}
ConsoleRunner::run($helperSet, $commands);
 public function testSetGetName()
 {
     $config = new Configuration($this->getSqliteConnection());
     $config->setName('Test');
     $this->assertEquals('Test', $config->getName());
 }
Example #25
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;
 }
Example #26
0
 private function getConfiguration(Bundle $bundle)
 {
     if (isset($this->cacheConfigs[$bundle->getName()])) {
         return $this->cacheConfigs[$bundle->getName()];
     }
     $driverName = $this->connection->getDriver()->getName();
     $migrationsDir = "{$bundle->getPath()}/Migrations/{$driverName}";
     $migrationsName = "{$bundle->getName()} migration";
     $migrationsNamespace = "{$bundle->getNamespace()}\\Migrations\\{$driverName}";
     $migrationsTableName = 'doctrine_' . strtolower($bundle->getName()) . '_versions';
     $config = new Configuration($this->connection);
     $config->setName($migrationsName);
     $config->setMigrationsDirectory($migrationsDir);
     $config->setMigrationsNamespace($migrationsNamespace);
     $config->setMigrationsTableName($migrationsTableName);
     if (is_dir($migrationsDir)) {
         $config->registerMigrationsFromDirectory($migrationsDir);
     }
     $this->cacheConfigs[$bundle->getName()] = $config;
     return $config;
 }
 /**
  * Bootstraps the application.
  *
  * This method is called after all services are registered
  * and should be used for "dynamic" configuration (whenever
  * a service must be requested).
  *
  * @param Application $app
  */
 public function boot(Application $app)
 {
     $helperSet = new HelperSet(array('connection' => new ConnectionHelper($app['db']), 'dialog' => new DialogHelper()));
     if (isset($app['orm.em'])) {
         $helperSet->set(new EntityManagerHelper($app['orm.em']), 'em');
     }
     $this->console->setHelperSet($helperSet);
     $commands = array('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\ExecuteCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\GenerateCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\StatusCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\VersionCommand');
     // @codeCoverageIgnoreStart
     if (true === $this->console->getHelperSet()->has('em')) {
         $commands[] = 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\DiffCommand';
     }
     // @codeCoverageIgnoreEnd
     $configuration = new Configuration($app['db'], $app['migrations.output_writer']);
     $configuration->setMigrationsDirectory($app['migrations.directory']);
     $configuration->setName($app['migrations.name']);
     $configuration->setMigrationsNamespace($app['migrations.namespace']);
     $configuration->setMigrationsTableName($app['migrations.table_name']);
     $configuration->registerMigrationsFromDirectory($app['migrations.directory']);
     foreach ($commands as $name) {
         /** @var AbstractCommand $command */
         $command = new $name();
         $command->setMigrationConfiguration($configuration);
         $this->console->add($command);
     }
 }
Example #28
0
 /**
  * Add a new configuration instance to configuration manager
  *
  * @param string $namespace A module name or component name
  * @param \Doctrine\DBAL\Migrations\Configuration\Configuration $configuration
  */
 public function add($namespace, Configuration $configuration)
 {
     $configuration->setMigrationsTableName($this->application->getConfig('migration.tablename', 'migrations'));
     $configuration->setName($namespace);
     $this->configurations[$namespace] = $configuration;
 }
Example #29
0
<?php

$app = (require_once __DIR__ . '/bootstrap.php');
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\DialogHelper;
use Doctrine\DBAL\Migrations\Tools\Console\Command;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Symfony\Component\Console\Application as SymfonyApplication;
$helpers['em'] = new EntityManagerHelper($app['orm.em']);
$helpers['dialog'] = new DialogHelper();
$helperSet = new HelperSet($helpers);
$commands = array(new Command\DiffCommand(), new Command\ExecuteCommand(), new Command\GenerateCommand(), new Command\MigrateCommand(), new Command\StatusCommand(), new Command\VersionCommand());
$application = new SymfonyApplication();
$config = new Configuration($app['db']);
$config->setName('Skel Migration');
$config->setMigrationsDirectory(__DIR__ . '/data/DoctrineMigrations');
$config->setMigrationsNamespace('Application\\Migrations');
$config->setMigrationsTableName('migration_version');
foreach ($commands as $command) {
    if ($command instanceof Command\AbstractCommand) {
        $command->setMigrationConfiguration($config);
    }
    $application->add($command);
}
ConsoleRunner::run($helperSet, $application->all());
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Helper\QuestionHelper;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\DBAL\Migrations\OutputWriter;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
require_once __DIR__ . "/../app/config/bootstrap.php";
$cli = new Application('Doctrine Command Line Interface', \Doctrine\ORM\Version::VERSION);
$helperSet = new HelperSet(array('db' => new ConnectionHelper($entityManager->getConnection()), 'em' => new EntityManagerHelper($entityManager), 'dialog' => new QuestionHelper()));
$cli->setHelperSet($helperSet);
$outputWriter = new OutputWriter(function ($message) {
    $output = new ConsoleOutput();
    $output->writeln($message);
});
$config = new Configuration($entityManager->getConnection(), $outputWriter);
$config->setMigrationsDirectory(__DIR__ . $configuration['migrations']['directory']);
$config->setName($configuration['migrations']['name']);
$config->setMigrationsNamespace($configuration['migrations']['namespace']);
$config->setMigrationsTableName($configuration['migrations']['table_name']);
$config->registerMigrationsFromDirectory(__DIR__ . $configuration['migrations']['directory']);
$commands = array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand());
foreach ($commands as $command) {
    $command->setMigrationConfiguration($config);
    $cli->add($command);
}
ConsoleRunner::addCommands($cli);
$cli->run();