From ec9ba0e26bbea448ec9eb939bb65037efc62406a Mon Sep 17 00:00:00 2001 From: Toni Uebernickel Date: Fri, 25 Nov 2011 16:56:39 +0100 Subject: [PATCH] add bundle inheritance to schema processing --- Command/AbstractPropelCommand.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Command/AbstractPropelCommand.php b/Command/AbstractPropelCommand.php index 7910639..ccc103b 100644 --- a/Command/AbstractPropelCommand.php +++ b/Command/AbstractPropelCommand.php @@ -184,7 +184,15 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand $base = ltrim(realpath($kernel->getRootDir().'/..'), DIRECTORY_SEPARATOR); + $cacheFiles = array(); + $bundleSchemas = array(); + $ignoredBundles = array(); + foreach ($kernel->getBundles() as $bundle) { + if (in_array($bundle->getName(), $ignoredBundles)) { + continue; + } + if (is_dir($dir = $bundle->getPath().'/Resources/config')) { $finder = new Finder(); $schemas = $finder->files()->name('*schema.xml')->followLinks()->in($dir); @@ -193,8 +201,24 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand continue; } + // In case this is a child bundle, we ignore the parent. + if (null !== $bundle->getParent()) { + $ignoredBundles[] = $bundle->getParent(); + + // The parent schema has been added before. + // Remove the deprecated schema files. + if (!empty($bundleSchemas[$bundle->getParent()])) { + foreach ($bundleSchemas[$bundle->getParent()] as $schemaFile) { + $filesystem->remove($schemaFile); + unset($cacheFiles[$schemaFile]); + unset($this->tempSchemas[basename($schemaFile)]); + } + } + } + $packagePrefix = self::getPackagePrefix($bundle, $base); + $bundleSchemas[$bundle->getName()] = array(); foreach ($schemas as $schema) { $tempSchema = $bundle->getName().'-'.$schema->getBaseName(); $this->tempSchemas[$tempSchema] = array( @@ -206,6 +230,9 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand $file = $cacheDir.DIRECTORY_SEPARATOR.$tempSchema; $filesystem->copy((string) $schema, $file, true); + $cacheFiles[$file] = $file; + $bundleSchemas[$bundle->getName()][] = $file; + // the package needs to be set absolute // besides, the automated namespace to package conversion has // not taken place yet so it needs to be done manually