[DoctrineBundle] Fixes for building when you have multiple bundles which mixes mapping information types

This commit is contained in:
Jonathan H. Wage 2010-02-25 20:29:39 -05:00 committed by Fabien Potencier
parent 1be4ff9095
commit 2db073b03a
3 changed files with 51 additions and 20 deletions

View File

@ -46,21 +46,32 @@ class BuildEntitiesDoctrineCommand extends DoctrineCommand
*/ */
protected function execute(InputInterface $input, OutputInterface $output) 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'); $tmp = dirname(str_replace('\\', '/', get_class($bundle)));
foreach ($bundles as $p) $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);
}
} }

View File

@ -33,6 +33,7 @@ use Doctrine\Common\Cli\CliController as DoctrineCliController;
abstract class DoctrineCommand extends Command abstract class DoctrineCommand extends Command
{ {
protected protected
$application,
$cli, $cli,
$em; $em;
@ -80,12 +81,16 @@ abstract class DoctrineCommand extends Command
protected function runCommand($name, array $input = array()) protected function runCommand($name, array $input = array())
{ {
if ($this->application === null)
{
$this->application = new Application($this->container->getKernelService());
}
$arguments = array(); $arguments = array();
$arguments = array_merge(array($name), $input); $arguments = array_merge(array($name), $input);
$input = new ArrayInput($arguments); $input = new ArrayInput($arguments);
$application = new Application($this->container->getKernelService()); $this->application->setAutoExit(false);
$application->setAutoExit(false); $this->application->run($input);
$application->run($input);
} }
/** /**

View File

@ -204,14 +204,29 @@ class DoctrineExtension extends LoaderExtension
$namespace = str_replace('/', '\\', dirname($tmp)); $namespace = str_replace('/', '\\', dirname($tmp));
$class = basename($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); if (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Resources/config/doctrine/metadata'))
$mappingDriverDef->addMethodCall('addDriver', array( {
new Reference(sprintf('doctrine.orm.metadata_driver.%s', $type)), $type = $this->detectMappingType($dir);
$namespace.'\\'.$class.'\\Entities' }
) 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'
)
);
}
} }
} }