private function getMigrationsConfiguration()
 {
     $em = $this->getDoctrine()->getEntityManager();
     $dir = $this->container->getParameter('doctrine_migrations.dir_name');
     $configuration = new \Doctrine\DBAL\Migrations\Configuration\Configuration($em->getConnection());
     $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;
 }
 /**
  * Return the configuration needed for Migrations.
  *
  * @return \Doctrine\DBAL\Migrations\Configuration\Configuration
  */
 protected function getMigrationConfiguration()
 {
     $this->output = array();
     $that = $this;
     $outputWriter = new \Doctrine\DBAL\Migrations\OutputWriter(function ($message) use($that) {
         $that->output[] = $message;
     });
     $connection = $this->entityManager->getConnection();
     $schemaManager = $connection->getSchemaManager();
     if ($schemaManager->tablesExist(array('flow3_doctrine_migrationstatus')) === true) {
         $schemaManager->renameTable('flow3_doctrine_migrationstatus', self::DOCTRINE_MIGRATIONSTABLENAME);
     }
     $configuration = new \Doctrine\DBAL\Migrations\Configuration\Configuration($connection, $outputWriter);
     $configuration->setMigrationsNamespace('TYPO3\\Flow\\Persistence\\Doctrine\\Migrations');
     $configuration->setMigrationsDirectory(\TYPO3\Flow\Utility\Files::concatenatePaths(array(FLOW_PATH_DATA, 'DoctrineMigrations')));
     $configuration->setMigrationsTableName(self::DOCTRINE_MIGRATIONSTABLENAME);
     $configuration->createMigrationTable();
     $databasePlatformName = $this->getDatabasePlatformName();
     foreach ($this->packageManager->getActivePackages() as $package) {
         $path = \TYPO3\Flow\Utility\Files::concatenatePaths(array($package->getPackagePath(), 'Migrations', $databasePlatformName));
         if (is_dir($path)) {
             $configuration->registerMigrationsFromDirectory($path);
         }
     }
     return $configuration;
 }
Beispiel #3
0
 /**
  * Return the configuration needed for Migrations.
  *
  * @return \Doctrine\DBAL\Migrations\Configuration\Configuration
  */
 protected function getMigrationConfiguration()
 {
     $this->output = array();
     $that = $this;
     $outputWriter = new \Doctrine\DBAL\Migrations\OutputWriter(function ($message) use($that) {
         $that->output[] = $message;
     });
     $connection = $this->entityManager->getConnection();
     if ($connection->getSchemaManager()->tablesExist(array('flow3_doctrine_migrationstatus')) === TRUE) {
         // works for SQLite, MySQL, PostgreSQL, Oracle
         // does not work for SQL Server
         $connection->exec('ALTER TABLE flow3_doctrine_migrationstatus RENAME TO flow_doctrine_migrationstatus');
     }
     $configuration = new \Doctrine\DBAL\Migrations\Configuration\Configuration($connection, $outputWriter);
     $configuration->setMigrationsNamespace('TYPO3\\Flow\\Persistence\\Doctrine\\Migrations');
     $configuration->setMigrationsDirectory(\TYPO3\Flow\Utility\Files::concatenatePaths(array(FLOW_PATH_DATA, 'DoctrineMigrations')));
     $configuration->setMigrationsTableName('flow_doctrine_migrationstatus');
     $configuration->createMigrationTable();
     $databasePlatformName = $this->getDatabasePlatformName();
     foreach ($this->packageManager->getActivePackages() as $package) {
         $path = \TYPO3\Flow\Utility\Files::concatenatePaths(array($package->getPackagePath(), 'Migrations', $databasePlatformName));
         if (is_dir($path)) {
             $configuration->registerMigrationsFromDirectory($path);
         }
     }
     return $configuration;
 }
Beispiel #4
0
/**
 * Executes DB changes based in the classes defined in
 * src/Chamilo/CoreBundle/Migrations/Schema/*
 *
 * @param string $chamiloVersion
 * @param EntityManager $manager
 * @throws \Doctrine\DBAL\DBALException
 */
