本文整理匯總了PHP中Doctrine\DBAL\Migrations\Configuration\Configuration::setMigrationsNamespace方法的典型用法代碼示例。如果您正苦於以下問題:PHP Configuration::setMigrationsNamespace方法的具體用法?PHP Configuration::setMigrationsNamespace怎麽用?PHP Configuration::setMigrationsNamespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\DBAL\Migrations\Configuration\Configuration
的用法示例。
在下文中一共展示了Configuration::setMigrationsNamespace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: indexAction
public function indexAction()
{
$container = $this->container;
$conn = $this->get('doctrine')->getConnection();
$dir = $container->getParameter('doctrine_migrations.dir_name');
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$configuration = new Configuration($conn);
$configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace'));
$configuration->setMigrationsDirectory($dir);
$configuration->registerMigrationsFromDirectory($dir);
$configuration->setName($container->getParameter('doctrine_migrations.name'));
$configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
$versions = $configuration->getMigrations();
foreach ($versions as $version) {
$migration = $version->getMigration();
if ($migration instanceof ContainerAwareInterface) {
$migration->setContainer($container);
}
}
$migration = new Migration($configuration);
$migrated = $migration->migrate();
// ...
}
示例2: setUp
public function setUp()
{
$this->connection = $this->getSqliteConnection();
$this->config = new Configuration($this->connection);
$this->config->setMigrationsNamespace('Doctrine\\DBAL\\Migrations\\Tests\\Functional');
$this->config->setMigrationsDirectory('.');
}
示例3: setUp
public function setUp()
{
$params = array('driver' => 'pdo_sqlite', 'memory' => true);
$this->connection = DriverManager::getConnection($params);
$this->config = new Configuration($this->connection);
$this->config->setMigrationsNamespace('Doctrine\DBAL\Migrations\Tests\Functional');
$this->config->setMigrationsDirectory('.');
}
示例4: setUp
public function setUp()
{
$this->command = $this->getMockBuilder('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\VersionCommand')->setConstructorArgs(array('migrations:version'))->setMethods(array('getMigrationConfiguration'))->getMock();
$this->configuration = new Configuration($this->getSqliteConnection());
$this->configuration->setMigrationsNamespace('DoctrineMigrations');
$this->configuration->setMigrationsDirectory(sys_get_temp_dir());
$this->command->expects($this->once())->method('getMigrationConfiguration')->will($this->returnValue($this->configuration));
}
示例5: register
/**
* {@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;
});
}
示例6: generateMigrationSql
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;
}
示例7: preUpdate
/**
* @param Connection $connection
* @param AppKernel $kernel
*/
public function preUpdate(Connection $connection, AppKernel $kernel)
{
/** @var \Symfony\Component\HttpKernel\Bundle\Bundle[] $bundles */
$bundles = $kernel->getBundles();
$isPortfolioBundleInstalled = false;
foreach ($bundles as $bundle) {
if ('IcapPortfolioBundle' === $bundle->getName()) {
$isPortfolioBundleInstalled = true;
}
}
if ($connection->getSchemaManager()->tablesExist(['icap__portfolio_widget_badges'])) {
if ($isPortfolioBundleInstalled) {
$this->log('Found existing database schema: skipping install migration...');
$config = new Configuration($connection);
$config->setMigrationsTableName('doctrine_icapbadgebundle_versions');
$config->setMigrationsNamespace('claro_badge');
// required but useless
$config->setMigrationsDirectory('claro_badge');
// idem
try {
$version = new Version($config, '20150929141509', 'stdClass');
$version->markMigrated();
} catch (\Exception $e) {
$this->log('Already migrated');
}
} else {
$this->log('Deleting badges tables for portfolio...');
$connection->getSchemaManager()->dropTable('icap__portfolio_widget_badges_badge');
$connection->getSchemaManager()->dropTable('icap__portfolio_widget_badges');
$this->log('badges tables for portfolio deleted.');
}
}
}
示例8: testValidateMigrations
public function testValidateMigrations()
{
$config = new Configuration($this->getSqliteConnection());
$config->setMigrationsNamespace("DoctrineMigrations\\");
$config->setMigrationsDirectory(sys_get_temp_dir());
$config->validate();
}
示例9: getConnection
/**
* @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');
}
示例10: boot
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);
}
});
}
示例11: getSqliteConfiguration
/**
* @return Configuration
*/
public function getSqliteConfiguration()
{
$config = new Configuration($this->getSqliteConnection());
$config->setMigrationsDirectory(\sys_get_temp_dir());
$config->setMigrationsNamespace('DoctrineMigrations');
return $config;
}
示例12: migrateBadgeTables
/**
* @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));
}
}
示例13: initializeDatabase
/**
* データベースを初期化する.
*
* データベースを初期化し、マイグレーションを行なう.
* 全てのデータが初期化されるため注意すること.
*
* @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', 'admin@example.com', 'admin@example.com', 'admin@example.com', 'admin@example.com', current_timestamp, 0)";
$stmt = $pdo->prepare($sql);
$stmt->execute();
}
示例14: boot
/**
* 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;
}));
}
}
}
示例15: create
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;
}