Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[DoctrineBundle] Fixes for building when you have multiple bundles wh…
…ich mixes mapping information types
  • Loading branch information
jwage authored and fabpot committed Mar 1, 2010
1 parent 1be4ff9 commit 2db073b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
Expand Up @@ -46,21 +46,32 @@ protected function configure()
*/
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);
}
}
11 changes: 8 additions & 3 deletions src/Symfony/Framework/DoctrineBundle/Command/DoctrineCommand.php
Expand Up @@ -33,6 +33,7 @@
abstract class DoctrineCommand extends Command
{
protected
$application,
$cli,
$em;

Expand Down Expand Up @@ -80,12 +81,16 @@ protected function buildDoctrineCliTaskOptions(InputInterface $input, array $opt

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);
}

/**
Expand Down
Expand Up @@ -204,14 +204,29 @@ public function ormLoad($config)
$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'
)
);
}
}
}

Expand Down

0 comments on commit 2db073b

Please sign in to comment.