function migrate($chamiloVersion, EntityManager $manager)
{
    $debug = true;
    $connection = $manager->getConnection();
    $config = new \Doctrine\DBAL\Migrations\Configuration\Configuration($connection);
    // Table name that will store migrations log (will be created automatically,
    // default name is: doctrine_migration_versions)
    $config->setMigrationsTableName('version');
    // Namespace of your migration classes, do not forget escape slashes, do not add last slash
    $config->setMigrationsNamespace('Application\\Migrations\\Schema\\V' . $chamiloVersion);
    // Directory where your migrations are located
    $config->setMigrationsDirectory(api_get_path(SYS_PATH) . 'app/Migrations/Schema/V' . $chamiloVersion);
    // Load your migrations
    $config->registerMigrationsFromDirectory($config->getMigrationsDirectory());
    $migration = new \Doctrine\DBAL\Migrations\Migration($config);
    $versions = $config->getMigrations();
    /** @var Doctrine\DBAL\Migrations\Version $migrationItem */
    foreach ($versions as $version) {
        $version->getMigration()->setEntityManager($manager);
    }
    $to = null;
    // Retrieve SQL queries that should be run to migrate you schema to $to version,
    // if $to == null - schema will be migrated to latest version
    $versions = $migration->getSql($to);
    if ($debug) {
        $nl = '<br>';
        foreach ($versions as $version => $queries) {
            echo 'VERSION: ' . $version . $nl;
            echo '----------------------------------------------' . $nl . $nl;
            foreach ($queries as $query) {
                echo $query . $nl;
            }
            echo $nl . $nl;
        }
    }
    try {
        // Execute migration!
        $migration->migrate($to);
        if ($debug) {
            echo 'DONE' . $nl;
        }
    } catch (Exception $ex) {
        if ($debug) {
            echo 'ERROR: ' . $ex->getMessage() . $nl;
        }
    }
}
Beispiel #5
0
function initializeDatabase(\Eccube\Application $app)
{
    // Get an instance of your entity manager
    $entityManager = $app['orm.em'];
    $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
    out('Dropping database schema...', 'info');
    $tool->dropSchema($classes);
    out('Creating database schema...', 'info');
    $tool->createSchema($classes);
    out('Database schema created successfully!', 'success');
    $config = new \Doctrine\DBAL\Migrations\Configuration\Configuration($app['db']);
    $config->setMigrationsNamespace('DoctrineMigrations');
    $migrationDir = __DIR__ . '/src/Eccube/Resource/doctrine/migration';
    $config->setMigrationsDirectory($migrationDir);
    $config->registerMigrationsFromDirectory($migrationDir);
    $migration = new \Doctrine\DBAL\Migrations\Migration($config);
    $migration->migrate();
    out('Database migration successfully!', 'success');
    $login_id = getenv('ADMIN_USER');
    $login_password = getenv('ADMIN_PASS');
    $passwordEncoder = new \Eccube\Security\Core\Encoder\PasswordEncoder($app['config']);
    $salt = \Eccube\Util\Str::random(32);
    $encodedPassword = $passwordEncoder->encodePassword($login_password, $salt);
    out('Creating admin accounts...', 'info');
    $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, :login_id, :admin_pass , :salt , '1', '0', '0', '1', '1', current_timestamp, current_timestamp,'管理者', 'EC-CUBE SHOP');";
    $stmt = $pdo->prepare($sql);
    $stmt->execute(array(':login_id' => $login_id, ':admin_pass' => $encodedPassword, ':salt' => $salt));
    $stmt->closeCursor();
    $shop_name = getenv('SHOP_NAME');
    $admin_mail = getenv('ADMIN_MAIL');
    $sql = "INSERT INTO dtb_base_info (id, shop_name, email01, email02, email03, email04, update_date, option_product_tax_rule) VALUES (1, :shop_name, :admin_mail1, :admin_mail2, :admin_mail3, :admin_mail4, current_timestamp, 0)";
    $stmt = $pdo->prepare($sql);
    $stmt->execute(array(':shop_name' => $shop_name, ':admin_mail1' => $admin_mail, ':admin_mail2' => $admin_mail, ':admin_mail3' => $admin_mail, ':admin_mail4' => $admin_mail));
    $stmt->closeCursor();
}
Beispiel #6
0
 protected function getDoctrineMigrationConfig()
 {
     $config = Registry::getConfig();
     // Doctrine Migration
     $entityManager = Registry::getEntityManager();
     $configuration = new \Doctrine\DBAL\Migrations\Configuration\Configuration($entityManager->getConnection());
     $configuration->setName($config->migration->doctrine->name);
     $configuration->setMigrationsNamespace($config->migration->doctrine->migrations_namespace);
     $configuration->setMigrationsTableName($config->migration->doctrine->table_name);
     $configuration->setMigrationsDirectory($config->migration->doctrine->migrations_directory);
     $configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
     return $configuration;
 }
 /**
  * Get Doctrine Migration Command Line Interface
  * 
  * @return \Symfony\Component\Console\Application
  */
 public function getDoctrineMigrationCli()
 {
     if ($this->cli) {
         return $this->cli;
     }
     $em = \Env::get('em');
     $conn = $em->getConnection();
     $this->cli = new \Symfony\Component\Console\Application('Doctrine Migration Command Line Interface', \Doctrine\Common\Version::VERSION);
     $this->cli->setCatchExceptions(true);
     $helperSet = $this->cli->getHelperSet();
     $helpers = array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($conn), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($this->cx->getDb()->getEntityManager()));
     foreach ($helpers as $name => $helper) {
         $helperSet->set($helper, $name);
     }
     //custom configuration
     $configuration = new \Doctrine\DBAL\Migrations\Configuration\Configuration($conn);
     $configuration->setName('Doctrine Migration');
     $configuration->setMigrationsNamespace('Cx\\Core_Modules\\Update\\Data\\Migrations');
     $configuration->setMigrationsTableName(DBPREFIX . 'migration_versions');
     $configuration->setMigrationsDirectory($this->cx->getCodeBaseCoreModulePath() . '/Update/Data/Migrations');
     $configuration->registerMigrationsFromDirectory($this->cx->getCodeBaseCoreModulePath() . '/Update/Data/Migrations');
     $this->cli->addCommands(array($this->getDoctrineMigrationCommand('\\Cx\\Core_Modules\\Update\\Model\\Entity\\MigrationsDiffDoctrineCommand', $configuration), $this->getDoctrineMigrationCommand('\\Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\ExecuteCommand', $configuration), $this->getDoctrineMigrationCommand('\\Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\GenerateCommand', $configuration), $this->getDoctrineMigrationCommand('\\Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand', $configuration), $this->getDoctrineMigrationCommand('\\Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\StatusCommand', $configuration), $this->getDoctrineMigrationCommand('\\Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\VersionCommand', $configuration)));
     $this->cli->setAutoExit(false);
     return $this->cli;
 }
