protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manager = new DisconnectedMetadataFactory($this->getContainer()->get('doctrine'));
     try {
         $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('name'));
         $output->writeln(sprintf('Clearing entities for bundle "<info>%s</info>"', $bundle->getName()));
         $metadata = $manager->getBundleMetadata($bundle);
     } catch (\InvalidArgumentException $e) {
         $name = strtr($input->getArgument('name'), '/', '\\');
         if (false !== ($pos = strpos($name, ':'))) {
             $name = $this->getContainer()->get('doctrine')->getAliasNamespace(substr($name, 0, $pos)) . '\\' . substr($name, $pos + 1);
         }
         if (class_exists($name)) {
             $output->writeln(sprintf('Fixing entity "<info>%s</info>"', $name));
             $metadata = $manager->getClassMetadata($name, $input->getOption('path'));
         } else {
             $output->writeln(sprintf('Fixing entities for namespace "<info>%s</info>"', $name));
             $metadata = $manager->getNamespaceMetadata($name, $input->getOption('path'));
         }
     }
     foreach ($metadata->getMetadata() as $m) {
         // Getting the metadata for the entity class once more to get the correct path if the namespace has multiple occurrences
         try {
             $entityMetadata = $manager->getClassMetadata($m->getName(), $input->getOption('path'));
         } catch (\RuntimeException $e) {
             // fall back to the bundle metadata when no entity class could be found
             $entityMetadata = $metadata;
         }
         $output->writeln(sprintf('  > fixing <comment>%s</comment>', $m->name));
         $res = $this->fixEntity($m, $entityMetadata->getPath());
         if (!$res) {
             $output->writeln(sprintf('> FAILED'));
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $manager = new DisconnectedMetadataFactory($this->getContainer()->get('doctrine'));
     try {
         $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
         $output->writeln(sprintf('Generating translation for bundle "<info>%s</info>"', $bundle->getName()));
         $metadata = $manager->getBundleMetadata($bundle);
     } catch (\InvalidArgumentException $e) {
         $name = strtr($input->getArgument('name'), '/', '\\');
         if (false !== ($pos = strpos($name, ':'))) {
             $name = $this->getContainer()->get('doctrine')->getAliasNamespace(substr($name, 0, $pos)) . '\\' . substr($name, $pos + 1);
         }
         if (class_exists($name)) {
             $output->writeln(sprintf('Generating entity "<info>%s</info>"', $name));
             $metadata = $manager->getClassMetadata($name, $input->getOption('path'));
         } else {
             $output->writeln(sprintf('Generating entities for namespace "<info>%s</info>"', $name));
             $metadata = $manager->getNamespaceMetadata($name, $input->getOption('path'));
         }
     }
     $generator = $this->getEntityGenerator();
     $backupExisting = !$input->getOption('no-backup');
     $generator->setBackupExisting($backupExisting);
     $repoGenerator = new EntityRepositoryGenerator();
     foreach ($metadata->getMetadata() as $m) {
         if ($backupExisting) {
             $basename = substr($m->name, strrpos($m->name, '\\') + 1);
             $output->writeln(sprintf('  > backing up <comment>%s.php</comment> to <comment>%s.php~</comment>', $basename, $basename));
         }
         // Getting the metadata for the entity class once more to get the correct path if the namespace has multiple occurrences
         try {
             $entityMetadata = $manager->getClassMetadata($m->getName(), $input->getOption('path'));
         } catch (\RuntimeException $e) {
             // fall back to the bundle metadata when no entity class could be found
             $entityMetadata = $metadata;
         }
         $output->writeln(sprintf('  > generating <comment>%s</comment>', $m->name));
         $generator->generate(array($m), $entityMetadata->getPath());
         if ($m->customRepositoryClassName && false !== strpos($m->customRepositoryClassName, $metadata->getNamespace())) {
             $repoGenerator->writeEntityRepositoryClass($m->customRepositoryClassName, $metadata->getPath());
         }
     }
 }
 /**
  * Returning ClassMetadata
  *
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  * @param bool $displayStatus Displaying process messages
  *
  * @return ClassMetadataCollection
  */
 protected function getMetadata(InputInterface $input, OutputInterface $output, $displayStatus)
 {
     $manager = new DisconnectedMetadataFactory($this->getContainer()->get('doctrine'));
     try {
         $bundle = $this->getContainer()->get("kernel")->getBundle($input->getArgument('name'));
         if ($displayStatus) {
             $output->writeln(sprintf('Generating entities for bundle "<info>%s</info>"', $bundle->getName()));
         }
         $metadata = $manager->getBundleMetadata($bundle);
     } catch (\InvalidArgumentException $e) {
         $name = strtr($input->getArgument('name'), '/', '\\');
         if (false !== ($pos = strpos($name, ':'))) {
             $name = $this->getContainer()->get('doctrine')->getAliasNamespace(substr($name, 0, $pos)) . '\\' . substr($name, $pos + 1);
         }
         if (class_exists($name)) {
             if ($displayStatus) {
                 $output->writeln(sprintf('Generating entity "<info>%s</info>"', $name));
             }
             $metadata = $manager->getClassMetadata($name, $input->getOption('path'));
         } else {
             if ($displayStatus) {
                 $output->writeln(sprintf('Generating entities for namespace "<info>%s</info>"', $name));
             }
             $metadata = $manager->getNamespaceMetadata($name, $input->getOption('path'));
         }
     }
     return $metadata;
 }