Преглед на файлове

Merge remote branch 'mcbennn/master'

* mcbennn/master:
  'annotate' option is useless
  no-backup option instead of force, cleaned comparison operator
  Implements some options that already exist on other doctrine-related commands
Fabien Potencier преди 14 години
родител
ревизия
be046bcb44

+ 7 - 0
src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php

@@ -32,6 +32,7 @@ class GenerateEntitiesDoctrineCommand extends DoctrineCommand
             ->setDescription('Generate entity classes and method stubs from your mapping information')
             ->addArgument('name', InputArgument::REQUIRED, 'A bundle name, a namespace, or a class name')
             ->addOption('path', null, InputOption::VALUE_REQUIRED, 'The path where to generate entities when it cannot be guessed')
+            ->addOption('no-backup', null, InputOption::VALUE_NONE, 'Do not backup existing entities files.')
             ->setHelp(<<<EOT
 The <info>doctrine:generate:entities</info> command generates entity classes
 and method stubs from your mapping information:
@@ -57,6 +58,11 @@ you must provide the <comment>--path</comment> option:
 
   <info>./app/console doctrine:generate:entities Blog/Entity --path=src/</info>
 
+You should provide the <comment>--no-backup</comment> option if you dont mind to back up files
+before to generate entities:
+
+  <info>./app/console doctrine:generate:entities Blog/Entity --no-backup</info>
+
 EOT
         );
     }
@@ -85,6 +91,7 @@ EOT
         }
 
         $generator = $this->getEntityGenerator();
+        $generator->setBackupExisting(!$input->getOption('no-backup'));
         $repoGenerator = new EntityRepositoryGenerator();
         foreach ($metadatas as $metadata) {
             $output->writeln(sprintf('  > generating <comment>%s</comment>', $metadata->name));

+ 15 - 0
src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php

@@ -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) {