Beispiel #8
0
$dcConfig->setProxyNamespace('Orm\\Proxies');
$dcConfig->setEntityNamespaces(array('Orm\\Entity'));
$dcConfig->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\StaticPHPDriver(realpath(BASE_PATH . '/library/Orm/Entity')));
// create db connection (use Zend_Db like at bootstrap)
require_once 'Zend/Db.php';
$dbConfig = $cmsConfig['db'];
$dbAdapter = \Zend_Db::factory($dbConfig['adapter'], $dbConfig);
$connectionOptions = array('pdo' => $dbAdapter->getConnection(), 'dbname' => $dbConfig['dbname']);
// create entity manager
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $dcConfig, new Doctrine\Common\EventManager());
// Create OutputWriter
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$migrationOutputWriter = new \Doctrine\DBAL\Migrations\OutputWriter(function ($message) use($output) {
    $output->writeln($message);
});
// create migration commands
$migrationCommands = array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand());
// set config to migration commands
$configuration = new \Doctrine\DBAL\Migrations\Configuration\Configuration($em->getConnection(), $migrationOutputWriter);
$configuration->setMigrationsTableName('migrations');
$configuration->setMigrationsNamespace('Orm\\Migrations');
$configuration->setMigrationsDirectory(BASE_PATH . '/library/Orm/Migrations/');
$configuration->registerMigrationsFromDirectory(BASE_PATH . '/library/Orm/Migrations/');
foreach ($migrationCommands as $command) {
    $command->setMigrationConfiguration($configuration);
}
// Create and run ConsoleRunner
$helperSet = \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($em);
$helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
$cli = \Doctrine\ORM\Tools\Console\ConsoleRunner::createApplication($helperSet, $migrationCommands);
$cli->run(null, $output);
/**
 * Executes DB changes based in the classes defined in
 * src/Chamilo/CoreBundle/Migrations/Schema/*
 *
 * @param string $chamiloVersion
 * @param EntityManager $manager
 * @throws \Doctrine\DBAL\DBALException
 */
