Merge pull request #6655 from OskarStark/symfony-style
Use SymfonyStyle for command output
This commit is contained in:
commit
b47a39be64
@ -19,13 +19,14 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
|
||||
|
||||
use Doctrine\ORM\Cache;
|
||||
use Doctrine\ORM\Cache\Region\DefaultRegion;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\ORM\Cache\Region\DefaultRegion;
|
||||
use Doctrine\ORM\Cache;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to clear a collection cache region.
|
||||
@ -40,17 +41,14 @@ class CollectionRegionCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:clear-cache:region:collection')
|
||||
->setDescription('Clear a second-level cache collection region.')
|
||||
$this->setName('orm:clear-cache:region:collection')
|
||||
->setDescription('Clear a second-level cache collection region')
|
||||
->addArgument('owner-class', InputArgument::OPTIONAL, 'The owner entity name.')
|
||||
->addArgument('association', InputArgument::OPTIONAL, 'The association collection name.')
|
||||
->addArgument('owner-id', InputArgument::OPTIONAL, 'The owner identifier.')
|
||||
->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all entity regions will be deleted/invalidated.')
|
||||
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.');
|
||||
|
||||
|
||||
$this->setHelp(<<<EOT
|
||||
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.')
|
||||
->setHelp(<<<EOT
|
||||
The <info>%command.name%</info> command is meant to clear a second-level cache collection regions for an associated Entity Manager.
|
||||
It is possible to delete/invalidate all collection region, a specific collection region or flushes the cache provider.
|
||||
|
||||
@ -82,6 +80,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
$ownerClass = $input->getArgument('owner-class');
|
||||
$assoc = $input->getArgument('association');
|
||||
@ -92,7 +92,7 @@ EOT
|
||||
throw new \InvalidArgumentException('No second-level cache is configured on the given EntityManager.');
|
||||
}
|
||||
|
||||
if ( (! $ownerClass || ! $assoc) && ! $input->getOption('all')) {
|
||||
if (( ! $ownerClass || ! $assoc) && ! $input->getOption('all')) {
|
||||
throw new \InvalidArgumentException('Missing arguments "--owner-class" "--association"');
|
||||
}
|
||||
|
||||
@ -108,13 +108,19 @@ EOT
|
||||
|
||||
$collectionRegion->getCache()->flushAll();
|
||||
|
||||
$output->writeln(sprintf('Flushing cache provider configured for <info>"%s#%s"</info>', $ownerClass, $assoc));
|
||||
$ui->comment(
|
||||
sprintf(
|
||||
'Flushing cache provider configured for <info>"%s#%s"</info>',
|
||||
$ownerClass,
|
||||
$assoc
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($input->getOption('all')) {
|
||||
$output->writeln('Clearing <info>all</info> second-level cache collection regions');
|
||||
$ui->comment('Clearing <info>all</info> second-level cache collection regions');
|
||||
|
||||
$cache->evictEntityRegions();
|
||||
|
||||
@ -122,13 +128,20 @@ EOT
|
||||
}
|
||||
|
||||
if ($ownerId) {
|
||||
$output->writeln(sprintf('Clearing second-level cache entry for collection <info>"%s#%s"</info> owner entity identified by <info>"%s"</info>', $ownerClass, $assoc, $ownerId));
|
||||
$ui->comment(
|
||||
sprintf(
|
||||
'Clearing second-level cache entry for collection <info>"%s#%s"</info> owner entity identified by <info>"%s"</info>',
|
||||
$ownerClass,
|
||||
$assoc,
|
||||
$ownerId
|
||||
)
|
||||
);
|
||||
$cache->evictCollection($ownerClass, $assoc, $ownerId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf('Clearing second-level cache for collection <info>"%s#%s"</info>', $ownerClass, $assoc));
|
||||
$ui->comment(sprintf('Clearing second-level cache for collection <info>"%s#%s"</info>', $ownerClass, $assoc));
|
||||
$cache->evictCollectionRegion($ownerClass, $assoc);
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,14 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
|
||||
|
||||
use Doctrine\ORM\Cache;
|
||||
use Doctrine\ORM\Cache\Region\DefaultRegion;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\ORM\Cache\Region\DefaultRegion;
|
||||
use Doctrine\ORM\Cache;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to clear a entity cache region.
|
||||
@ -40,16 +41,13 @@ class EntityRegionCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:clear-cache:region:entity')
|
||||
->setDescription('Clear a second-level cache entity region.')
|
||||
$this->setName('orm:clear-cache:region:entity')
|
||||
->setDescription('Clear a second-level cache entity region')
|
||||
->addArgument('entity-class', InputArgument::OPTIONAL, 'The entity name.')
|
||||
->addArgument('entity-id', InputArgument::OPTIONAL, 'The entity identifier.')
|
||||
->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all entity regions will be deleted/invalidated.')
|
||||
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.');
|
||||
|
||||
|
||||
$this->setHelp(<<<EOT
|
||||
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.')
|
||||
->setHelp(<<<EOT
|
||||
The <info>%command.name%</info> command is meant to clear a second-level cache entity region for an associated Entity Manager.
|
||||
It is possible to delete/invalidate all entity region, a specific entity region or flushes the cache provider.
|
||||
|
||||
@ -81,6 +79,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
$entityClass = $input->getArgument('entity-class');
|
||||
$entityId = $input->getArgument('entity-id');
|
||||
@ -106,13 +106,13 @@ EOT
|
||||
|
||||
$entityRegion->getCache()->flushAll();
|
||||
|
||||
$output->writeln(sprintf('Flushing cache provider configured for entity named <info>"%s"</info>', $entityClass));
|
||||
$ui->comment(sprintf('Flushing cache provider configured for entity named <info>"%s"</info>', $entityClass));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($input->getOption('all')) {
|
||||
$output->writeln('Clearing <info>all</info> second-level cache entity regions');
|
||||
$ui->comment('Clearing <info>all</info> second-level cache entity regions');
|
||||
|
||||
$cache->evictEntityRegions();
|
||||
|
||||
@ -120,13 +120,19 @@ EOT
|
||||
}
|
||||
|
||||
if ($entityId) {
|
||||
$output->writeln(sprintf('Clearing second-level cache entry for entity <info>"%s"</info> identified by <info>"%s"</info>', $entityClass, $entityId));
|
||||
$ui->comment(
|
||||
sprintf(
|
||||
'Clearing second-level cache entry for entity <info>"%s"</info> identified by <info>"%s"</info>',
|
||||
$entityClass,
|
||||
$entityId
|
||||
)
|
||||
);
|
||||
$cache->evictEntity($entityClass, $entityId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf('Clearing second-level cache for entity <info>"%s"</info>', $entityClass));
|
||||
$ui->comment(sprintf('Clearing second-level cache for entity <info>"%s"</info>', $entityClass));
|
||||
$cache->evictEntityRegion($entityClass);
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,13 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\Common\Cache\ApcCache;
|
||||
use Doctrine\Common\Cache\XcacheCache;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to clear the metadata cache of the various cache drivers.
|
||||
@ -43,19 +44,10 @@ class MetadataCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:clear-cache:metadata')
|
||||
->setDescription('Clear all metadata cache of the various cache drivers.')
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'flush', null, InputOption::VALUE_NONE,
|
||||
'If defined, cache entries will be flushed instead of deleted/invalidated.'
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->setHelp(<<<EOT
|
||||
$this->setName('orm:clear-cache:metadata')
|
||||
->setDescription('Clear all metadata cache of the various cache drivers')
|
||||
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
|
||||
->setHelp(<<<EOT
|
||||
The <info>%command.name%</info> command is meant to clear the metadata cache of associated Entity Manager.
|
||||
It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider
|
||||
instance completely.
|
||||
@ -80,6 +72,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
$cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();
|
||||
|
||||
@ -95,8 +89,7 @@ EOT
|
||||
throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
|
||||
}
|
||||
|
||||
|
||||
$output->writeln('Clearing ALL Metadata cache entries');
|
||||
$ui->comment('Clearing <info>all</info> Metadata cache entries');
|
||||
|
||||
$result = $cacheDriver->deleteAll();
|
||||
$message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
|
||||
@ -106,6 +99,14 @@ EOT
|
||||
$message = ($result) ? 'Successfully flushed cache entries.' : $message;
|
||||
}
|
||||
|
||||
$output->writeln($message);
|
||||
if ( ! $result) {
|
||||
$ui->error($message);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$ui->success($message);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,13 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\Common\Cache\ApcCache;
|
||||
use Doctrine\Common\Cache\XcacheCache;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to clear the query cache of the various cache drivers.
|
||||
@ -43,19 +44,10 @@ class QueryCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:clear-cache:query')
|
||||
->setDescription('Clear all query cache of the various cache drivers.')
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'flush', null, InputOption::VALUE_NONE,
|
||||
'If defined, cache entries will be flushed instead of deleted/invalidated.'
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->setHelp(<<<EOT
|
||||
$this->setName('orm:clear-cache:query')
|
||||
->setDescription('Clear all query cache of the various cache drivers')
|
||||
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
|
||||
->setHelp(<<<EOT
|
||||
The <info>%command.name%</info> command is meant to clear the query cache of associated Entity Manager.
|
||||
It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider
|
||||
instance completely.
|
||||
@ -80,6 +72,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
$cacheDriver = $em->getConfiguration()->getQueryCacheImpl();
|
||||
|
||||
@ -94,7 +88,7 @@ EOT
|
||||
throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
|
||||
}
|
||||
|
||||
$output->write('Clearing ALL Query cache entries' . PHP_EOL);
|
||||
$ui->comment('Clearing <info>all</info> Query cache entries');
|
||||
|
||||
$result = $cacheDriver->deleteAll();
|
||||
$message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
|
||||
@ -104,6 +98,14 @@ EOT
|
||||
$message = ($result) ? 'Successfully flushed cache entries.' : $message;
|
||||
}
|
||||
|
||||
$output->write($message . PHP_EOL);
|
||||
if ( ! $result) {
|
||||
$ui->error($message);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$ui->success($message);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,14 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
|
||||
|
||||
use Doctrine\ORM\Cache;
|
||||
use Doctrine\ORM\Cache\Region\DefaultRegion;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\ORM\Cache\Region\DefaultRegion;
|
||||
use Doctrine\ORM\Cache;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to clear a query cache region.
|
||||
@ -40,15 +41,12 @@ class QueryRegionCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:clear-cache:region:query')
|
||||
->setDescription('Clear a second-level cache query region.')
|
||||
$this->setName('orm:clear-cache:region:query')
|
||||
->setDescription('Clear a second-level cache query region')
|
||||
->addArgument('region-name', InputArgument::OPTIONAL, 'The query region to clear.')
|
||||
->addOption('all', null, InputOption::VALUE_NONE, 'If defined, all query regions will be deleted/invalidated.')
|
||||
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.');
|
||||
|
||||
|
||||
$this->setHelp(<<<EOT
|
||||
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, all cache entries will be flushed.')
|
||||
->setHelp(<<<EOT
|
||||
The <info>%command.name%</info> command is meant to clear a second-level cache query region for an associated Entity Manager.
|
||||
It is possible to delete/invalidate all query region, a specific query region or flushes the cache provider.
|
||||
|
||||
@ -80,6 +78,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
$name = $input->getArgument('region-name');
|
||||
$cache = $em->getCache();
|
||||
@ -105,20 +105,25 @@ EOT
|
||||
|
||||
$queryRegion->getCache()->flushAll();
|
||||
|
||||
$output->writeln(sprintf('Flushing cache provider configured for second-level cache query region named <info>"%s"</info>', $name));
|
||||
$ui->comment(
|
||||
sprintf(
|
||||
'Flushing cache provider configured for second-level cache query region named <info>"%s"</info>',
|
||||
$name
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($input->getOption('all')) {
|
||||
$output->writeln('Clearing <info>all</info> second-level cache query regions');
|
||||
$ui->comment('Clearing <info>all</info> second-level cache query regions');
|
||||
|
||||
$cache->evictQueryRegions();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf('Clearing second-level cache query region named <info>"%s"</info>', $name));
|
||||
$ui->comment(sprintf('Clearing second-level cache query region named <info>"%s"</info>', $name));
|
||||
$cache->evictQueryRegion($name);
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,13 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command\ClearCache;
|
||||
|
||||
use Doctrine\Common\Cache\ApcCache;
|
||||
use Doctrine\Common\Cache\XcacheCache;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\Common\Cache\ApcCache;
|
||||
use Doctrine\Common\Cache\XcacheCache;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to clear the result cache of the various cache drivers.
|
||||
@ -43,19 +44,10 @@ class ResultCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:clear-cache:result')
|
||||
->setDescription('Clear all result cache of the various cache drivers.')
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'flush', null, InputOption::VALUE_NONE,
|
||||
'If defined, cache entries will be flushed instead of deleted/invalidated.'
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->setHelp(<<<EOT
|
||||
$this->setName('orm:clear-cache:result')
|
||||
->setDescription('Clear all result cache of the various cache drivers')
|
||||
->addOption('flush', null, InputOption::VALUE_NONE, 'If defined, cache entries will be flushed instead of deleted/invalidated.')
|
||||
->setHelp(<<<EOT
|
||||
The <info>%command.name%</info> command is meant to clear the result cache of associated Entity Manager.
|
||||
It is possible to invalidate all cache entries at once - called delete -, or flushes the cache provider
|
||||
instance completely.
|
||||
@ -80,6 +72,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
$cacheDriver = $em->getConfiguration()->getResultCacheImpl();
|
||||
|
||||
@ -95,7 +89,7 @@ EOT
|
||||
throw new \LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI.");
|
||||
}
|
||||
|
||||
$output->writeln('Clearing ALL Result cache entries');
|
||||
$ui->comment('Clearing <info>all</info> Result cache entries');
|
||||
|
||||
$result = $cacheDriver->deleteAll();
|
||||
$message = ($result) ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.';
|
||||
@ -105,6 +99,14 @@ EOT
|
||||
$message = ($result) ? 'Successfully flushed cache entries.' : $message;
|
||||
}
|
||||
|
||||
$output->writeln($message);
|
||||
if ( ! $result) {
|
||||
$ui->error($message);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$ui->success($message);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,14 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
|
||||
use Doctrine\ORM\Tools\ConvertDoctrine1Schema;
|
||||
use Doctrine\ORM\Tools\EntityGenerator;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Command to convert a Doctrine 1 schema to a Doctrine 2 mapping file.
|
||||
@ -99,41 +99,16 @@ class ConvertDoctrine1SchemaCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:convert-d1-schema')
|
||||
$this->setName('orm:convert-d1-schema')
|
||||
->setAliases(['orm:convert:d1-schema'])
|
||||
->setDescription('Converts Doctrine 1.X schema into a Doctrine 2.X schema.')
|
||||
->setDefinition(
|
||||
[
|
||||
new InputArgument(
|
||||
'from-path', InputArgument::REQUIRED, 'The path of Doctrine 1.X schema information.'
|
||||
),
|
||||
new InputArgument(
|
||||
'to-type', InputArgument::REQUIRED, 'The destination Doctrine 2.X mapping type.'
|
||||
),
|
||||
new InputArgument(
|
||||
'dest-path', InputArgument::REQUIRED,
|
||||
'The path to generate your Doctrine 2.X mapping information.'
|
||||
),
|
||||
new InputOption(
|
||||
'from', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'Optional paths of Doctrine 1.X schema information.',
|
||||
[]
|
||||
),
|
||||
new InputOption(
|
||||
'extend', null, InputOption::VALUE_OPTIONAL,
|
||||
'Defines a base class to be extended by generated entity classes.'
|
||||
),
|
||||
new InputOption(
|
||||
'num-spaces', null, InputOption::VALUE_OPTIONAL,
|
||||
'Defines the number of indentation spaces', 4
|
||||
)
|
||||
]
|
||||
)
|
||||
->setHelp(<<<EOT
|
||||
Converts Doctrine 1.X schema into a Doctrine 2.X schema.
|
||||
EOT
|
||||
);
|
||||
->setDescription('Converts Doctrine 1.x schema into a Doctrine 2.x schema')
|
||||
->addArgument('from-path', InputArgument::REQUIRED, 'The path of Doctrine 1.X schema information.')
|
||||
->addArgument('to-type', InputArgument::REQUIRED, 'The destination Doctrine 2.X mapping type.')
|
||||
->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your Doctrine 2.X mapping information.')
|
||||
->addOption('from', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Optional paths of Doctrine 1.X schema information.', [])
|
||||
->addOption('extend', null, InputOption::VALUE_OPTIONAL, 'Defines a base class to be extended by generated entity classes.')
|
||||
->addOption('num-spaces', null, InputOption::VALUE_OPTIONAL, 'Defines the number of indentation spaces', 4)
|
||||
->setHelp('Converts Doctrine 1.x schema into a Doctrine 2.x schema.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,16 +19,17 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\ORM\Tools\Console\MetadataFilter;
|
||||
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
|
||||
use Doctrine\ORM\Tools\EntityGenerator;
|
||||
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
|
||||
use Doctrine\ORM\Mapping\Driver\DatabaseDriver;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Doctrine\ORM\Tools\Console\MetadataFilter;
|
||||
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
|
||||
use Doctrine\ORM\Tools\EntityGenerator;
|
||||
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to convert your mapping information between the various formats.
|
||||
@ -47,44 +48,17 @@ class ConvertMappingCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:convert-mapping')
|
||||
$this->setName('orm:convert-mapping')
|
||||
->setAliases(['orm:convert:mapping'])
|
||||
->setDescription('Convert mapping information between supported formats.')
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'A string pattern used to match entities that should be processed.'
|
||||
),
|
||||
new InputArgument(
|
||||
'to-type', InputArgument::REQUIRED, 'The mapping type to be converted.'
|
||||
),
|
||||
new InputArgument(
|
||||
'dest-path', InputArgument::REQUIRED,
|
||||
'The path to generate your entities classes.'
|
||||
),
|
||||
new InputOption(
|
||||
'force', 'f', InputOption::VALUE_NONE,
|
||||
'Force to overwrite existing mapping files.'
|
||||
),
|
||||
new InputOption(
|
||||
'from-database', null, null, 'Whether or not to convert mapping information from existing database.'
|
||||
),
|
||||
new InputOption(
|
||||
'extend', null, InputOption::VALUE_OPTIONAL,
|
||||
'Defines a base class to be extended by generated entity classes.'
|
||||
),
|
||||
new InputOption(
|
||||
'num-spaces', null, InputOption::VALUE_OPTIONAL,
|
||||
'Defines the number of indentation spaces', 4
|
||||
),
|
||||
new InputOption(
|
||||
'namespace', null, InputOption::VALUE_OPTIONAL,
|
||||
'Defines a namespace for the generated entity classes, if converted from database.'
|
||||
),
|
||||
]
|
||||
)
|
||||
->setDescription('Convert mapping information between supported formats')
|
||||
->addArgument('to-type', InputArgument::REQUIRED, 'The mapping type to be converted.')
|
||||
->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your entities classes.')
|
||||
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.')
|
||||
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force to overwrite existing mapping files.')
|
||||
->addOption('from-database', null, null, 'Whether or not to convert mapping information from existing database.')
|
||||
->addOption('extend', null, InputOption::VALUE_OPTIONAL, 'Defines a base class to be extended by generated entity classes.')
|
||||
->addOption('num-spaces', null, InputOption::VALUE_OPTIONAL, 'Defines the number of indentation spaces', 4)
|
||||
->addOption('namespace', null, InputOption::VALUE_OPTIONAL, 'Defines a namespace for the generated entity classes, if converted from database.')
|
||||
->setHelp(<<<EOT
|
||||
Convert mapping information between supported formats.
|
||||
|
||||
@ -116,6 +90,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
if ($input->getOption('from-database') === true) {
|
||||
@ -171,20 +147,26 @@ EOT
|
||||
}
|
||||
}
|
||||
|
||||
if (count($metadata)) {
|
||||
if (empty($metadata)) {
|
||||
$ui->success('No Metadata Classes to process.');
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($metadata as $class) {
|
||||
$output->writeln(sprintf('Processing entity "<info>%s</info>"', $class->name));
|
||||
$ui->text(sprintf('Processing entity "<info>%s</info>"', $class->name));
|
||||
}
|
||||
|
||||
$exporter->setMetadata($metadata);
|
||||
$exporter->export();
|
||||
|
||||
$output->writeln(PHP_EOL . sprintf(
|
||||
'Exporting "<info>%s</info>" mapping information to "<info>%s</info>"', $toType, $destPath
|
||||
));
|
||||
} else {
|
||||
$output->writeln('No Metadata Classes to process.');
|
||||
}
|
||||
$ui->newLine();
|
||||
$ui->text(
|
||||
sprintf(
|
||||
'Exporting "<info>%s</info>" mapping information to "<info>%s</info>"',
|
||||
$toType,
|
||||
$destPath
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,9 +20,10 @@
|
||||
namespace Doctrine\ORM\Tools\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
@ -43,21 +44,10 @@ class EnsureProductionSettingsCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:ensure-production-settings')
|
||||
->setDescription('Verify that Doctrine is properly configured for a production environment.')
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'complete', null, InputOption::VALUE_NONE,
|
||||
'Flag to also inspect database connection existence.'
|
||||
)
|
||||
]
|
||||
)
|
||||
->setHelp(<<<EOT
|
||||
Verify that Doctrine is properly configured for a production environment.
|
||||
EOT
|
||||
);
|
||||
$this->setName('orm:ensure-production-settings')
|
||||
->setDescription('Verify that Doctrine is properly configured for a production environment')
|
||||
->addOption('complete', null, InputOption::VALUE_NONE, 'Flag to also inspect database connection existence.')
|
||||
->setHelp('Verify that Doctrine is properly configured for a production environment.');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,6 +55,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
try {
|
||||
@ -74,11 +66,13 @@ EOT
|
||||
$em->getConnection()->connect();
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$output->writeln('<error>' . $e->getMessage() . '</error>');
|
||||
$ui->error($e->getMessage());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('<info>Environment is correctly configured for production.</info>');
|
||||
$ui->success('Environment is correctly configured for production.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,15 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\ORM\Tools\Console\MetadataFilter;
|
||||
use Doctrine\ORM\Tools\EntityGenerator;
|
||||
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Doctrine\ORM\Tools\EntityGenerator;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to generate entity classes and method stubs from your mapping information.
|
||||
@ -45,49 +46,18 @@ class GenerateEntitiesCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:generate-entities')
|
||||
$this->setName('orm:generate-entities')
|
||||
->setAliases(['orm:generate:entities'])
|
||||
->setDescription('Generate entity classes and method stubs from your mapping information.')
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'A string pattern used to match entities that should be processed.'
|
||||
),
|
||||
new InputArgument(
|
||||
'dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.'
|
||||
),
|
||||
new InputOption(
|
||||
'generate-annotations', null, InputOption::VALUE_OPTIONAL,
|
||||
'Flag to define if generator should generate annotation metadata on entities.', false
|
||||
),
|
||||
new InputOption(
|
||||
'generate-methods', null, InputOption::VALUE_OPTIONAL,
|
||||
'Flag to define if generator should generate stub methods on entities.', true
|
||||
),
|
||||
new InputOption(
|
||||
'regenerate-entities', null, InputOption::VALUE_OPTIONAL,
|
||||
'Flag to define if generator should regenerate entity if it exists.', false
|
||||
),
|
||||
new InputOption(
|
||||
'update-entities', null, InputOption::VALUE_OPTIONAL,
|
||||
'Flag to define if generator should only update entity if it exists.', true
|
||||
),
|
||||
new InputOption(
|
||||
'extend', null, InputOption::VALUE_REQUIRED,
|
||||
'Defines a base class to be extended by generated entity classes.'
|
||||
),
|
||||
new InputOption(
|
||||
'num-spaces', null, InputOption::VALUE_REQUIRED,
|
||||
'Defines the number of indentation spaces', 4
|
||||
),
|
||||
new InputOption(
|
||||
'no-backup', null, InputOption::VALUE_NONE,
|
||||
'Flag to define if generator should avoid backuping existing entity file if it exists.'
|
||||
)
|
||||
]
|
||||
)
|
||||
->setDescription('Generate entity classes and method stubs from your mapping information')
|
||||
->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your entity classes.')
|
||||
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.')
|
||||
->addOption('generate-annotations', null, InputOption::VALUE_OPTIONAL, 'Flag to define if generator should generate annotation metadata on entities.', false)
|
||||
->addOption('generate-methods', null, InputOption::VALUE_OPTIONAL, 'Flag to define if generator should generate stub methods on entities.', true)
|
||||
->addOption('regenerate-entities', null, InputOption::VALUE_OPTIONAL, 'Flag to define if generator should regenerate entity if it exists.', false)
|
||||
->addOption('update-entities', null, InputOption::VALUE_OPTIONAL, 'Flag to define if generator should only update entity if it exists.', true)
|
||||
->addOption('extend', null, InputOption::VALUE_REQUIRED, 'Defines a base class to be extended by generated entity classes.')
|
||||
->addOption('num-spaces', null, InputOption::VALUE_REQUIRED, 'Defines the number of indentation spaces', 4)
|
||||
->addOption('no-backup', null, InputOption::VALUE_NONE, 'Flag to define if generator should avoid backuping existing entity file if it exists.')
|
||||
->setHelp(<<<EOT
|
||||
Generate entity classes and method stubs from your mapping information.
|
||||
|
||||
@ -116,6 +86,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
$cmf = new DisconnectedClassMetadataFactory();
|
||||
@ -138,8 +110,11 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
if (count($metadatas)) {
|
||||
// Create EntityGenerator
|
||||
if (empty($metadatas)) {
|
||||
$ui->success('No Metadata Classes to process.');
|
||||
return;
|
||||
}
|
||||
|
||||
$entityGenerator = new EntityGenerator();
|
||||
|
||||
$entityGenerator->setGenerateAnnotations($input->getOption('generate-annotations'));
|
||||
@ -154,18 +129,14 @@ EOT
|
||||
}
|
||||
|
||||
foreach ($metadatas as $metadata) {
|
||||
$output->writeln(
|
||||
sprintf('Processing entity "<info>%s</info>"', $metadata->name)
|
||||
);
|
||||
$ui->text(sprintf('Processing entity "<info>%s</info>"', $metadata->name));
|
||||
}
|
||||
|
||||
// Generating Entities
|
||||
$entityGenerator->generate($metadatas, $destPath);
|
||||
|
||||
// Outputting information message
|
||||
$output->writeln(PHP_EOL . sprintf('Entity classes generated to "<info>%s</INFO>"', $destPath));
|
||||
} else {
|
||||
$output->writeln('No Metadata Classes to process.');
|
||||
}
|
||||
$ui->newLine();
|
||||
$ui->success(sprintf('Entity classes generated to "%s"', $destPath));
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,14 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Tools\Console\MetadataFilter;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to (re)generate the proxy classes used by doctrine.
|
||||
@ -43,26 +45,12 @@ class GenerateProxiesCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:generate-proxies')
|
||||
$this->setName('orm:generate-proxies')
|
||||
->setAliases(['orm:generate:proxies'])
|
||||
->setDescription('Generates proxy classes for entity classes.')
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'A string pattern used to match entities that should be processed.'
|
||||
),
|
||||
new InputArgument(
|
||||
'dest-path', InputArgument::OPTIONAL,
|
||||
'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.'
|
||||
),
|
||||
]
|
||||
)
|
||||
->setHelp(<<<EOT
|
||||
Generates proxy classes for entity classes.
|
||||
EOT
|
||||
);
|
||||
->setDescription('Generates proxy classes for entity classes')
|
||||
->addArgument('dest-path', InputArgument::OPTIONAL, 'The path to generate your proxy classes. If none is provided, it will attempt to grab from configuration.')
|
||||
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.')
|
||||
->setHelp('Generates proxy classes for entity classes.');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,6 +58,9 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
/** @var EntityManagerInterface $em */
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
$metadatas = $em->getMetadataFactory()->getAllMetadata();
|
||||
@ -98,20 +89,20 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
if ( count($metadatas)) {
|
||||
if (empty($metadatas)) {
|
||||
$ui->success('No Metadata Classes to process.');
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($metadatas as $metadata) {
|
||||
$output->writeln(
|
||||
sprintf('Processing entity "<info>%s</info>"', $metadata->name)
|
||||
);
|
||||
$ui->text(sprintf('Processing entity "<info>%s</info>"', $metadata->name));
|
||||
}
|
||||
|
||||
// Generating Proxies
|
||||
$em->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
|
||||
|
||||
// Outputting information message
|
||||
$output->writeln(PHP_EOL . sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath));
|
||||
} else {
|
||||
$output->writeln('No Metadata Classes to process.');
|
||||
}
|
||||
$ui->newLine();
|
||||
$ui->text(sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath));
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,14 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Doctrine\ORM\Tools\Console\MetadataFilter;
|
||||
use Doctrine\ORM\Tools\EntityRepositoryGenerator;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to generate repository classes for mapping information.
|
||||
@ -44,25 +45,12 @@ class GenerateRepositoriesCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:generate-repositories')
|
||||
$this->setName('orm:generate-repositories')
|
||||
->setAliases(['orm:generate:repositories'])
|
||||
->setDescription('Generate repository classes from your mapping information.')
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
|
||||
'A string pattern used to match entities that should be processed.'
|
||||
),
|
||||
new InputArgument(
|
||||
'dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.'
|
||||
)
|
||||
]
|
||||
)
|
||||
->setHelp(<<<EOT
|
||||
Generate repository classes from your mapping information.
|
||||
EOT
|
||||
);
|
||||
->setDescription('Generate repository classes from your mapping information')
|
||||
->addArgument('dest-path', InputArgument::REQUIRED, 'The path to generate your repository classes.')
|
||||
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be processed.')
|
||||
->setHelp('Generate repository classes from your mapping information.');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,6 +58,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
$metadatas = $em->getMetadataFactory()->getAllMetadata();
|
||||
@ -92,7 +82,11 @@ EOT
|
||||
);
|
||||
}
|
||||
|
||||
if (count($metadatas)) {
|
||||
if (empty($metadatas)) {
|
||||
$ui->success('No Metadata Classes to process.');
|
||||
return;
|
||||
}
|
||||
|
||||
$numRepositories = 0;
|
||||
$generator = new EntityRepositoryGenerator();
|
||||
|
||||
@ -100,24 +94,21 @@ EOT
|
||||
|
||||
foreach ($metadatas as $metadata) {
|
||||
if ($metadata->customRepositoryClassName) {
|
||||
$output->writeln(
|
||||
sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName)
|
||||
);
|
||||
$ui->text(sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName));
|
||||
|
||||
$generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath);
|
||||
|
||||
$numRepositories++;
|
||||
++$numRepositories;
|
||||
}
|
||||
}
|
||||
|
||||
if ($numRepositories) {
|
||||
if ($numRepositories === 0) {
|
||||
$ui->text('No Repository classes were found to be processed.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Outputting information message
|
||||
$output->writeln(PHP_EOL . sprintf('Repository classes generated to "<info>%s</INFO>"', $destPath));
|
||||
} else {
|
||||
$output->writeln('No Repository classes were found to be processed.');
|
||||
}
|
||||
} else {
|
||||
$output->writeln('No Metadata Classes to process.');
|
||||
}
|
||||
$ui->newLine();
|
||||
$ui->text(sprintf('Repository classes generated to "<info>%s</INFO>"', $destPath));
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,10 @@
|
||||
namespace Doctrine\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\ORM\Mapping\MappingException;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Show information about mapped entities.
|
||||
@ -38,8 +39,7 @@ class InfoCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:info')
|
||||
$this->setName('orm:info')
|
||||
->setDescription('Show basic information about all mapped entities')
|
||||
->setHelp(<<<EOT
|
||||
The <info>%command.name%</info> shows basic information about which
|
||||
@ -54,6 +54,8 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
/* @var $entityManager \Doctrine\ORM\EntityManager */
|
||||
$entityManager = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
@ -61,25 +63,34 @@ EOT
|
||||
->getMetadataDriverImpl()
|
||||
->getAllClassNames();
|
||||
|
||||
if (!$entityClassNames) {
|
||||
throw new \Exception(
|
||||
'You do not have any mapped Doctrine ORM entities according to the current configuration. '.
|
||||
if ( ! $entityClassNames) {
|
||||
$ui->caution(
|
||||
[
|
||||
'You do not have any mapped Doctrine ORM entities according to the current configuration.',
|
||||
'If you have entities or mapping files you should check your mapping configuration for errors.'
|
||||
]
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("Found <info>%d</info> mapped entities:", count($entityClassNames)));
|
||||
$ui->text(sprintf("Found <info>%d</info> mapped entities:", count($entityClassNames)));
|
||||
$ui->newLine();
|
||||
|
||||
$failure = false;
|
||||
|
||||
foreach ($entityClassNames as $entityClassName) {
|
||||
try {
|
||||
$entityManager->getClassMetadata($entityClassName);
|
||||
$output->writeln(sprintf("<info>[OK]</info> %s", $entityClassName));
|
||||
$ui->text(sprintf("<info>[OK]</info> %s", $entityClassName));
|
||||
} catch (MappingException $e) {
|
||||
$output->writeln("<error>[FAIL]</error> ".$entityClassName);
|
||||
$output->writeln(sprintf("<comment>%s</comment>", $e->getMessage()));
|
||||
$output->writeln('');
|
||||
$ui->text(
|
||||
[
|
||||
sprintf("<error>[FAIL]</error> %s", $entityClassName),
|
||||
sprintf("<comment>%s</comment>", $e->getMessage()),
|
||||
''
|
||||
]
|
||||
);
|
||||
|
||||
$failure = true;
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ namespace Doctrine\ORM\Tools\Console\Command;
|
||||
use Doctrine\Common\Persistence\Mapping\MappingException;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Show information about mapped entities.
|
||||
@ -41,8 +41,7 @@ final class MappingDescribeCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:mapping:describe')
|
||||
$this->setName('orm:mapping:describe')
|
||||
->addArgument('entityName', InputArgument::REQUIRED, 'Full or partial name of entity')
|
||||
->setDescription('Display information about mapped objects')
|
||||
->setHelp(<<<EOT
|
||||
@ -62,10 +61,12 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
/* @var $entityManager \Doctrine\ORM\EntityManagerInterface */
|
||||
$entityManager = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
$this->displayEntity($input->getArgument('entityName'), $entityManager, $output);
|
||||
$this->displayEntity($input->getArgument('entityName'), $entityManager, $ui);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -75,18 +76,14 @@ EOT
|
||||
*
|
||||
* @param string $entityName Full or partial entity class name
|
||||
* @param EntityManagerInterface $entityManager
|
||||
* @param OutputInterface $output
|
||||
* @param SymfonyStyle $ui
|
||||
*/
|
||||
private function displayEntity($entityName, EntityManagerInterface $entityManager, OutputInterface $output)
|
||||
private function displayEntity($entityName, EntityManagerInterface $entityManager, SymfonyStyle $ui)
|
||||
{
|
||||
$table = new Table($output);
|
||||
|
||||
$table->setHeaders(['Field', 'Value']);
|
||||
|
||||
$metadata = $this->getClassMetadata($entityName, $entityManager);
|
||||
|
||||
array_map(
|
||||
[$table, 'addRow'],
|
||||
$ui->table(
|
||||
['Field', 'Value'],
|
||||
array_merge(
|
||||
[
|
||||
$this->formatField('Name', $metadata->name),
|
||||
@ -125,8 +122,6 @@ EOT
|
||||
$this->formatMappings($metadata->fieldMappings)
|
||||
)
|
||||
);
|
||||
|
||||
$table->render();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,8 +133,7 @@ EOT
|
||||
*/
|
||||
private function getMappedEntities(EntityManagerInterface $entityManager)
|
||||
{
|
||||
$entityClassNames = $entityManager
|
||||
->getConfiguration()
|
||||
$entityClassNames = $entityManager->getConfiguration()
|
||||
->getMetadataDriverImpl()
|
||||
->getAllClassNames();
|
||||
|
||||
@ -219,13 +213,9 @@ EOT
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
if (defined('JSON_UNESCAPED_UNICODE') && defined('JSON_UNESCAPED_SLASHES')) {
|
||||
return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
return json_encode($value);
|
||||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
return sprintf('<%s>', get_class($value));
|
||||
}
|
||||
@ -285,14 +275,6 @@ EOT
|
||||
*/
|
||||
private function formatEntityListeners(array $entityListeners)
|
||||
{
|
||||
return $this->formatField(
|
||||
'Entity listeners',
|
||||
array_map(
|
||||
function ($entityListener) {
|
||||
return get_class($entityListener);
|
||||
},
|
||||
$entityListeners
|
||||
)
|
||||
);
|
||||
return $this->formatField('Entity listeners', array_map('get_class', $entityListeners));
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,13 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\Common\Util\Debug;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\Common\Util\Debug;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to execute DQL queries in a given EntityManager.
|
||||
@ -43,39 +44,15 @@ class RunDqlCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:run-dql')
|
||||
->setDescription('Executes arbitrary DQL directly from the command line.')
|
||||
->setDefinition(
|
||||
[
|
||||
new InputArgument('dql', InputArgument::REQUIRED, 'The DQL to execute.'),
|
||||
new InputOption(
|
||||
'hydrate', null, InputOption::VALUE_REQUIRED,
|
||||
'Hydration mode of result set. Should be either: object, array, scalar or single-scalar.',
|
||||
'object'
|
||||
),
|
||||
new InputOption(
|
||||
'first-result', null, InputOption::VALUE_REQUIRED,
|
||||
'The first result in the result set.'
|
||||
),
|
||||
new InputOption(
|
||||
'max-result', null, InputOption::VALUE_REQUIRED,
|
||||
'The maximum number of results in the result set.'
|
||||
),
|
||||
new InputOption(
|
||||
'depth', null, InputOption::VALUE_REQUIRED,
|
||||
'Dumping depth of Entity graph.', 7
|
||||
),
|
||||
new InputOption(
|
||||
'show-sql', null, InputOption::VALUE_NONE,
|
||||
'Dump generated SQL instead of executing query'
|
||||
)
|
||||
]
|
||||
)
|
||||
->setHelp(<<<EOT
|
||||
Executes arbitrary DQL directly from the command line.
|
||||
EOT
|
||||
);
|
||||
$this->setName('orm:run-dql')
|
||||
->setDescription('Executes arbitrary DQL directly from the command line')
|
||||
->addArgument('dql', InputArgument::REQUIRED, 'The DQL to execute.')
|
||||
->addOption('hydrate', null, InputOption::VALUE_REQUIRED, 'Hydration mode of result set. Should be either: object, array, scalar or single-scalar.', 'object')
|
||||
->addOption('first-result', null, InputOption::VALUE_REQUIRED, 'The first result in the result set.')
|
||||
->addOption('max-result', null, InputOption::VALUE_REQUIRED, 'The maximum number of results in the result set.')
|
||||
->addOption('depth', null, InputOption::VALUE_REQUIRED, 'Dumping depth of Entity graph.', 7)
|
||||
->addOption('show-sql', null, InputOption::VALUE_NONE, 'Dump generated SQL instead of executing query')
|
||||
->setHelp('Executes arbitrary DQL directly from the command line.');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,17 +60,19 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
/* @var $em \Doctrine\ORM\EntityManagerInterface */
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
|
||||
if (($dql = $input->getArgument('dql')) === null) {
|
||||
throw new \RuntimeException("Argument 'DQL' is required in order to execute this command correctly.");
|
||||
throw new \RuntimeException("Argument 'dql' is required in order to execute this command correctly.");
|
||||
}
|
||||
|
||||
$depth = $input->getOption('depth');
|
||||
|
||||
if ( ! is_numeric($depth)) {
|
||||
throw new \LogicException("Option 'depth' must contains an integer value");
|
||||
throw new \LogicException("Option 'depth' must contain an integer value");
|
||||
}
|
||||
|
||||
$hydrationModeName = $input->getOption('hydrate');
|
||||
@ -109,7 +88,7 @@ EOT
|
||||
|
||||
if (($firstResult = $input->getOption('first-result')) !== null) {
|
||||
if ( ! is_numeric($firstResult)) {
|
||||
throw new \LogicException("Option 'first-result' must contains an integer value");
|
||||
throw new \LogicException("Option 'first-result' must contain an integer value");
|
||||
}
|
||||
|
||||
$query->setFirstResult((int) $firstResult);
|
||||
@ -117,19 +96,19 @@ EOT
|
||||
|
||||
if (($maxResult = $input->getOption('max-result')) !== null) {
|
||||
if ( ! is_numeric($maxResult)) {
|
||||
throw new \LogicException("Option 'max-result' must contains an integer value");
|
||||
throw new \LogicException("Option 'max-result' must contain an integer value");
|
||||
}
|
||||
|
||||
$query->setMaxResults((int) $maxResult);
|
||||
}
|
||||
|
||||
if ($input->getOption('show-sql')) {
|
||||
$output->writeln(Debug::dump($query->getSQL(), 2, true, false));
|
||||
$ui->text($query->getSQL());
|
||||
return;
|
||||
}
|
||||
|
||||
$resultSet = $query->execute([], constant($hydrationMode));
|
||||
|
||||
$output->writeln(Debug::dump($resultSet, $input->getOption('depth'), true, false));
|
||||
$ui->text(Debug::dump($resultSet, $input->getOption('depth'), true, false));
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,11 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
|
||||
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Base class for CreateCommand, DropCommand and UpdateCommand.
|
||||
@ -44,13 +45,15 @@ abstract class AbstractCommand extends Command
|
||||
*
|
||||
* @return null|int Null or 0 if everything went fine, or an error code.
|
||||
*/
|
||||
abstract protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas);
|
||||
abstract protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$emHelper = $this->getHelper('em');
|
||||
|
||||
/* @var $em \Doctrine\ORM\EntityManager */
|
||||
@ -58,15 +61,12 @@ abstract class AbstractCommand extends Command
|
||||
|
||||
$metadatas = $em->getMetadataFactory()->getAllMetadata();
|
||||
|
||||
if ( ! empty($metadatas)) {
|
||||
// Create SchemaTool
|
||||
$tool = new SchemaTool($em);
|
||||
|
||||
return $this->executeSchemaCommand($input, $output, $tool, $metadatas);
|
||||
} else {
|
||||
$output->writeln('No Metadata Classes to process.');
|
||||
if (empty($metadatas)) {
|
||||
$ui->success('No Metadata Classes to process.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $this->executeSchemaCommand($input, $output, new SchemaTool($em), $metadatas, $ui);
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,11 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
|
||||
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to create the database schema for a set of classes based on their mappings.
|
||||
@ -41,19 +42,9 @@ class CreateCommand extends AbstractCommand
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:schema-tool:create')
|
||||
->setDescription(
|
||||
'Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output.'
|
||||
)
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'dump-sql', null, InputOption::VALUE_NONE,
|
||||
'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.'
|
||||
)
|
||||
]
|
||||
)
|
||||
$this->setName('orm:schema-tool:create')
|
||||
->setDescription('Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output')
|
||||
->addOption('dump-sql', null, InputOption::VALUE_NONE, 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.')
|
||||
->setHelp(<<<EOT
|
||||
Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output.
|
||||
|
||||
@ -69,19 +60,31 @@ EOT
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
|
||||
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui)
|
||||
{
|
||||
if ($input->getOption('dump-sql')) {
|
||||
$sqls = $schemaTool->getCreateSchemaSql($metadatas);
|
||||
$output->writeln(implode(';' . PHP_EOL, $sqls) . ';');
|
||||
} else {
|
||||
$output->writeln('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL);
|
||||
$dumpSql = true === $input->getOption('dump-sql');
|
||||
|
||||
$output->writeln('Creating database schema...');
|
||||
$schemaTool->createSchema($metadatas);
|
||||
$output->writeln('Database schema created successfully!');
|
||||
if ($dumpSql) {
|
||||
$sqls = $schemaTool->getCreateSchemaSql($metadatas);
|
||||
$ui->text('The following SQL statements will be executed:');
|
||||
$ui->newLine();
|
||||
|
||||
foreach ($sqls as $sql) {
|
||||
$ui->text(sprintf(' %s;', $sql));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$ui->caution('This operation should not be executed in a production environment!');
|
||||
|
||||
$ui->text('Creating database schema...');
|
||||
$ui->newLine();
|
||||
|
||||
$schemaTool->createSchema($metadatas);
|
||||
|
||||
$ui->success('Database schema created successfully!');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,11 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
|
||||
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to drop the database schema for a set of classes based on their mappings.
|
||||
@ -41,27 +42,11 @@ class DropCommand extends AbstractCommand
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:schema-tool:drop')
|
||||
->setDescription(
|
||||
'Drop the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output.'
|
||||
)
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'dump-sql', null, InputOption::VALUE_NONE,
|
||||
'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.'
|
||||
),
|
||||
new InputOption(
|
||||
'force', 'f', InputOption::VALUE_NONE,
|
||||
"Don't ask for the deletion of the database, but force the operation to run."
|
||||
),
|
||||
new InputOption(
|
||||
'full-database', null, InputOption::VALUE_NONE,
|
||||
'Instead of using the Class Metadata to detect the database table schema, drop ALL assets that the database contains.'
|
||||
),
|
||||
]
|
||||
)
|
||||
$this->setName('orm:schema-tool:drop')
|
||||
->setDescription('Drop the complete database schema of EntityManager Storage Connection or generate the corresponding SQL output')
|
||||
->addOption('dump-sql', null, InputOption::VALUE_NONE, 'Instead of trying to apply generated SQLs into EntityManager Storage Connection, output them.')
|
||||
->addOption('force', 'f', InputOption::VALUE_NONE, "Don't ask for the deletion of the database, but force the operation to run.")
|
||||
->addOption('full-database', null, InputOption::VALUE_NONE, 'Instead of using the Class Metadata to detect the database table schema, drop ALL assets that the database contains.')
|
||||
->setHelp(<<<EOT
|
||||
Processes the schema and either drop the database schema of EntityManager Storage Connection or generate the SQL output.
|
||||
Beware that the complete database is dropped by this command, even tables that are not relevant to your metadata model.
|
||||
@ -78,23 +63,31 @@ EOT
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
|
||||
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui)
|
||||
{
|
||||
$isFullDatabaseDrop = $input->getOption('full-database');
|
||||
$dumpSql = true === $input->getOption('dump-sql');
|
||||
$force = true === $input->getOption('force');
|
||||
|
||||
if ($input->getOption('dump-sql')) {
|
||||
if ($dumpSql) {
|
||||
if ($isFullDatabaseDrop) {
|
||||
$sqls = $schemaTool->getDropDatabaseSQL();
|
||||
} else {
|
||||
$sqls = $schemaTool->getDropSchemaSQL($metadatas);
|
||||
}
|
||||
$output->writeln(implode(';' . PHP_EOL, $sqls));
|
||||
$ui->text('The following SQL statements will be executed:');
|
||||
$ui->newLine();
|
||||
|
||||
foreach ($sqls as $sql) {
|
||||
$ui->text(sprintf(' %s;', $sql));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($input->getOption('force')) {
|
||||
$output->writeln('Dropping database schema...');
|
||||
if ($force) {
|
||||
$ui->text('Dropping database schema...');
|
||||
$ui->newLine();
|
||||
|
||||
if ($isFullDatabaseDrop) {
|
||||
$schemaTool->dropDatabase();
|
||||
@ -102,12 +95,12 @@ EOT
|
||||
$schemaTool->dropSchema($metadatas);
|
||||
}
|
||||
|
||||
$output->writeln('Database schema dropped successfully!');
|
||||
$ui->success('Database schema dropped successfully!');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$output->writeln('<comment>ATTENTION</comment>: This operation should not be executed in a production environment.' . PHP_EOL);
|
||||
$ui->caution('This operation should not be executed in a production environment!');
|
||||
|
||||
if ($isFullDatabaseDrop) {
|
||||
$sqls = $schemaTool->getDropDatabaseSQL();
|
||||
@ -115,18 +108,23 @@ EOT
|
||||
$sqls = $schemaTool->getDropSchemaSQL($metadatas);
|
||||
}
|
||||
|
||||
if (count($sqls)) {
|
||||
$output->writeln(sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sqls)));
|
||||
$output->writeln('Please run the operation by passing one - or both - of the following options:');
|
||||
|
||||
$output->writeln(sprintf(' <info>%s --force</info> to execute the command', $this->getName()));
|
||||
$output->writeln(sprintf(' <info>%s --dump-sql</info> to dump the SQL statements to the screen', $this->getName()));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$output->writeln('Nothing to drop. The database is empty!');
|
||||
if (empty($sqls)) {
|
||||
$ui->success('Nothing to drop. The database is empty!');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$ui->text(
|
||||
[
|
||||
sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sqls)),
|
||||
'',
|
||||
'Please run the operation by passing one - or both - of the following options:',
|
||||
'',
|
||||
sprintf(' <info>%s --force</info> to execute the command', $this->getName()),
|
||||
sprintf(' <info>%s --dump-sql</info> to dump the SQL statements to the screen', $this->getName()),
|
||||
]
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,11 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command\SchemaTool;
|
||||
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to generate the SQL needed to update the database schema to match
|
||||
@ -48,30 +49,12 @@ class UpdateCommand extends AbstractCommand
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName($this->name)
|
||||
->setDescription(
|
||||
'Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata.'
|
||||
)
|
||||
->setDefinition(
|
||||
[
|
||||
new InputOption(
|
||||
'complete', null, InputOption::VALUE_NONE,
|
||||
'If defined, all assets of the database which are not relevant to the current metadata will be dropped.'
|
||||
),
|
||||
|
||||
new InputOption(
|
||||
'dump-sql', null, InputOption::VALUE_NONE,
|
||||
'Dumps the generated SQL statements to the screen (does not execute them).'
|
||||
),
|
||||
new InputOption(
|
||||
'force', 'f', InputOption::VALUE_NONE,
|
||||
'Causes the generated SQL statements to be physically executed against your database.'
|
||||
),
|
||||
]
|
||||
);
|
||||
|
||||
$this->setHelp(<<<EOT
|
||||
$this->setName($this->name)
|
||||
->setDescription('Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata')
|
||||
->addOption('complete', null, InputOption::VALUE_NONE, 'If defined, all assets of the database which are not relevant to the current metadata will be dropped.')
|
||||
->addOption('dump-sql', null, InputOption::VALUE_NONE, 'Dumps the generated SQL statements to the screen (does not execute them).')
|
||||
->addOption('force', 'f', InputOption::VALUE_NONE, 'Causes the generated SQL statements to be physically executed against your database.')
|
||||
->setHelp(<<<EOT
|
||||
The <info>%command.name%</info> command generates the SQL needed to
|
||||
synchronize the database schema with the current mapping metadata of the
|
||||
default entity manager.
|
||||
@ -107,15 +90,15 @@ EOT
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
|
||||
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas, SymfonyStyle $ui)
|
||||
{
|
||||
// Defining if update is complete or not (--complete not defined means $saveMode = true)
|
||||
$saveMode = ! $input->getOption('complete');
|
||||
|
||||
$sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode);
|
||||
|
||||
if (0 === count($sqls)) {
|
||||
$output->writeln('Nothing to update - your database is already in sync with the current entity metadata.');
|
||||
if (empty($sqls)) {
|
||||
$ui->success('Nothing to update - your database is already in sync with the current entity metadata.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -124,35 +107,52 @@ EOT
|
||||
$force = true === $input->getOption('force');
|
||||
|
||||
if ($dumpSql) {
|
||||
$output->writeln(implode(';' . PHP_EOL, $sqls) . ';');
|
||||
$ui->text('The following SQL statements will be executed:');
|
||||
$ui->newLine();
|
||||
|
||||
foreach ($sqls as $sql) {
|
||||
$ui->text(sprintf(' %s;', $sql));
|
||||
}
|
||||
}
|
||||
|
||||
if ($force) {
|
||||
if ($dumpSql) {
|
||||
$output->writeln('');
|
||||
$ui->newLine();
|
||||
}
|
||||
$output->writeln('Updating database schema...');
|
||||
$ui->text('Updating database schema...');
|
||||
$ui->newLine();
|
||||
|
||||
$schemaTool->updateSchema($metadatas, $saveMode);
|
||||
|
||||
$pluralization = (1 === count($sqls)) ? 'query was' : 'queries were';
|
||||
|
||||
$output->writeln(sprintf('Database schema updated successfully! "<info>%s</info>" %s executed', count($sqls), $pluralization));
|
||||
$ui->text(sprintf(' <info>%s</info> %s executed', count($sqls), $pluralization));
|
||||
$ui->success('Database schema updated successfully!');
|
||||
}
|
||||
|
||||
if ($dumpSql || $force) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$output->writeln('<comment>ATTENTION</comment>: This operation should not be executed in a production environment.');
|
||||
$output->writeln(' Use the incremental update to detect changes during development and use');
|
||||
$output->writeln(' the SQL DDL provided to manually update your database in production.');
|
||||
$output->writeln('');
|
||||
$ui->caution(
|
||||
[
|
||||
'This operation should not be executed in a production environment!',
|
||||
'',
|
||||
'Use the incremental update to detect changes during development and use',
|
||||
'the SQL DDL provided to manually update your database in production.',
|
||||
]
|
||||
);
|
||||
|
||||
$output->writeln(sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sqls)));
|
||||
$output->writeln('Please run the operation by passing one - or both - of the following options:');
|
||||
|
||||
$output->writeln(sprintf(' <info>%s --force</info> to execute the command', $this->getName()));
|
||||
$output->writeln(sprintf(' <info>%s --dump-sql</info> to dump the SQL statements to the screen', $this->getName()));
|
||||
$ui->text(
|
||||
[
|
||||
sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sqls)),
|
||||
'',
|
||||
'Please run the operation by passing one - or both - of the following options:',
|
||||
'',
|
||||
sprintf(' <info>%s --force</info> to execute the command', $this->getName()),
|
||||
sprintf(' <info>%s --dump-sql</info> to dump the SQL statements to the screen', $this->getName()),
|
||||
]
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -19,11 +19,12 @@
|
||||
|
||||
namespace Doctrine\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\ORM\Tools\SchemaValidator;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Doctrine\ORM\Tools\SchemaValidator;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command to validate that the current mapping is valid.
|
||||
@ -43,26 +44,11 @@ class ValidateSchemaCommand extends Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('orm:validate-schema')
|
||||
->setDescription('Validate the mapping files.')
|
||||
->addOption(
|
||||
'skip-mapping',
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Skip the mapping validation check'
|
||||
)
|
||||
->addOption(
|
||||
'skip-sync',
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Skip checking if the mapping is in sync with the database'
|
||||
)
|
||||
->setHelp(
|
||||
<<<EOT
|
||||
'Validate that the mapping files are correct and in sync with the database.'
|
||||
EOT
|
||||
);
|
||||
$this->setName('orm:validate-schema')
|
||||
->setDescription('Validate the mapping files')
|
||||
->addOption('skip-mapping', null, InputOption::VALUE_NONE, 'Skip the mapping validation check')
|
||||
->addOption('skip-sync', null, InputOption::VALUE_NONE, 'Skip checking if the mapping is in sync with the database')
|
||||
->setHelp('Validate that the mapping files are correct and in sync with the database.');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,35 +56,43 @@ EOT
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$ui = new SymfonyStyle($input, $output);
|
||||
|
||||
$em = $this->getHelper('em')->getEntityManager();
|
||||
$validator = new SchemaValidator($em);
|
||||
$exit = 0;
|
||||
|
||||
$ui->section('Mapping');
|
||||
|
||||
if ($input->getOption('skip-mapping')) {
|
||||
$output->writeln('<comment>[Mapping] Skipped mapping check.</comment>');
|
||||
$ui->text('<comment>[SKIPPED] The mapping was not checked.</comment>');
|
||||
} elseif ($errors = $validator->validateMapping()) {
|
||||
foreach ($errors as $className => $errorMessages) {
|
||||
$output->writeln("<error>[Mapping] FAIL - The entity-class '" . $className . "' mapping is invalid:</error>");
|
||||
$ui->text(
|
||||
sprintf(
|
||||
'<error>[FAIL]</error> The entity-class <comment>%s</comment> mapping is invalid:',
|
||||
$className
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($errorMessages as $errorMessage) {
|
||||
$output->writeln('* ' . $errorMessage);
|
||||
}
|
||||
|
||||
$output->writeln('');
|
||||
$ui->listing($errorMessages);
|
||||
$ui->newLine();
|
||||
}
|
||||
|
||||
++$exit;
|
||||
} else {
|
||||
$output->writeln('<info>[Mapping] OK - The mapping files are correct.</info>');
|
||||
$ui->success('The mapping files are correct.');
|
||||
}
|
||||
|
||||
$ui->section('Database');
|
||||
|
||||
if ($input->getOption('skip-sync')) {
|
||||
$output->writeln('<comment>[Database] SKIPPED - The database was not checked for synchronicity.</comment>');
|
||||
} elseif (!$validator->schemaInSyncWithMetadata()) {
|
||||
$output->writeln('<error>[Database] FAIL - The database schema is not in sync with the current mapping file.</error>');
|
||||
$ui->text('<comment>[SKIPPED] The database was not checked for synchronicity.</comment>');
|
||||
} elseif ( ! $validator->schemaInSyncWithMetadata()) {
|
||||
$ui->error('The database schema is not in sync with the current mapping file.');
|
||||
$exit += 2;
|
||||
} else {
|
||||
$output->writeln('<info>[Database] OK - The database schema is in sync with the mapping files.</info>');
|
||||
$ui->success('The database schema is in sync with the mapping files.');
|
||||
}
|
||||
|
||||
return $exit;
|
||||
|
@ -19,6 +19,10 @@
|
||||
bootstrap="./tests/Doctrine/Tests/TestInit.php"
|
||||
>
|
||||
|
||||
<php>
|
||||
<env name="COLUMNS" value="120"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Doctrine ORM Test Suite">
|
||||
<directory>./tests/Doctrine/Tests/ORM</directory>
|
||||
|
@ -30,15 +30,10 @@ class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
|
||||
$this->enableSecondLevelCache();
|
||||
parent::setUp();
|
||||
|
||||
$this->application = new Application();
|
||||
$this->command = new CollectionRegionCommand();
|
||||
|
||||
$this->application->setHelperSet(new HelperSet(
|
||||
[
|
||||
'em' => new EntityManagerHelper($this->_em)
|
||||
]
|
||||
));
|
||||
|
||||
$this->application = new Application();
|
||||
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
|
||||
$this->application->add($this->command);
|
||||
}
|
||||
|
||||
@ -46,60 +41,79 @@ class ClearCacheCollectionRegionCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:collection');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'--all' => true,
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Clearing all second-level cache collection regions' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(' // Clearing all second-level cache collection regions', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testClearByOwnerEntityClassName()
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:collection');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'owner-class' => State::class,
|
||||
'association' => 'cities',
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Clearing second-level cache for collection "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(
|
||||
' // Clearing second-level cache for collection "Doctrine\Tests\Models\Cache\State#cities"',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
public function testClearCacheEntryName()
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:collection');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'owner-class' => State::class,
|
||||
'association' => 'cities',
|
||||
'owner-id' => 1,
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Clearing second-level cache entry for collection "Doctrine\Tests\Models\Cache\State#cities" owner entity identified by "1"' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(
|
||||
' // Clearing second-level cache entry for collection "Doctrine\Tests\Models\Cache\State#cities" owner',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
|
||||
self::assertContains(' // entity identified by "1"', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testFlushRegionName()
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:collection');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'owner-class' => State::class,
|
||||
'association' => 'cities',
|
||||
'--flush' => true,
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Flushing cache provider configured for "Doctrine\Tests\Models\Cache\State#cities"' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(
|
||||
' // Flushing cache provider configured for "Doctrine\Tests\Models\Cache\State#cities"',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -30,15 +30,10 @@ class ClearCacheEntityRegionCommandTest extends OrmFunctionalTestCase
|
||||
$this->enableSecondLevelCache();
|
||||
parent::setUp();
|
||||
|
||||
$this->application = new Application();
|
||||
$this->command = new EntityRegionCommand();
|
||||
|
||||
$this->application->setHelperSet(new HelperSet(
|
||||
[
|
||||
'em' => new EntityManagerHelper($this->_em)
|
||||
]
|
||||
));
|
||||
|
||||
$this->application = new Application();
|
||||
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
|
||||
$this->application->add($this->command);
|
||||
}
|
||||
|
||||
@ -46,57 +41,76 @@ class ClearCacheEntityRegionCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:entity');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'--all' => true,
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Clearing all second-level cache entity regions' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(' // Clearing all second-level cache entity regions', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testClearByEntityClassName()
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:entity');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'entity-class' => Country::class,
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Clearing second-level cache for entity "Doctrine\Tests\Models\Cache\Country"' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(
|
||||
' // Clearing second-level cache for entity "Doctrine\Tests\Models\Cache\Country"',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
public function testClearCacheEntryName()
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:entity');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'entity-class' => Country::class,
|
||||
'entity-id' => 1,
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Clearing second-level cache entry for entity "Doctrine\Tests\Models\Cache\Country" identified by "1"' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(
|
||||
' // Clearing second-level cache entry for entity "Doctrine\Tests\Models\Cache\Country" identified by',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
|
||||
self::assertContains(' // "1"', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testFlushRegionName()
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:entity');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'entity-class' => Country::class,
|
||||
'--flush' => true,
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Flushing cache provider configured for entity named "Doctrine\Tests\Models\Cache\Country"' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(
|
||||
' // Flushing cache provider configured for entity named "Doctrine\Tests\Models\Cache\Country"',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\Command\ClearCache\QueryRegionCommand;
|
||||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* @group DDC-2183
|
||||
@ -29,15 +29,10 @@ class ClearCacheQueryRegionCommandTest extends OrmFunctionalTestCase
|
||||
$this->enableSecondLevelCache();
|
||||
parent::setUp();
|
||||
|
||||
$this->application = new Application();
|
||||
$this->command = new QueryRegionCommand();
|
||||
|
||||
$this->application->setHelperSet(new HelperSet(
|
||||
[
|
||||
'em' => new EntityManagerHelper($this->_em)
|
||||
]
|
||||
));
|
||||
|
||||
$this->application = new Application();
|
||||
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
|
||||
$this->application->add($this->command);
|
||||
}
|
||||
|
||||
@ -45,56 +40,73 @@ class ClearCacheQueryRegionCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:query');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'--all' => true,
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Clearing all second-level cache query regions' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(' // Clearing all second-level cache query regions', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testClearDefaultRegionName()
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:query');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'region-name' => null,
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Clearing second-level cache query region named "query_cache_region"' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(
|
||||
' // Clearing second-level cache query region named "query_cache_region"',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
public function testClearByRegionName()
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:query');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'region-name' => 'my_region',
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Clearing second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(
|
||||
' // Clearing second-level cache query region named "my_region"',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
public function testFlushRegionName()
|
||||
{
|
||||
$command = $this->application->find('orm:clear-cache:region:query');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'region-name' => 'my_region',
|
||||
'--flush' => true,
|
||||
], ['decorated' => false]
|
||||
],
|
||||
['decorated' => false]
|
||||
);
|
||||
|
||||
$this->assertEquals('Flushing cache provider configured for second-level cache query region named "my_region"' . PHP_EOL, $tester->getDisplay());
|
||||
self::assertContains(
|
||||
' // Flushing cache provider configured for second-level cache query region named "my_region"',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -2,18 +2,18 @@
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
|
||||
use Doctrine\ORM\Configuration;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand;
|
||||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
|
||||
use Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* GenerateRepositoriesCommandTest
|
||||
*/
|
||||
class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
|
||||
{
|
||||
/**
|
||||
@ -34,25 +34,12 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
|
||||
|
||||
\mkdir($this->path);
|
||||
|
||||
|
||||
$metadataDriver = $this->_em->getConfiguration()->getMetadataDriverImpl();
|
||||
|
||||
$metadataDriver->addPaths(
|
||||
[
|
||||
__DIR__ . '/../../../../Models/DDC3231/'
|
||||
]
|
||||
);
|
||||
$metadataDriver->addPaths([__DIR__ . '/../../../../Models/DDC3231/']);
|
||||
|
||||
$this->application = new Application();
|
||||
|
||||
$this->application->setHelperSet(new HelperSet(
|
||||
[
|
||||
'em' => new EntityManagerHelper($this->_em)
|
||||
]
|
||||
));
|
||||
|
||||
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
|
||||
$this->application->add(new GenerateRepositoriesCommand());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,20 +75,20 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
|
||||
$cname = 'Doctrine\Tests\Models\DDC3231\DDC3231User1Repository';
|
||||
$fname = str_replace('\\', DIRECTORY_SEPARATOR, $cname) . '.php';
|
||||
|
||||
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname);
|
||||
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php');
|
||||
self::assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname);
|
||||
self::assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php');
|
||||
|
||||
require $this->path . DIRECTORY_SEPARATOR . $fname;
|
||||
require $this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php';
|
||||
|
||||
$this->assertTrue(class_exists($cname));
|
||||
$this->assertTrue(class_exists('DDC3231User1NoNamespaceRepository'));
|
||||
self::assertTrue(class_exists($cname));
|
||||
self::assertTrue(class_exists('DDC3231User1NoNamespaceRepository'));
|
||||
|
||||
$repo1 = new \ReflectionClass($cname);
|
||||
$repo2 = new \ReflectionClass('DDC3231User1NoNamespaceRepository');
|
||||
|
||||
$this->assertSame(EntityRepository::class, $repo1->getParentClass()->getName());
|
||||
$this->assertSame(EntityRepository::class, $repo2->getParentClass()->getName());
|
||||
self::assertSame(EntityRepository::class, $repo1->getParentClass()->getName());
|
||||
self::assertSame(EntityRepository::class, $repo2->getParentClass()->getName());
|
||||
}
|
||||
|
||||
public function testGenerateRepositoriesCustomDefaultRepository()
|
||||
@ -111,20 +98,20 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
|
||||
$cname = 'Doctrine\Tests\Models\DDC3231\DDC3231User2Repository';
|
||||
$fname = str_replace('\\', DIRECTORY_SEPARATOR, $cname) . '.php';
|
||||
|
||||
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname);
|
||||
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php');
|
||||
self::assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname);
|
||||
self::assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php');
|
||||
|
||||
require $this->path . DIRECTORY_SEPARATOR . $fname;
|
||||
require $this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php';
|
||||
|
||||
$this->assertTrue(class_exists($cname));
|
||||
$this->assertTrue(class_exists('DDC3231User2NoNamespaceRepository'));
|
||||
self::assertTrue(class_exists($cname));
|
||||
self::assertTrue(class_exists('DDC3231User2NoNamespaceRepository'));
|
||||
|
||||
$repo1 = new \ReflectionClass($cname);
|
||||
$repo2 = new \ReflectionClass('DDC3231User2NoNamespaceRepository');
|
||||
|
||||
$this->assertSame(DDC3231EntityRepository::class, $repo1->getParentClass()->getName());
|
||||
$this->assertSame(DDC3231EntityRepository::class, $repo2->getParentClass()->getName());
|
||||
self::assertSame(DDC3231EntityRepository::class, $repo1->getParentClass()->getName());
|
||||
self::assertSame(DDC3231EntityRepository::class, $repo2->getParentClass()->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,6 +126,7 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
|
||||
|
||||
$command = $this->application->find('orm:generate-repositories');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
@ -148,4 +136,38 @@ class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testNoMetadataClassesToProcess() : void
|
||||
{
|
||||
$configuration = $this->createMock(Configuration::class);
|
||||
$metadataFactory = $this->createMock(ClassMetadataFactory::class);
|
||||
$em = $this->createMock(EntityManagerInterface::class);
|
||||
|
||||
$configuration->method('getDefaultRepositoryClassName')
|
||||
->willReturn('fooRepository');
|
||||
|
||||
$metadataFactory->method('getAllMetadata')
|
||||
->willReturn([]);
|
||||
|
||||
$em->method('getMetadataFactory')
|
||||
->willReturn($metadataFactory);
|
||||
|
||||
$em->method('getConfiguration')
|
||||
->willReturn($configuration);
|
||||
|
||||
$application = new Application();
|
||||
$application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)]));
|
||||
$application->add(new GenerateRepositoriesCommand());
|
||||
|
||||
$command = $application->find('orm:generate-repositories');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(
|
||||
[
|
||||
'command' => $command->getName(),
|
||||
'dest-path' => $this->path,
|
||||
]
|
||||
);
|
||||
|
||||
self::assertContains('[OK] No Metadata Classes to process.', $tester->getDisplay());
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,10 @@
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Console\Command;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
|
||||
use Doctrine\ORM\Configuration;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Mapping\MappingException;
|
||||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
|
||||
use Doctrine\Tests\Models\Cache\AttractionInfo;
|
||||
use Doctrine\Tests\Models\Cache\City;
|
||||
@ -33,23 +37,86 @@ class InfoCommandTest extends OrmFunctionalTestCase
|
||||
parent::setUp();
|
||||
|
||||
$this->application = new Application();
|
||||
$command = new InfoCommand();
|
||||
|
||||
$this->application->setHelperSet(
|
||||
new HelperSet(['em' => new EntityManagerHelper($this->_em)])
|
||||
);
|
||||
|
||||
$this->application->add($command);
|
||||
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
|
||||
$this->application->add(new InfoCommand());
|
||||
|
||||
$this->command = $this->application->find('orm:info');
|
||||
$this->tester = new CommandTester($command);
|
||||
$this->tester = new CommandTester($this->command);
|
||||
}
|
||||
|
||||
public function testListAllClasses()
|
||||
{
|
||||
$this->tester->execute(['command' => $this->command->getName()]);
|
||||
|
||||
$this->assertContains(AttractionInfo::class, $this->tester->getDisplay());
|
||||
$this->assertContains(City::class, $this->tester->getDisplay());
|
||||
self::assertContains(AttractionInfo::class, $this->tester->getDisplay());
|
||||
self::assertContains(City::class, $this->tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testEmptyEntityClassNames() : void
|
||||
{
|
||||
$mappingDriver = $this->createMock(MappingDriver::class);
|
||||
$configuration = $this->createMock(Configuration::class);
|
||||
$em = $this->createMock(EntityManagerInterface::class);
|
||||
|
||||
$mappingDriver->method('getAllClassNames')
|
||||
->willReturn([]);
|
||||
|
||||
$configuration->method('getMetadataDriverImpl')
|
||||
->willReturn($mappingDriver);
|
||||
|
||||
$em->method('getConfiguration')
|
||||
->willReturn($configuration);
|
||||
|
||||
$application = new Application();
|
||||
$application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)]));
|
||||
$application->add(new InfoCommand());
|
||||
|
||||
$command = $application->find('orm:info');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName()]);
|
||||
|
||||
self::assertContains(
|
||||
' ! [CAUTION] You do not have any mapped Doctrine ORM entities according to the current configuration',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
|
||||
self::assertContains(
|
||||
' ! If you have entities or mapping files you should check your mapping configuration for errors.',
|
||||
$tester->getDisplay()
|
||||
);
|
||||
}
|
||||
|
||||
public function testInvalidEntityClassMetadata() : void
|
||||
{
|
||||
$mappingDriver = $this->createMock(MappingDriver::class);
|
||||
$configuration = $this->createMock(Configuration::class);
|
||||
$em = $this->createMock(EntityManagerInterface::class);
|
||||
|
||||
$mappingDriver->method('getAllClassNames')
|
||||
->willReturn(['InvalidEntity']);
|
||||
|
||||
$configuration->method('getMetadataDriverImpl')
|
||||
->willReturn($mappingDriver);
|
||||
|
||||
$em->method('getConfiguration')
|
||||
->willReturn($configuration);
|
||||
|
||||
$em->method('getClassMetadata')
|
||||
->with('InvalidEntity')
|
||||
->willThrowException(new MappingException('exception message'));
|
||||
|
||||
$application = new Application();
|
||||
$application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($em)]));
|
||||
$application->add(new InfoCommand());
|
||||
|
||||
$command = $application->find('orm:info');
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName()]);
|
||||
|
||||
self::assertContains('[FAIL] InvalidEntity', $tester->getDisplay());
|
||||
self::assertContains('exception message', $tester->getDisplay());
|
||||
}
|
||||
}
|
||||
|
@ -37,18 +37,11 @@ class MappingDescribeCommandTest extends OrmFunctionalTestCase
|
||||
parent::setUp();
|
||||
|
||||
$this->application = new Application();
|
||||
$command = new MappingDescribeCommand();
|
||||
|
||||
$this->application->setHelperSet(new HelperSet(
|
||||
[
|
||||
'em' => new EntityManagerHelper($this->_em)
|
||||
]
|
||||
));
|
||||
|
||||
$this->application->add($command);
|
||||
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
|
||||
$this->application->add(new MappingDescribeCommand());
|
||||
|
||||
$this->command = $this->application->find('orm:mapping:describe');
|
||||
$this->tester = new CommandTester($command);
|
||||
$this->tester = new CommandTester($this->command);
|
||||
}
|
||||
|
||||
public function testShowSpecificFuzzySingle()
|
||||
@ -61,8 +54,9 @@ class MappingDescribeCommandTest extends OrmFunctionalTestCase
|
||||
);
|
||||
|
||||
$display = $this->tester->getDisplay();
|
||||
$this->assertContains(AttractionInfo::class, $display);
|
||||
$this->assertContains('Root entity name', $display);
|
||||
|
||||
self::assertContains(AttractionInfo::class, $display);
|
||||
self::assertContains('Root entity name', $display);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,7 +82,7 @@ class MappingDescribeCommandTest extends OrmFunctionalTestCase
|
||||
$this->tester->execute(
|
||||
[
|
||||
'command' => $this->command->getName(),
|
||||
'entityName' => 'AttractionFooBar'
|
||||
'entityName' => 'AttractionFooBar',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -38,15 +38,10 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->application = new Application();
|
||||
$this->command = new RunDqlCommand();
|
||||
|
||||
$this->application->setHelperSet(new HelperSet(
|
||||
[
|
||||
'em' => new EntityManagerHelper($this->_em)
|
||||
]
|
||||
));
|
||||
|
||||
$this->application = new Application();
|
||||
$this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)]));
|
||||
$this->application->add($this->command);
|
||||
|
||||
$this->tester = new CommandTester($this->command);
|
||||
@ -54,7 +49,7 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
|
||||
|
||||
public function testCommandName()
|
||||
{
|
||||
$this->assertSame($this->command, $this->application->get('orm:run-dql'));
|
||||
self::assertSame($this->command, $this->application->get('orm:run-dql'));
|
||||
}
|
||||
|
||||
public function testWillRunQuery()
|
||||
@ -62,7 +57,7 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
|
||||
$this->_em->persist(new DateTimeModel());
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
0,
|
||||
$this->tester->execute(
|
||||
[
|
||||
@ -72,7 +67,7 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertContains(DateTimeModel::class, $this->tester->getDisplay());
|
||||
self::assertContains(DateTimeModel::class, $this->tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testWillShowQuery()
|
||||
@ -80,17 +75,17 @@ class RunDqlCommandTest extends OrmFunctionalTestCase
|
||||
$this->_em->persist(new DateTimeModel());
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertSame(
|
||||
self::assertSame(
|
||||
0,
|
||||
$this->tester->execute(
|
||||
[
|
||||
'command' => $this->command->getName(),
|
||||
'dql' => 'SELECT e FROM ' . DateTimeModel::class . ' e',
|
||||
'--show-sql' => 'true'
|
||||
'--show-sql' => 'true',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertStringMatchesFormat('%Astring%sSELECT %a', $this->tester->getDisplay());
|
||||
self::assertStringMatchesFormat('SELECT %a', trim($this->tester->getDisplay()));
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
<var name="tmpdb_username" value="travis" />
|
||||
<var name="tmpdb_password" value="" />
|
||||
<var name="tmpdb_port" value="3306"/>
|
||||
|
||||
<env name="COLUMNS" value="120"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
|
@ -19,6 +19,8 @@
|
||||
<var name="tmpdb_username" value="travis" />
|
||||
<var name="tmpdb_password" value="" />
|
||||
<var name="tmpdb_port" value="3306"/>
|
||||
|
||||
<env name="COLUMNS" value="120"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
|
@ -22,6 +22,8 @@
|
||||
<var name="tmpdb_username" value="postgres" />
|
||||
<var name="tmpdb_password" value="" />
|
||||
<var name="tmpdb_port" value="5432"/>
|
||||
|
||||
<env name="COLUMNS" value="120"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
|
@ -6,6 +6,10 @@
|
||||
failOnRisky="true"
|
||||
bootstrap="../Doctrine/Tests/TestInit.php"
|
||||
>
|
||||
<php>
|
||||
<env name="COLUMNS" value="120"/>
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Doctrine ORM Test Suite">
|
||||
<directory>./../Doctrine/Tests/ORM</directory>
|
||||
|
Loading…
x
Reference in New Issue
Block a user