registerMigrationsFromDirectory() 공개 메소드

Register migrations from a given directory. Recursively finds all files with the pattern VersionYYYYMMDDHHMMSS.php as the filename and registers them as migrations.
public registerMigrationsFromDirectory ( string $path ) : Version[]
$path string The root directory to where some migration classes live.
리턴 Doctrine\DBAL\Migrations\Version[] The array of migrations registered.
예제 #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();
     // ...
 }
 public function registerMigrations(ConsoleCommandEvent $event)
 {
     $command = $event->getCommand();
     if (!$this->isMigrationCommand($command)) {
         return;
     }
     $this->configuration->registerMigrationsFromDirectory($this->configuration->getMigrationsDirectory());
 }
 /**
  * {@inheritdoc}
  */
 public function register(Container $c)
 {
     $c['migrations.apps'] = function ($c) {
         $apps = new Container();
         foreach ($c['migrations.options'] as $key => $options) {
             $apps[$key] = function () use($c, $key, $options) {
                 $db = $c['dbs'][$key];
                 return $c['migrations.create_app']($c['migrations.create_helpers']($db), $c['migrations.create_commands']($db, $options));
             };
         }
         return $apps;
     };
     $c['migrations.create_app'] = $c->protect(function ($helpers, $commands) {
         return ConsoleRunner::createApplication($helpers, $commands);
     });
     $c['migrations.create_helpers'] = $c->protect(function ($db) {
         return new HelperSet(['db' => new ConnectionHelper($db), 'dialog' => new QuestionHelper()]);
     });
     $c['migrations.create_commands'] = $c->protect(function ($db, $options) {
         $config = new Configuration($db);
         if (isset($options['namespace'])) {
             $config->setMigrationsNamespace($options['namespace']);
         }
         $config->setMigrationsDirectory($options['path']);
         $config->registerMigrationsFromDirectory($options['path']);
         if (isset($options['table'])) {
             $config->setMigrationsTableName($options['table']);
         }
         $commands = [new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()];
         foreach ($commands as $command) {
             $command->setMigrationConfiguration($config);
         }
         return $commands;
     });
 }
예제 #4
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;
 }
예제 #5
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);
         }
     });
 }
예제 #7
0
 /**
  * @see http://jamesmcfadden.co.uk/database-unit-testing-with-doctrine-2-and-phpunit/
  */
 public function getConnection()
 {
     // 別途 Application を生成しているような箇所があると動作しないので注意
     $app = EccubeTestCase::createApplication();
     // Get an instance of your entity manager
     $entityManager = $app['orm.em'];
     // Retrieve PDO instance
     $pdo = $entityManager->getConnection()->getWrappedConnection();
     // Clear Doctrine to be safe
     $entityManager->clear();
     // Schema Tool to process our entities
     $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
     $classes = $entityManager->getMetaDataFactory()->getAllMetaData();
     // Drop all classes and re-build them for each test case
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     $config = new Configuration($app['db']);
     $config->setMigrationsNamespace('DoctrineMigrations');
     $migrationDir = __DIR__ . '/../../../src/Eccube/Resource/doctrine/migration';
     $config->setMigrationsDirectory($migrationDir);
     $config->registerMigrationsFromDirectory($migrationDir);
     $migration = new Migration($config);
     $migration->migrate(null, false);
     self::$app = $app;
     // Pass to PHPUnit
     return $this->createDefaultDBConnection($pdo, 'db_name');
 }
