|
@@ -18,6 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|
|
use Doctrine\ORM\Mapping\Driver\DatabaseDriver;
|
|
|
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
|
|
|
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
|
|
|
+use Doctrine\ORM\Tools\Console\MetadataFilter;
|
|
|
|
|
|
/**
|
|
|
* Import Doctrine ORM metadata mapping information from an existing database.
|
|
@@ -34,6 +35,8 @@ class ImportMappingDoctrineCommand extends DoctrineCommand
|
|
|
->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to import the mapping information to')
|
|
|
->addArgument('mapping-type', InputArgument::OPTIONAL, 'The mapping type to export the imported mapping information to')
|
|
|
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
|
|
|
+ ->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be mapped.')
|
|
|
+ ->addOption('force', null, InputOption::VALUE_NONE, 'Force to overwrite existing mapping files.')
|
|
|
->setDescription('Import mapping information from an existing database')
|
|
|
->setHelp(<<<EOT
|
|
|
The <info>doctrine:mapping:import</info> command imports mapping information
|
|
@@ -45,6 +48,16 @@ You can also optionally specify which entity manager to import from with the
|
|
|
<info>--em</info> option:
|
|
|
|
|
|
<info>./app/console doctrine:mapping:import "MyCustomBundle" xml --em=default</info>
|
|
|
+
|
|
|
+If you dont want to map every entity that can be found in the database, use the
|
|
|
+<info>--filter</info> option. It will try to match the targetted mapped entity with the
|
|
|
+provided pattern string.
|
|
|
+
|
|
|
+<info>./app/console doctrine:mapping:import "MyCustomBundle" xml --filter=MyMatchedEntity</info>
|
|
|
+
|
|
|
+Use the <info>--force</info> option, if you want to override existing mapping files:
|
|
|
+
|
|
|
+<info>./app/console doctrine:mapping:import "MyCustomBundle" xml --force</info>
|
|
|
EOT
|
|
|
);
|
|
|
}
|
|
@@ -66,6 +79,7 @@ EOT
|
|
|
|
|
|
$cme = new ClassMetadataExporter();
|
|
|
$exporter = $cme->getExporter($type);
|
|
|
+ $exporter->setOverwriteExistingFiles($input->getOption('force'));
|
|
|
|
|
|
if ('annotation' === $type) {
|
|
|
$entityGenerator = $this->getEntityGenerator();
|
|
@@ -83,6 +97,7 @@ EOT
|
|
|
$cmf = new DisconnectedClassMetadataFactory();
|
|
|
$cmf->setEntityManager($em);
|
|
|
$metadata = $cmf->getAllMetadata();
|
|
|
+ $metadata = MetadataFilter::filter($metadata, $input->getOption('filter'));
|
|
|
if ($metadata) {
|
|
|
$output->writeln(sprintf('Importing mapping information from "<info>%s</info>" entity manager', $emName));
|
|
|
foreach ($metadata as $class) {
|