function migrate($chamiloVersion, EntityManager $manager)
{
    $debug = true;
    $connection = $manager->getConnection();
    $config = new \Doctrine\DBAL\Migrations\Configuration\Configuration($connection);
    // Table name that will store migrations log (will be created automatically,
    // default name is: doctrine_migration_versions)
    $config->setMigrationsTableName('version');
    // Namespace of your migration classes, do not forget escape slashes, do not add last slash
    $config->setMigrationsNamespace('Application\\Migrations\\Schema\\V' . $chamiloVersion);
    // Directory where your migrations are located
    $config->setMigrationsDirectory(api_get_path(SYS_PATH) . 'app/Migrations/Schema/V' . $chamiloVersion);
    // Load your migrations
    $config->registerMigrationsFromDirectory($config->getMigrationsDirectory());
    $migration = new \Doctrine\DBAL\Migrations\Migration($config);
    $versions = $config->getMigrations();
    /** @var Doctrine\DBAL\Migrations\Version $migrationItem */
    foreach ($versions as $version) {
        $version->getMigration()->setEntityManager($manager);
    }
    $to = null;
    // if $to == null then schema will be migrated to latest version
    echo "<pre>";
    try {
        // Execute migration!
        $migratedSQL = $migration->migrate($to);
        if ($debug) {
            foreach ($migratedSQL as $version => $sqlList) {
                echo "VERSION: {$version}<br>";
                echo "----------------------------------------------<br>";
                foreach ($sqlList as $sql) {
                    echo "<code>{$sql}</code><br>";
                }
            }
            echo "<br>DONE!<br>";
        }
        return true;
    } catch (Exception $ex) {
        if ($debug) {
            echo "ERROR: {$ex->getMessage()}<br>";
            return false;
        }
    }
    echo "</pre>";
    return false;
}
Beispiel #10
0
 /**
  * Return the configuration needed for Migrations.
  *
  * @return \Doctrine\DBAL\Migrations\Configuration\Configuration
  */
 protected function getMigrationConfiguration()
 {
     $this->output = array();
     $that = $this;
     $outputWriter = new \Doctrine\DBAL\Migrations\OutputWriter(function ($message) use($that) {
         $that->output[] = $message;
     });
     $configuration = new \Doctrine\DBAL\Migrations\Configuration\Configuration($this->entityManager->getConnection(), $outputWriter);
     $configuration->setMigrationsNamespace('TYPO3\\FLOW3\\Persistence\\Doctrine\\Migrations');
     $configuration->setMigrationsDirectory(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array(FLOW3_PATH_DATA, 'DoctrineMigrations')));
     $configuration->setMigrationsTableName('flow3_doctrine_migrationstatus');
     $configuration->createMigrationTable();
     $databasePlatformName = $this->getDatabasePlatformName();
     foreach ($this->packageManager->getActivePackages() as $package) {
         $configuration->registerMigrationsFromDirectory(\TYPO3\FLOW3\Utility\Files::concatenatePaths(array($package->getPackagePath(), 'Migrations', $databasePlatformName)));
     }
     return $configuration;
 }
#!/usr/bin/env php
<?php 
use Symfony\Component\Console\Application;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../app/bootstrap.php';
$application = new Application();
// Migrations Commands
$configure = new \Doctrine\DBAL\Migrations\Configuration\Configuration($c['db.eng']);
$configure->setMigrationsNamespace('EngMigration');
$configure->setMigrationsDirectory(DOCROOT . '/database-migration/versions');
$configure->registerMigrationsFromDirectory($configure->getMigrationsDirectory());
$configure->setMigrationsTableName('english_migration_versions');
$symfony_output = new \Symfony\Component\Console\Output\ConsoleOutput();
$symfony_output->setDecorated(true);
$configure->setOutputWriter(new \Doctrine\DBAL\Migrations\OutputWriter(function ($msg) use($symfony_output) {
    $symfony_output->writeln($msg);
}));
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($c['db.eng']), 'dialog' => new \Symfony\Component\Console\Helper\DialogHelper(), 'configuration' => new \Doctrine\DBAL\Migrations\Tools\Console\Helper\ConfigurationHelper($c['db.eng'], $configure)));
$application->setHelperSet($helperSet);
$application->addCommands(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()));
$application->add(new \Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand());
$application->add(new \Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand());
$application->add(new \Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand());
$application->add(new \Doctrine\Bundle\DoctrineBundle\Command\ImportMappingDoctrineCommand());
$application->add(new \Eng\Core\Command\Util\VoiceManager($c));
$application->run();