diff --git a/src/Symfony/Framework/DoctrineBundle/Command/BuildEntitiesDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/BuildEntitiesDoctrineCommand.php index d4ec8cb9e0..41533e1c60 100644 --- a/src/Symfony/Framework/DoctrineBundle/Command/BuildEntitiesDoctrineCommand.php +++ b/src/Symfony/Framework/DoctrineBundle/Command/BuildEntitiesDoctrineCommand.php @@ -46,21 +46,32 @@ class BuildEntitiesDoctrineCommand extends DoctrineCommand */ protected function execute(InputInterface $input, OutputInterface $output) { - foreach ($this->container->getParameter('kernel.bundle_dirs') as $bundle => $path) + $dirs = array(); + $bundleDirs = $this->container->getKernelService()->getBundleDirs(); + foreach ($this->container->getKernelService()->getBundles() as $bundle) { - $bundles = glob($path.'/*Bundle'); - foreach ($bundles as $p) + $tmp = dirname(str_replace('\\', '/', get_class($bundle))); + $namespace = str_replace('/', '\\', dirname($tmp)); + $class = basename($tmp); + + if (isset($bundleDirs[$namespace])) { - if (!is_dir($metadataPath = $p.'/Resources/config/doctrine/metadata')) + if (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Entities')) { - continue; + $this->convertMapping($dir, $bundleDirs[$namespace].'/..'); + } else if (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Resources/config/doctrine/metadata')) { + $this->convertMapping($dir, $bundleDirs[$namespace].'/..'); } - $opts = array(); - $opts['--from'] = $metadataPath; - $opts['--to'] = 'annotation'; - $opts['--dest'] = realpath($path.'/..'); - $this->runCommand('doctrine:convert-mapping', $opts); } } } + + protected function convertMapping($mappingPath, $dest) + { + $opts = array(); + $opts['--from'] = $mappingPath; + $opts['--to'] = 'annotation'; + $opts['--dest'] = realpath($dest); + $this->runCommand('doctrine:convert-mapping', $opts); + } } \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/DoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/DoctrineCommand.php index 8aedf8b22f..a560aafc57 100644 --- a/src/Symfony/Framework/DoctrineBundle/Command/DoctrineCommand.php +++ b/src/Symfony/Framework/DoctrineBundle/Command/DoctrineCommand.php @@ -33,6 +33,7 @@ use Doctrine\Common\Cli\CliController as DoctrineCliController; abstract class DoctrineCommand extends Command { protected + $application, $cli, $em; @@ -80,12 +81,16 @@ abstract class DoctrineCommand extends Command protected function runCommand($name, array $input = array()) { + if ($this->application === null) + { + $this->application = new Application($this->container->getKernelService()); + } + $arguments = array(); $arguments = array_merge(array($name), $input); $input = new ArrayInput($arguments); - $application = new Application($this->container->getKernelService()); - $application->setAutoExit(false); - $application->run($input); + $this->application->setAutoExit(false); + $this->application->run($input); } /** diff --git a/src/Symfony/Framework/DoctrineBundle/DependencyInjection/DoctrineExtension.php b/src/Symfony/Framework/DoctrineBundle/DependencyInjection/DoctrineExtension.php index 1d94610290..5924fb7131 100644 --- a/src/Symfony/Framework/DoctrineBundle/DependencyInjection/DoctrineExtension.php +++ b/src/Symfony/Framework/DoctrineBundle/DependencyInjection/DoctrineExtension.php @@ -204,14 +204,29 @@ class DoctrineExtension extends LoaderExtension $namespace = str_replace('/', '\\', dirname($tmp)); $class = basename($tmp); - if (isset($bundleDirs[$namespace]) && is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Resources/config/doctrine/metadata')) + if (isset($bundleDirs[$namespace])) { - $type = $this->detectMappingType($dir); - $mappingDriverDef->addMethodCall('addDriver', array( - new Reference(sprintf('doctrine.orm.metadata_driver.%s', $type)), - $namespace.'\\'.$class.'\\Entities' - ) - ); + if (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Resources/config/doctrine/metadata')) + { + $type = $this->detectMappingType($dir); + } + elseif (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Entities')) + { + $type = 'annotation'; + } + else + { + $type = false; + } + + if (false !== $type) + { + $mappingDriverDef->addMethodCall('addDriver', array( + new Reference(sprintf('doctrine.orm.metadata_driver.%s', $type)), + $namespace.'\\'.$class.'\\Entities' + ) + ); + } } }