예제 #8
0
 /**
  * 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)
 {
     if (php_sapi_name() === 'cli') {
         $app['console.commands'] = $app->extend('console.commands', function ($commands) use($app) {
             $migrationCommands = [new Proxy\DiffCommandProxy(), new Proxy\ExecuteCommandProxy(), new Proxy\GenerateCommandProxy(), new Proxy\LatestCommandProxy(), new Proxy\MigrateCommandProxy(), new Proxy\StatusCommandProxy(), new Proxy\VersionCommandProxy()];
             if (isset($app['migrations.directory'])) {
                 $config = new Configuration($app['db']);
                 $config->setMigrationsDirectory($app['migrations.directory']);
                 $config->setMigrationsNamespace('DocMigrations');
                 $config->setMigrationsTableName('doc_migrations');
                 $config->registerMigrationsFromDirectory($app['migrations.directory']);
                 /** @var AbstractCommand $cmd */
                 foreach ($migrationCommands as $cmd) {
                     $cmd->setMigrationConfiguration($config);
                 }
             }
             return array_merge($commands, $migrationCommands, [new Proxy\ClearMetadataCacheDoctrineCommand(), new Proxy\ClearQueryCacheDoctrineCommand(), new Proxy\ClearResultCacheDoctrineCommand(), new Proxy\ConvertMappingDoctrineCommand(), new Proxy\CreateSchemaDoctrineCommand(), new Proxy\DropSchemaDoctrineCommand(), new Proxy\EnsureProductionSettingsDoctrineCommand(), new Proxy\InfoDoctrineCommand(), new Proxy\RunDqlDoctrineCommand(), new Proxy\RunSqlDoctrineCommand(), new Proxy\UpdateSchemaDoctrineCommand(), new Proxy\UpdateSchemaDoctrineCommand(), new Proxy\ValidateSchemaCommand(), new Proxy\GenProxiesDoctrineCommand(), new CreateDatabaseDoctrineCommand(), new DropDatabaseDoctrineCommand()]);
         });
         if (isset($app['console'])) {
             $app['console'] = $app->share($app->extend('console', function (ConsoleApplication $consoleApplication) use($app) {
                 $helperSet = $consoleApplication->getHelperSet();
                 $helperSet->set(new ManagerRegistryHelper($app['doctrine']), 'doctrine');
                 return $consoleApplication;
             }));
         }
     }
 }
예제 #9
0
 /**
  * データベースを初期化する.
  *
  * データベースを初期化し、マイグレーションを行なう.
  * 全てのデータが初期化されるため注意すること.
  *
  * @link http://jamesmcfadden.co.uk/database-unit-testing-with-doctrine-2-and-phpunit/
  */
 public function initializeDatabase()
 {
     // Get an instance of your entity manager
     $entityManager = $this->app['orm.em'];
     // Retrieve PDO instance
     $pdo = $entityManager->getConnection()->getWrappedConnection();
     // Clear Doctrine to be safe
     $entityManager->clear();
     // Schema Tool to process our entities
     $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
     $classes = $entityManager->getMetaDataFactory()->getAllMetaData();
     // Drop all classes and re-build them for each test case
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     $config = new Configuration($this->app['db']);
     $config->setMigrationsNamespace('DoctrineMigrations');
     $migrationDir = __DIR__ . '/../../../src/Eccube/Resource/doctrine/migration';
     $config->setMigrationsDirectory($migrationDir);
     $config->registerMigrationsFromDirectory($migrationDir);
     $migration = new Migration($config);
     $migration->migrate(null, false);
     // 通常は eccube_install.sh で追加されるデータを追加する
     $sql = "INSERT INTO dtb_member (member_id, login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date, create_date,name,department) VALUES (2, 'admin', 'test', 'test', 1, 0, 0, 1, 1, current_timestamp, current_timestamp,'管理者','EC-CUBE SHOP')";
     $stmt = $pdo->prepare($sql);
     $stmt->execute();
     $sql = "INSERT INTO dtb_base_info (id, shop_name, email01, email02, email03, email04, update_date, option_product_tax_rule) VALUES (1, 'SHOP_NAME', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', current_timestamp, 0)";
     $stmt = $pdo->prepare($sql);
     $stmt->execute();
 }
 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');
 }
 public static function create(Connection $connection)
 {
     $directory = __DIR__ . "/../app/migrations";
     $configuration = new Configuration($connection);
     $configuration->setMigrationsNamespace('DoctrineMigrations');
     $configuration->setMigrationsTableName('migrations');
     $configuration->setMigrationsDirectory($directory);
     $configuration->registerMigrationsFromDirectory($directory);
     return $configuration;
 }
