init without trunk

This commit is contained in:
Kevin Adametz 2020-07-09 12:49:32 +02:00
parent ed24ac4994
commit bb809e7233
14652 changed files with 177862 additions and 94817 deletions

View file

@ -0,0 +1,105 @@
<?php
/*
* This file is part of the Doctrine MigrationsBundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MigrationsBundle\Command;
use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand as BaseCommand;
use Doctrine\DBAL\Migrations\Configuration\AbstractFileConfiguration;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
/**
* Base class for Doctrine console commands to extend from.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
abstract class DoctrineCommand extends BaseCommand
{
public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
{
if (!$configuration->getMigrationsDirectory()) {
$dir = $container->getParameter('doctrine_migrations.dir_name');
if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {
$error = error_get_last();
throw new \ErrorException($error['message']);
}
$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 (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {
$error = error_get_last();
throw new \ErrorException($error['message']);
}
$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 instanceof AbstractFileConfiguration) || !$configuration->getMigrationsTableName()) {
$configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
}
// Migrations is not register from configuration loader
if (!($configuration instanceof AbstractFileConfiguration)) {
$configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
}
$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 InvalidArgumentException('Invalid value for "doctrine_migrations.organize_migrations" parameter.');
}
self::injectContainerToMigrations($container, $configuration->getMigrations());
}
/**
* @param ContainerInterface $container
* @param array $versions
*
* Injects the container to migrations aware of it
*/
private static function injectContainerToMigrations(ContainerInterface $container, array $versions)
{
foreach ($versions as $version) {
$migration = $version->getMigration();
if ($migration instanceof ContainerAwareInterface) {
$migration->setContainer($container);
}
}
}
}

View file

@ -0,0 +1,55 @@
<?php
/*
* This file is part of the Doctrine MigrationsBundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Guilehrme Blanco <guilhermeblanco@hotmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MigrationsBundle\Command\Helper;
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper as BaseDoctrineCommandHelper;
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
/**
* Provides some helper and convenience methods to configure doctrine commands in the context of bundles
* and multiple connections/entity managers.
*
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
*/
abstract class DoctrineCommandHelper extends BaseDoctrineCommandHelper
{
public static function setApplicationHelper(Application $application, InputInterface $input)
{
$container = $application->getKernel()->getContainer();
$doctrine = $container->get('doctrine');
$managerNames = $doctrine->getManagerNames();
if ($input->getOption('db') || empty($managerNames)) {
self::setApplicationConnection($application, $input->getOption('db'));
} else {
self::setApplicationEntityManager($application, $input->getOption('em'));
}
if ($input->getOption('shard')) {
$connection = $application->getHelperSet()->get('db')->getConnection();
if (!$connection instanceof PoolingShardConnection) {
if (empty($managerNames)) {
throw new \LogicException(sprintf("Connection '%s' must implement shards configuration.", $input->getOption('db')));
} else {
throw new \LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $input->getOption('em')));
}
}
$connection->connect($input->getOption('shard'));
}
}
}

View file

@ -0,0 +1,63 @@
<?php
/*
* This file is part of the Doctrine MigrationsBundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MigrationsBundle\Command;
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper;
use Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand;
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use LogicException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Command for generate migration classes by comparing your current database schema
* to your mapping information.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class MigrationsDiffDoctrineCommand extends DiffCommand
{
protected function configure()
{
parent::configure();
$this
->setName('doctrine:migrations:diff')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command.')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
;
}
public function execute(InputInterface $input, OutputInterface $output)
{
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('em'));
if ($input->getOption('shard')) {
$connection = $this->getApplication()->getHelperSet()->get('db')->getConnection();
if (!$connection instanceof PoolingShardConnection) {
throw new LogicException(sprintf("Connection of EntityManager '%s' must implements shards configuration.", $input->getOption('em')));
}
$connection->connect($input->getOption('shard'));
}
$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
return parent::execute($input, $output);
}
}

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Doctrine MigrationsBundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MigrationsBundle\Command;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand;
/**
* Command for executing single migrations up or down manually.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class MigrationsExecuteDoctrineCommand extends ExecuteCommand
{
protected function configure()
{
parent::configure();
$this
->setName('doctrine:migrations:execute')
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
;
}
public function execute(InputInterface $input, OutputInterface $output)
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
return parent::execute($input, $output);
}
}

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Doctrine MigrationsBundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MigrationsBundle\Command;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand;
/**
* Command for generating new blank migration classes
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class MigrationsGenerateDoctrineCommand extends GenerateCommand
{
protected function configure()
{
parent::configure();
$this
->setName('doctrine:migrations:generate')
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
;
}
public function execute(InputInterface $input, OutputInterface $output)
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
return parent::execute($input, $output);
}
}

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Doctrine MigrationsBundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MigrationsBundle\Command;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand;
/**
* Command for outputting the latest version number.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class MigrationsLatestDoctrineCommand extends LatestCommand
{
protected function configure()
{
parent::configure();
$this
->setName('doctrine:migrations:latest')
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
;
}
public function execute(InputInterface $input, OutputInterface $output)
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
return parent::execute($input, $output);
}
}

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Doctrine MigrationsBundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MigrationsBundle\Command;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand;
/**
* Command for executing a migration to a specified version or the latest available version.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class MigrationsMigrateDoctrineCommand extends MigrateCommand
{
protected function configure()
{
parent::configure();
$this
->setName('doctrine:migrations:migrate')
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
;
}
public function execute(InputInterface $input, OutputInterface $output)
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
return parent::execute($input, $output);
}
}

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Doctrine MigrationsBundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MigrationsBundle\Command;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand;
/**
* Command to view the status of a set of migrations.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class MigrationsStatusDoctrineCommand extends StatusCommand
{
protected function configure()
{
parent::configure();
$this
->setName('doctrine:migrations:status')
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
;
}
public function execute(InputInterface $input, OutputInterface $output)
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
return parent::execute($input, $output);
}
}

View file

@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Doctrine MigrationsBundle
*
* The code was originally distributed inside the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (c) Doctrine Project, Benjamin Eberlei <kontakt@beberlei.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Doctrine\Bundle\MigrationsBundle\Command;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand;
/**
* Command for manually adding and deleting migration versions from the version table.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
*/
class MigrationsVersionDoctrineCommand extends VersionCommand
{
protected function configure()
{
parent::configure();
$this
->setName('doctrine:migrations:version')
->addOption('db', null, InputOption::VALUE_REQUIRED, 'The database connection to use for this command.')
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
;
}
public function execute(InputInterface $input, OutputInterface $output)
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);
$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
return parent::execute($input, $output);
}
}