예제 #12
0
파일: Migration.php 프로젝트: csbill/csbill
 /**
  * @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;
 }
예제 #13
0
 public function migrationSchema($app, $migrationFilePath, $pluginCode, $version = null)
 {
     $config = new Configuration($app['db']);
     $config->setMigrationsNamespace('DoctrineMigrations');
     $config->setMigrationsDirectory($migrationFilePath);
     $config->registerMigrationsFromDirectory($migrationFilePath);
     $config->setMigrationsTableName(self::MIGRATION_TABLE_PREFIX . $pluginCode);
     $migration = new Migration($config);
     // null 又は 'last' を渡すと最新バージョンまでマイグレートする
     // 0か'first'を渡すと最初に戻る
     $migration->migrate($version, false);
 }
 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']);
 }
예제 #16
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'));
 }
 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());
 }
예제 #18
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');
 }
예제 #19
0
 /**
  * データベースを初期化する.
  *
  * データベースを初期化し、マイグレーションを行なう.
  * 全てのデータが初期化されるため注意すること.
  *
  * @link http://jamesmcfadden.co.uk/database-unit-testing-with-doctrine-2-and-phpunit/
  */
 public function initializeDatabase()
 {
     // Get an instance of your entity manager
     $entityManager = $this->app['orm.em'];
     // Retrieve PDO instance
     $pdo = $entityManager->getConnection()->getWrappedConnection();
     // Clear Doctrine to be safe
     $entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
     $entityManager->clear();
     gc_collect_cycles();
     // Schema Tool to process our entities
     $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
     $classes = $entityManager->getMetaDataFactory()->getAllMetaData();
     // Drop all classes and re-build them for each test case
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     $config = new Configuration($this->app['db']);
     $config->setMigrationsNamespace('DoctrineMigrations');
     $migrationDir = __DIR__ . '/../../../src/Eccube/Resource/doctrine/migration';
     $config->setMigrationsDirectory($migrationDir);
     $config->registerMigrationsFromDirectory($migrationDir);
     $migration = new Migration($config);
     // initialize migrations.sql from bootstrap
     if (!file_exists(sys_get_temp_dir() . '/migrations.sql')) {
         $sql = $migration->migrate(null, false);
         file_put_contents(sys_get_temp_dir() . '/migrations.sql', json_encode($sql));
     } else {
         $migrations = json_decode(file_get_contents(sys_get_temp_dir() . '/migrations.sql'), true);
         foreach ($migrations as $migration_sql) {
             foreach ($migration_sql as $sql) {
                 if ($this->isSqliteInMemory()) {
                     // XXX #1199 の問題を無理矢理回避...
                     $sql = preg_replace('/CURRENT_TIMESTAMP/i', "datetime('now','-9 hours')", $sql);
                 }
                 $stmt = $pdo->prepare($sql);
                 $stmt->execute();
                 $stmt->closeCursor();
             }
         }
     }
     // 通常は eccube_install.sh で追加されるデータを追加する
     $sql = "INSERT INTO dtb_member (member_id, login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date, create_date,name,department) VALUES (2, 'admin', 'test', 'test', 1, 0, 0, 1, 1, current_timestamp, current_timestamp,'管理者','EC-CUBE SHOP')";
     $stmt = $pdo->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $sql = "INSERT INTO dtb_base_info (id, shop_name, email01, email02, email03, email04, update_date, option_product_tax_rule) VALUES (1, 'SHOP_NAME', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', current_timestamp, 0)";
     $stmt = $pdo->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
 }
 /**
  * {@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;
 }
예제 #21
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']]);
 }
 /**
  * {@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;
 }
 /**
  * Constructor
  *
  * @param Application $console Console
  * @param ContainerInterface $container Container DI
  */
 public function __construct(Application $console, ContainerInterface $container)
 {
     $config = $container->get('Config');
     $entityManager = $container->get('EntityManager');
     $migrationConfiguration = new Configuration($entityManager->getConnection());
     $migrationConfiguration->setMigrationsTableName($config->{'doctrine.orm'}->migrations->table);
     $migrationConfiguration->setMigrationsNamespace($config->{'doctrine.orm'}->migrations->namespace);
     $migrationConfiguration->setMigrationsDirectory($config->{'doctrine.orm'}->migrations->directory);
     $migrationConfiguration->registerMigrationsFromDirectory($config->{'doctrine.orm'}->migrations->directory);
     $migrationCommands = ['DiffCommand', 'ExecuteCommand', 'GenerateCommand', 'MigrateCommand', 'StatusCommand', 'VersionCommand'];
     foreach ($migrationCommands as $commandName) {
         /** @var \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand $command */
         $fullCommandName = 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\' . $commandName;
         $command = new $fullCommandName();
         $command->setMigrationConfiguration($migrationConfiguration);
         $console->add($command);
     }
 }
 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;
     });
 }
 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;
 }
예제 #26
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();
 }
예제 #27
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());
 }
예제 #28
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];
 }
예제 #30
0
 private function getMigration()
 {
     $app = new \Eccube\Application();
     $app->initDoctrine();
     $config = new Configuration($app['db']);
     $config->setMigrationsNamespace('DoctrineMigrations');
     $migrationDir = __DIR__ . '/../../Resource/doctrine/migration';
     $config->setMigrationsDirectory($migrationDir);
     $config->registerMigrationsFromDirectory($migrationDir);
     $migration = new Migration($config);
     return $migration;
 }