diff --git a/src/Symfony/Foundation/bootstrap.php b/src/Symfony/Foundation/bootstrap.php index ecaddb3e13..7e7bc6a43e 100644 --- a/src/Symfony/Foundation/bootstrap.php +++ b/src/Symfony/Foundation/bootstrap.php @@ -3,6 +3,7 @@ namespace Symfony\Foundation\Bundle; use Symfony\Components\DependencyInjection\ContainerInterface; +use Symfony\Components\Console\Application; @@ -20,6 +21,36 @@ abstract class Bundle implements BundleInterface public function shutdown(ContainerInterface $container) { } + + public function registerCommands(Application $application) + { + foreach ($application->getKernel()->getBundleDirs() as $dir) + { + $bundleBase = dirname(str_replace('\\', '/', get_class($this))); + $commandDir = $dir.'/'.basename($bundleBase).'/Command'; + if (!is_dir($commandDir)) + { + continue; + } + + foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($commandDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) + { + if ($file->isDir() || substr($file, -4) !== '.php') + { + continue; + } + + $class = str_replace('/', '\\', $bundleBase).'\\Command\\'.str_replace(realpath($commandDir).'/', '', basename(realpath($file), '.php')); + + $r = new \ReflectionClass($class); + + if ($r->isSubclassOf('Symfony\\Components\\Console\\Command\\Command') && !$r->isAbstract()) + { + $application->addCommand(new $class()); + } + } + } + } } diff --git a/src/Symfony/Framework/DoctrineBundle/Bundle.php b/src/Symfony/Framework/DoctrineBundle/Bundle.php index 6d80987968..6a2668b9f0 100644 --- a/src/Symfony/Framework/DoctrineBundle/Bundle.php +++ b/src/Symfony/Framework/DoctrineBundle/Bundle.php @@ -7,6 +7,7 @@ use Symfony\Components\DependencyInjection\ContainerInterface; use Symfony\Components\DependencyInjection\Loader\Loader; use Symfony\Components\DependencyInjection\Loader\XmlFileLoader; use Symfony\Framework\DoctrineBundle\DependencyInjection\DoctrineExtension; +use Symfony\Components\Console\Application; /* * This file is part of the Symfony framework. @@ -55,4 +56,4 @@ class Bundle extends BaseBundle $container->setParameter('doctrine.orm.metadata_driver.mapping_dirs', $metadataDirs); $container->setParameter('doctrine.orm.entity_dirs', $entityDirs); } -} +} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/BuildDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/BuildDoctrineCommand.php deleted file mode 100644 index 9599b5fafe..0000000000 --- a/src/Symfony/Framework/DoctrineBundle/Command/BuildDoctrineCommand.php +++ /dev/null @@ -1,162 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -/** - * Build command allows you to easily build and re-build your Doctrine development environment - * - * @package Symfony - * @subpackage Framework_DoctrineBundle - * @author Fabien Potencier - * @author Jonathan H. Wage - * @author Kris Wallsmith - */ -class BuildDoctrineCommand extends DoctrineCommand -{ - const - BUILD_ENTITIES = 1, - BUILD_DB = 16, - - OPTION_ENTITIES = 1, - OPTION_DB = 16, - OPTION_ALL = 31; - - /** - * @see Command - */ - protected function configure() - { - $this - ->setName('doctrine:build') - ->setDescription('Build task for easily re-building your Doctrine development environment.') - ->addOption('all', null, null, 'Build everything and reset the database') - ->addOption('entities', null, null, 'Build model classes') - ->addOption('db', null, null, 'Drop database, create database and create schema.') - ->addOption('and-load', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY, 'Load data fixtures') - ->addOption('and-append', null, InputOption::PARAMETER_OPTIONAL | InputOption::PARAMETER_IS_ARRAY, 'Load data fixtures and append to existing data') - ->addOption('and-update-schema', null, null, 'Update schema after rebuilding all classes') - ->addOption('connection', null, null, 'The connection to use.') - ->setHelp(' -The doctrine:build task builds your Doctrine development environment. - - php console doctrine:build --all - -The above command will re-build your entities and re-create your database schema. - -If you wanted to only update your schema instead of re-creating it you can run -the following: - - php console doctrine:build --entities --and-update-schema - -Now your entities are re-built and your database schema is up to date! - -You can also use the --and-load and --and-append to -load data fixtures after running another build option. - - php console doctrine:build --all --and-load - -The above will re-build everything and load all bundle data fixtures. -') - ; - } - - /** - * @see Command - * - * @throws \InvalidArgumentException When neither of any build options is included - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - if (!$mode = $this->calculateMode($input)) - { - throw new \InvalidArgumentException(sprintf("You must include one or more of the following build options:\n--%s\n\nSee this task's help page for more information:\n\n php console help doctrine:build", join(', --', array_keys($this->getBuildOptions())))); - } - - if (self::BUILD_ENTITIES == (self::BUILD_ENTITIES & $mode)) - { - $this->runCommand('doctrine:build-entities'); - } - - if (self::BUILD_DB == (self::BUILD_DB & $mode)) - { - $this->runCommand('doctrine:schema-tool', array('--re-create' => true, '--connection' => $input->getOption('connection'))); - } - - if ($input->getOption('and-update-schema')) - { - $this->runCommand('doctrine:schema-tool', array('--update' => true, '--connection' => $input->getOption('connection'))); - $this->runCommand('doctrine:schema-tool', array('--complete-update' => true, '--connection' => $input->getOption('connection'))); - } - - if ($input->hasOption('and-load')) - { - $dirOrFile = $input->getOption('and-load'); - $this->runCommand('doctrine:load-data-fixtures', - array('--dir-or-file' => $dirOrFile, '--append' => false) - ); - } - else if ($input->hasOption('and-append')) - { - $dirOrFile = $input->getOption('and-append'); - $this->runCommand('doctrine:load-data-fixtures', array('--dir-or-file' => $dirOrFile, '--append' => true)); - } - } - - /** - * Calculates a bit mode based on the supplied options. - * - * @param InputInterface $input - * @return integer - */ - protected function calculateMode(InputInterface $input) - { - $mode = 0; - foreach ($this->getBuildOptions() as $name => $value) - { - if ($input->getOption($name) === true) - { - $mode = $mode | $value; - } - } - - return $mode; - } - - /** - * Returns an array of valid build options. - * - * @return array An array of option names and their mode - */ - protected function getBuildOptions() - { - $options = array(); - foreach ($this->getDefinition()->getOptions() as $option) - { - if (defined($constant = __CLASS__.'::OPTION_'.str_replace('-', '_', strtoupper($option->getName())))) - { - $options[$option->getName()] = constant($constant); - } - } - - return $options; - } -} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/ClearCacheDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/ClearCacheDoctrineCommand.php deleted file mode 100644 index 1a09ef97ca..0000000000 --- a/src/Symfony/Framework/DoctrineBundle/Command/ClearCacheDoctrineCommand.php +++ /dev/null @@ -1,62 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -/** - * Manage the cache clearing of the Doctrine ORM. - * - * @package Symfony - * @subpackage Framework_DoctrineBundle - * @author Fabien Potencier - * @author Jonathan H. Wage - */ -class ClearCacheDoctrineCommand extends DoctrineCommand -{ - /** - * @see Command - */ - protected function configure() - { - $this - ->setName('doctrine:clear-cache') - ->setDescription('Clear cache from configured query, result and metadata drivers.') - ->setAliases(array('doctrine:cc')) - ->addOption('query', null, null, 'Clear the query cache.') - ->addOption('metadata', null, null, 'Clear the metadata cache.') - ->addOption('result', null, null, 'Clear the result cache.') - ->addOption('id', null, null, 'Clear a cache entry by its id.') - ->addOption('regex', null, null, 'Clear cache entries that match a regular expression.') - ->addOption('prefix', null, null, 'Clear cache entries that match a prefix.') - ->addOption('suffix', null, null, 'Clear cache entries that match a suffix.') - ; - } - - /** - * @see Command - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $options = $this->buildDoctrineCliTaskOptions($input, array( - 'query', 'metadata', 'result', 'id', 'regex', 'prefix', 'suffix' - )); - $this->runDoctrineCliTask('orm:clear-cache', $options); - } -} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/ClearMetadataCacheDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/ClearMetadataCacheDoctrineCommand.php new file mode 100644 index 0000000000..e8a840c923 --- /dev/null +++ b/src/Symfony/Framework/DoctrineBundle/Command/ClearMetadataCacheDoctrineCommand.php @@ -0,0 +1,42 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Command to clear the metadata cache of the various cache drivers. + * + * @package Symfony + * @subpackage Framework_DoctrineBundle + * @author Fabien Potencier + * @author Jonathan H. Wage + */ +class ClearMetadataCacheDoctrineCommand extends MetadataCommand +{ + protected function configure() + { + parent::configure(); + $this->setName('doctrine:clear-cache:metadata'); + $this->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to clear the cache for.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); + + return parent::execute($input, $output); + } +} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/ClearQueryCacheDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/ClearQueryCacheDoctrineCommand.php new file mode 100644 index 0000000000..efdc3c56ff --- /dev/null +++ b/src/Symfony/Framework/DoctrineBundle/Command/ClearQueryCacheDoctrineCommand.php @@ -0,0 +1,42 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Command to clear the query cache of the various cache drivers. + * + * @package Symfony + * @subpackage Framework_DoctrineBundle + * @author Fabien Potencier + * @author Jonathan H. Wage + */ +class ClearQueryCacheDoctrineCommand extends QueryCommand +{ + protected function configure() + { + parent::configure(); + $this->setName('doctrine:clear-cache:query'); + $this->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to clear the cache for.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); + + return parent::execute($input, $output); + } +} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/ClearResultCacheDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/ClearResultCacheDoctrineCommand.php new file mode 100644 index 0000000000..75ea42935a --- /dev/null +++ b/src/Symfony/Framework/DoctrineBundle/Command/ClearResultCacheDoctrineCommand.php @@ -0,0 +1,42 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Command to clear the result cache of the various cache drivers. + * + * @package Symfony + * @subpackage Framework_DoctrineBundle + * @author Fabien Potencier + * @author Jonathan H. Wage + */ +class ClearResultCacheDoctrineCommand extends ResultCommand +{ + protected function configure() + { + parent::configure(); + $this->setName('doctrine:clear-cache:result'); + $this->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to clear the cache for.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); + + return parent::execute($input, $output); + } +} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/ConvertMappingDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/ConvertMappingDoctrineCommand.php index e4d9718678..60e12eaa8e 100644 --- a/src/Symfony/Framework/DoctrineBundle/Command/ConvertMappingDoctrineCommand.php +++ b/src/Symfony/Framework/DoctrineBundle/Command/ConvertMappingDoctrineCommand.php @@ -7,9 +7,7 @@ use Symfony\Components\Console\Input\InputOption; use Symfony\Components\Console\Input\InputInterface; use Symfony\Components\Console\Output\OutputInterface; use Symfony\Components\Console\Output\Output; -use Symfony\Framework\WebBundle\Util\Filesystem; -use Doctrine\Common\Cli\Configuration; -use Doctrine\Common\Cli\CliController as DoctrineCliController; +use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand; /* * This file is part of the Symfony framework. @@ -29,20 +27,16 @@ use Doctrine\Common\Cli\CliController as DoctrineCliController; * @author Fabien Potencier * @author Jonathan H. Wage */ -class ConvertMappingDoctrineCommand extends DoctrineCommand +class ConvertMappingDoctrineCommand extends ConvertMappingCommand { /** * @see Command */ protected function configure() { - $this - ->setName('doctrine:convert-mapping') - ->setDescription('Convert mapping information between supported formats.') - ->addOption('from', null, null, 'The source to convert from.') - ->addOption('to', null, null, 'The type of mapping to convert to.') - ->addOption('dest', null, null, 'Where to output the converted source.') - ; + parent::configure(); + $this->setName('doctrine:convert-mapping'); + $this->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to convert the mapping information from.'); } /** @@ -50,9 +44,8 @@ class ConvertMappingDoctrineCommand extends DoctrineCommand */ protected function execute(InputInterface $input, OutputInterface $output) { - $options = $this->buildDoctrineCliTaskOptions($input, array( - 'from', 'to', 'dest' - )); - $this->runDoctrineCliTask('orm:convert-mapping', $options); + DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); + + return parent::execute($input, $output); } } \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/CreateSchemaDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/CreateSchemaDoctrineCommand.php new file mode 100644 index 0000000000..4909bbb885 --- /dev/null +++ b/src/Symfony/Framework/DoctrineBundle/Command/CreateSchemaDoctrineCommand.php @@ -0,0 +1,50 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Command to create the database schema for a set of classes based on their mappings. + * + * @package Symfony + * @subpackage Framework_DoctrineBundle + * @author Fabien Potencier + * @author Jonathan H. Wage + */ +class CreateSchemaDoctrineCommand extends CreateCommand +{ + /** + * @see Command + */ + protected function configure() + { + parent::configure(); + $this->setName('doctrine:create-schema'); + $this->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to create the schema for.'); + } + + /** + * @see Command + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); + + parent::execute($input, $output); + } +} \ 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 10913bf8e9..0167792b5b 100644 --- a/src/Symfony/Framework/DoctrineBundle/Command/DoctrineCommand.php +++ b/src/Symfony/Framework/DoctrineBundle/Command/DoctrineCommand.php @@ -10,9 +10,12 @@ use Symfony\Components\Console\Input\InputInterface; use Symfony\Components\Console\Output\OutputInterface; use Symfony\Components\Console\Output\Output; use Symfony\Framework\WebBundle\Console\Application; -use Symfony\Framework\WebBundle\Util\Filesystem; -use Doctrine\Common\Cli\Configuration; -use Doctrine\Common\Cli\CliController as DoctrineCliController; +use Symfony\Foundation\Bundle\Bundle; +use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; +use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; +use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\ORM\Mapping\ClassMetadataInfo; /* * This file is part of the Symfony framework. @@ -32,65 +35,57 @@ use Doctrine\Common\Cli\CliController as DoctrineCliController; */ abstract class DoctrineCommand extends Command { - protected - $application, - $cli, - $em; - - protected function getDoctrineCli() + public static function setApplicationEntityManager(Application $application, $emName) { - if ($this->cli === null) + $container = $application->getKernel()->getContainer(); + $emName = $emName ? $emName : 'default'; + $emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName); + if (!$container->hasService($emServiceName)) { - $configuration = new Configuration(); - $this->cli = new DoctrineCliController($configuration); + throw new \InvalidArgumentException(sprintf('Could not find Doctrine EntityManager named "%s"', $emName)); } - $em = $this->em ? $this->em : $this->container->getDoctrine_Orm_EntityManagerService(); - $this->cli->getConfiguration()->setAttribute('em', $em); - return $this->cli; + + $em = $container->getService($emServiceName); + $helperSet = $application->getHelperSet(); + $helperSet->set(new ConnectionHelper($em->getConnection()), 'db'); + $helperSet->set(new EntityManagerHelper($em), 'em'); } - protected function runDoctrineCliTask($name, $options = array()) + public static function setApplicationConnection(Application $application, $connName) { - $builtOptions = array(); - foreach ($options as $key => $value) + $container = $application->getKernel()->getContainer(); + $connName = $connName ? $connName : 'default'; + $connServiceName = sprintf('doctrine.dbal.%s_connection', $connName); + if (!$container->hasService($connServiceName)) { - if ($value === null) - { - $builtOptions[] = sprintf('--%s', $key); - } - else - { - $builtOptions[] = sprintf('--%s=%s', $key, $value); - } + throw new \InvalidArgumentException(sprintf('Could not find Doctrine Connection named "%s"', $connName)); } - return $this->getDoctrineCli()->run(array_merge(array('doctrine', $name), $builtOptions)); + + $connection = $container->getService($connServiceName); + $helperSet = $application->getHelperSet(); + $helperSet->set(new ConnectionHelper($connection), 'db'); } - protected function buildDoctrineCliTaskOptions(InputInterface $input, array $options) + protected function getEntityManager($name = null) { - $taskOptions = array(); - foreach ($options as $option) + $name = $name ? $name : 'default'; + $serviceName = sprintf('doctrine.orm.%s_entity_manager', $name); + if (!$this->container->hasService($serviceName)) { - if ($value = $input->getOption($option)) - { - $options[$option] = $value; - } + throw new \InvalidArgumentException(sprintf('Could not find Doctrine EntityManager named "%s"', $name)); } - return $options; + + return $this->container->getService($serviceName); } protected function runCommand($name, array $input = array()) { - if ($this->application === null) - { - $this->application = new Application($this->container->getKernelService()); - } - + $application = new Application($this->container->getKernelService()); $arguments = array(); $arguments = array_merge(array($name), $input); $input = new ArrayInput($arguments); - $this->application->setAutoExit(false); - $this->application->run($input); + $application->setAutoExit(false); + $application->run($input); } /** @@ -127,4 +122,45 @@ abstract class DoctrineCommand extends Command } return $entityManagers; } + + protected function getBundleMetadatas(Bundle $bundle) + { + $tmp = dirname(str_replace('\\', '/', get_class($bundle))); + $namespace = str_replace('/', '\\', dirname($tmp)); + $class = basename($tmp); + + $bundleMetadatas = array(); + $entityManagers = $this->getDoctrineEntityManagers(); + foreach ($entityManagers as $key => $em) + { + $cmf = new SymfonyDisconnectedClassMetadataFactory($em); + $metadatas = $cmf->getAllMetadata(); + foreach ($metadatas as $metadata) + { + if (strpos($metadata->name, $namespace) !== false) + { + $bundleMetadatas[] = $metadata; + } + } + } + return $bundleMetadatas; + } +} + +class SymfonyDisconnectedClassMetadataFactory extends DisconnectedClassMetadataFactory +{ + /** + * @override + */ + protected function _newClassMetadataInstance($className) + { + if (class_exists($className)) + { + return new ClassMetadata($className); + } + else + { + return new ClassMetadataInfo($className); + } + } } \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/VersionDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/DropSchemaDoctrineCommand.php similarity index 64% rename from src/Symfony/Framework/DoctrineBundle/Command/VersionDoctrineCommand.php rename to src/Symfony/Framework/DoctrineBundle/Command/DropSchemaDoctrineCommand.php index 86fe1aba0f..d1042f3595 100644 --- a/src/Symfony/Framework/DoctrineBundle/Command/VersionDoctrineCommand.php +++ b/src/Symfony/Framework/DoctrineBundle/Command/DropSchemaDoctrineCommand.php @@ -7,9 +7,7 @@ use Symfony\Components\Console\Input\InputOption; use Symfony\Components\Console\Input\InputInterface; use Symfony\Components\Console\Output\OutputInterface; use Symfony\Components\Console\Output\Output; -use Symfony\Framework\WebBundle\Util\Filesystem; -use Doctrine\Common\Cli\Configuration; -use Doctrine\Common\Cli\CliController as DoctrineCliController; +use Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand; /* * This file is part of the Symfony framework. @@ -21,24 +19,23 @@ use Doctrine\Common\Cli\CliController as DoctrineCliController; */ /** - * Check what version of the Doctrine ORM being used. + * Command to drop the database schema for a set of classes based on their mappings. * * @package Symfony * @subpackage Framework_DoctrineBundle * @author Fabien Potencier * @author Jonathan H. Wage */ -class VersionDoctrineCommand extends DoctrineCommand +class DropSchemaDoctrineCommand extends DropCommand { /** * @see Command */ protected function configure() { - $this - ->setName('doctrine:version') - ->setDescription('Displays the current installed Doctrine version.') - ; + parent::configure(); + $this->setName('doctrine:drop-schema'); + $this->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to drop the schema for.'); } /** @@ -46,6 +43,8 @@ class VersionDoctrineCommand extends DoctrineCommand */ protected function execute(InputInterface $input, OutputInterface $output) { - $this->runDoctrineCliTask('orm:version'); + DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); + + parent::execute($input, $output); } } \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/EnsureProductionSettingsDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/EnsureProductionSettingsDoctrineCommand.php index 81fac0093d..5a4863c1ec 100644 --- a/src/Symfony/Framework/DoctrineBundle/Command/EnsureProductionSettingsDoctrineCommand.php +++ b/src/Symfony/Framework/DoctrineBundle/Command/EnsureProductionSettingsDoctrineCommand.php @@ -7,9 +7,7 @@ use Symfony\Components\Console\Input\InputOption; use Symfony\Components\Console\Input\InputInterface; use Symfony\Components\Console\Output\OutputInterface; use Symfony\Components\Console\Output\Output; -use Symfony\Framework\WebBundle\Util\Filesystem; -use Doctrine\Common\Cli\Configuration; -use Doctrine\Common\Cli\CliController as DoctrineCliController; +use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand; /* * This file is part of the Symfony framework. @@ -28,17 +26,16 @@ use Doctrine\Common\Cli\CliController as DoctrineCliController; * @author Fabien Potencier * @author Jonathan H. Wage */ -class EnsureProductionSettingsDoctrineCommand extends DoctrineCommand +class EnsureProductionSettingsDoctrineCommand extends EnsureProductionSettingsCommand { /** * @see Command */ protected function configure() { - $this - ->setName('doctrine:ensure-production-settings') - ->setDescription('Verify that Doctrine is properly configured for a production environment.') - ; + parent::configure(); + $this->setName('doctrine:ensure-production-settings'); + $this->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to ensure production settings for.'); } /** @@ -46,6 +43,8 @@ class EnsureProductionSettingsDoctrineCommand extends DoctrineCommand */ protected function execute(InputInterface $input, OutputInterface $output) { - $this->runDoctrineCliTask('orm:ensure-production-settings'); + DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); + + parent::execute($input, $output); } } \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/BuildEntitiesDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php similarity index 51% rename from src/Symfony/Framework/DoctrineBundle/Command/BuildEntitiesDoctrineCommand.php rename to src/Symfony/Framework/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php index 5c6cb3131a..da503a97f8 100644 --- a/src/Symfony/Framework/DoctrineBundle/Command/BuildEntitiesDoctrineCommand.php +++ b/src/Symfony/Framework/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php @@ -7,9 +7,8 @@ use Symfony\Components\Console\Input\InputOption; use Symfony\Components\Console\Input\InputInterface; use Symfony\Components\Console\Output\OutputInterface; use Symfony\Components\Console\Output\Output; -use Symfony\Framework\WebBundle\Util\Filesystem; -use Doctrine\Common\Cli\Configuration; -use Doctrine\Common\Cli\CliController as DoctrineCliController; +use Symfony\Foundation\Bundle\Bundle; +use Doctrine\ORM\Tools\EntityGenerator; /* * This file is part of the Symfony framework. @@ -21,32 +20,36 @@ use Doctrine\Common\Cli\CliController as DoctrineCliController; */ /** - * Build all Bundle entity classes from mapping information. + * Generate entity classes from mapping information * * @package Symfony * @subpackage Framework_DoctrineBundle * @author Fabien Potencier * @author Jonathan H. Wage */ -class BuildEntitiesDoctrineCommand extends DoctrineCommand +class GenerateEntitiesDoctrineCommand extends DoctrineCommand { - /** - * @see Command - */ protected function configure() { - $this - ->setName('doctrine:build-entities') - ->setDescription('Build all Bundle entity classes from mapping information.') - ; + $this + ->setName('doctrine:generate-entities') + ->setDescription('Generate entity classes and method stubs from your mapping information.') + ->setHelp(<<setGenerateAnnotations(false); + $entityGenerator->setGenerateStubMethods(true); + $entityGenerator->setRegenerateEntityIfExists(false); + $entityGenerator->setUpdateEntityIfExists(true); + $entityGenerator->setNumSpaces(2); + $bundleDirs = $this->container->getKernelService()->getBundleDirs(); foreach ($this->container->getKernelService()->getBundles() as $bundle) { @@ -56,24 +59,17 @@ class BuildEntitiesDoctrineCommand extends DoctrineCommand if (isset($bundleDirs[$namespace])) { - if (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Resources/config/doctrine/metadata')) + $destination = realpath($bundleDirs[$namespace].'/..'); + if ($metadatas = $this->getBundleMetadatas($bundle)) { - $this->convertMapping($dir, $bundleDirs[$namespace].'/..'); - } - else if (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Entities')) - { - $this->convertMapping($dir, $bundleDirs[$namespace].'/..'); + $output->writeln(sprintf('Generating entities for "%s"', $class)); + foreach ($metadatas as $metadata) + { + $output->writeln(sprintf(' > generating %s', $metadata->name)); + $entityGenerator->generate(array($metadata), $destination); + } } } } } - - 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/GenerateEntityDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php new file mode 100644 index 0000000000..8d8ab847ad --- /dev/null +++ b/src/Symfony/Framework/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php @@ -0,0 +1,144 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Initialize a new Doctrine entity inside a bundle. + * + * @package Symfony + * @subpackage Framework_DoctrineBundle + * @author Fabien Potencier + * @author Jonathan H. Wage + */ +class GenerateEntityDoctrineCommand extends DoctrineCommand +{ + /** + * @see Command + */ + protected function configure() + { + $this + ->setName('doctrine:generate-entity') + ->setDescription('Generate a new Doctrine entity inside a bundle.') + ->addArgument('bundle', null, InputArgument::REQUIRED, 'The bundle to initialize the entity in.') + ->addArgument('entity', null, InputArgument::REQUIRED, 'The entity class to initialize.') + ->addOption('mapping-type', null, InputOption::PARAMETER_OPTIONAL, 'The mapping type to to use for the entity.') + ->addOption('fields', null, InputOption::PARAMETER_OPTIONAL, 'The fields to create with the new entity.') + ->setHelp(' +The doctrine:generate-entity task initializes a new Doctrine entity inside a bundle: + + php console doctrine:generate-entity "Bundle\MyCustomBundle" "User\Group" + +The above would initialize a new entity in the following entity namespace Bundle\MyCustomBundle\Entities\User\Group. + +You can also optionally specify the fields you want to generate in the new entity: + + php console doctrine:generate-entity "Bundle\MyCustomBundle" "User\Group" --fields="name:string(255) description:text" + ') + ; + } + + /** + * @see Command + * + * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle\MySampleBundle") + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + if (!preg_match('/Bundle$/', $bundle = $input->getArgument('bundle'))) + { + throw new \InvalidArgumentException('The bundle name must end with Bundle. Example: "Bundle\MySampleBundle".'); + } + + $dirs = $this->container->getKernelService()->getBundleDirs(); + + $tmp = str_replace('\\', '/', $bundle); + $namespace = str_replace('/', '\\', dirname($tmp)); + $bundle = basename($tmp); + + if (!isset($dirs[$namespace])) + { + throw new \InvalidArgumentException(sprintf('Unable to initialize the bundle entity (%s not defined).', $namespace)); + } + + $entity = $input->getArgument('entity'); + $entityNamespace = $namespace.'\\'.$bundle.'\\Entities'; + $fullEntityClassName = $entityNamespace.'\\'.$entity; + $tmp = str_replace('\\', '/', $fullEntityClassName); + $tmp = str_replace('/', '\\', dirname($tmp)); + $className = basename($tmp); + $mappingType = $input->getOption('mapping-type'); + $mappingType = $mappingType ? $mappingType : 'xml'; + + $class = new ClassMetadataInfo($fullEntityClassName); + $class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); + $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO); + + // Map the specified fields + $fields = $input->getOption('fields'); + $e = explode(' ', $fields); + foreach ($e as $value) + { + $e = explode(':', $value); + $name = $e[0]; + $type = isset($e[1]) ? $e[1] : 'string'; + preg_match_all('/(.*)\((.*)\)/', $type, $matches); + $type = isset($matches[1][0]) ? $matches[1][0] : 'string'; + $length = isset($matches[2][0]) ? $matches[2][0] : null; + $class->mapField(array( + 'fieldName' => $name, + 'type' => $type, + 'length' => $length + )); + } + + // Setup a new exporter for the mapping type specified + $cme = new ClassMetadataExporter(); + $exporter = $cme->getExporter($mappingType); + + if ($mappingType === 'annotation') + { + $path = $dirs[$namespace].'/'.$bundle.'/Entities/'.str_replace($entityNamespace.'\\', null, $fullEntityClassName).'.php'; + + $entityGenerator = new EntityGenerator(); + $entityGenerator->setGenerateAnnotations(false); + $entityGenerator->setGenerateStubMethods(true); + $entityGenerator->setRegenerateEntityIfExists(false); + $entityGenerator->setUpdateEntityIfExists(false); + $entityGenerator->setNumSpaces(2); + + $exporter->setEntityGenerator($entityGenerator); + } else { + $path = $dirs[$namespace].'/'.$bundle.'/Resources/config/doctrine/metadata/'.str_replace('\\', '.', $fullEntityClassName).'.dcm.xml'; + } + + $code = $exporter->exportClassMetadata($class); + + if (!is_dir($dir = dirname($path))) + { + mkdir($dir, 0777, true); + } + + file_put_contents($path, $code); + + $this->runCommand('doctrine:generate-entities'); + } +} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/GenerateProxiesDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/GenerateProxiesDoctrineCommand.php index 8883a33e1b..791810fad5 100644 --- a/src/Symfony/Framework/DoctrineBundle/Command/GenerateProxiesDoctrineCommand.php +++ b/src/Symfony/Framework/DoctrineBundle/Command/GenerateProxiesDoctrineCommand.php @@ -7,7 +7,7 @@ use Symfony\Components\Console\Input\InputOption; use Symfony\Components\Console\Input\InputInterface; use Symfony\Components\Console\Output\OutputInterface; use Symfony\Components\Console\Output\Output; -use Symfony\Framework\WebBundle\Util\Filesystem; +use Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand; /* * This file is part of the Symfony framework. @@ -24,18 +24,18 @@ use Symfony\Framework\WebBundle\Util\Filesystem; * @package Symfony * @subpackage Framework_DoctrineBundle * @author Fabien Potencier + * @author Jonathan H. Wage */ -class GenerateProxiesDoctrineCommand extends DoctrineCommand +class GenerateProxiesDoctrineCommand extends GenerateProxiesCommand { /** * @see Command */ protected function configure() { - $this - ->setName('doctrine:generate-proxies') - ->setDescription('Generates proxy classes for entity classes.') - ; + parent::configure(); + $this->setName('doctrine:generate-proxies'); + $this->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to generate proxies for.'); } /** @@ -43,28 +43,8 @@ class GenerateProxiesDoctrineCommand extends DoctrineCommand */ protected function execute(InputInterface $input, OutputInterface $output) { - $dirs = array(); - $bundleDirs = $this->container->getKernelService()->getBundleDirs(); - foreach ($this->container->getKernelService()->getBundles() as $bundle) - { - $tmp = dirname(str_replace('\\', '/', get_class($bundle))); - $namespace = str_replace('/', '\\', dirname($tmp)); - $class = basename($tmp); + DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); - if (isset($bundleDirs[$namespace]) && is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Entities')) - { - $dirs[] = $dir; - } - } - - if (!is_dir($dir = $this->container->getParameter('kernel.cache_dir').'/doctrine/Proxies')) - { - mkdir($dir, 0777, true); - } - - foreach ($dirs as $dir) - { - $this->runDoctrineCliTask('orm:generate-proxies', array('class-dir' => $dir)); - } + return parent::execute($input, $output); } -} +} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/GenerateRepositoriesDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/GenerateRepositoriesDoctrineCommand.php new file mode 100644 index 0000000000..552941b6cc --- /dev/null +++ b/src/Symfony/Framework/DoctrineBundle/Command/GenerateRepositoriesDoctrineCommand.php @@ -0,0 +1,63 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Command to generate repository classes for mapping information. + * + * @package Symfony + * @subpackage Framework_DoctrineBundle + * @author Fabien Potencier + * @author Jonathan H. Wage + */ +class GenerateRepositoriesDoctrineCommand extends DoctrineCommand +{ + protected function configure() + { + $this->setName('doctrine:generate-repositories'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $generator = new EntityRepositoryGenerator(); + $kernel = $this->application->getKernel(); + $bundleDirs = $kernel->getBundleDirs(); + foreach ($kernel->getBundles() as $bundle) + { + $tmp = dirname(str_replace('\\', '/', get_class($bundle))); + $namespace = str_replace('/', '\\', dirname($tmp)); + $class = basename($tmp); + + if (isset($bundleDirs[$namespace])) + { + $destination = realpath($bundleDirs[$namespace].'/..'); + if ($metadatas = $this->getBundleMetadatas($bundle)) + { + $output->writeln(sprintf('Generating entity repositories for "%s"', $class)); + foreach ($metadatas as $metadata) + { + if ($metadata->customRepositoryClassName) + { + $output->writeln(sprintf(' > generating %s', $metadata->customRepositoryClassName)); + $generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destination); + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/ImportMappingDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/ImportMappingDoctrineCommand.php deleted file mode 100644 index 8e8906eaae..0000000000 --- a/src/Symfony/Framework/DoctrineBundle/Command/ImportMappingDoctrineCommand.php +++ /dev/null @@ -1,83 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -/** - * Import the initial mapping information for entities from an existing database - * into a bundle. - * - * @package Symfony - * @subpackage Framework_DoctrineBundle - * @author Fabien Potencier - * @author Jonathan H. Wage - */ -class ImportMappingDoctrineCommand extends DoctrineCommand -{ - /** - * @see Command - */ - protected function configure() - { - $this - ->setName('doctrine:import-mapping') - ->setDescription('Import the initial mapping information for entities from an existing database.') - ->addOption('connection', null, InputOption::PARAMETER_REQUIRED, 'The connection import from.') - ->addOption('bundle', null, InputOption::PARAMETER_REQUIRED, 'The bundle to import the mapping information to.') - ->addOption('type', null, InputOption::PARAMETER_OPTIONAL, 'The mapping format type to generate (defaults to xml).', 'xml') - ; - } - - /** - * @see Command - * - * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle\MySampleBundle") - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - if (!preg_match('/Bundle$/', $bundle = $input->getOption('bundle'))) - { - throw new \InvalidArgumentException('The bundle must end with Bundle.'); - } - - $dirs = $this->container->getKernelService()->getBundleDirs(); - - $tmp = str_replace('\\', '/', $bundle); - $namespace = str_replace('/', '\\', dirname($tmp)); - $bundle = basename($tmp); - - if (!isset($dirs[$namespace])) - { - throw new \InvalidArgumentException(sprintf('Could not find namespace "%s" for bundle "%s".', $namespace, $bundle)); - } - - $path = $dirs[$namespace].'/'.$bundle.'/Resources/config/doctrine/metadata'; - - if (!is_dir($path)) - { - mkdir($path, 0777, true); - } - - $this->em = $this->container->getService(sprintf('doctrine.orm.%s_entity_manager', $input->getOption('connection'))); - $this->runCommand('doctrine:convert-mapping', array( - '--from' => 'database', - '--to' => $input->getOption('type'), - '--dest' => $path - ) - ); - } -} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/InitEntityDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/InitEntityDoctrineCommand.php deleted file mode 100644 index 2806ed5269..0000000000 --- a/src/Symfony/Framework/DoctrineBundle/Command/InitEntityDoctrineCommand.php +++ /dev/null @@ -1,118 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -/** - * Initialize a new Doctrine entity inside a bundle. - * - * @package Symfony - * @subpackage Framework_DoctrineBundle - * @author Fabien Potencier - * @author Jonathan H. Wage - */ -class InitEntityDoctrineCommand extends DoctrineCommand -{ - /** - * @see Command - */ - protected function configure() - { - $this - ->setName('doctrine:init-entity') - ->setDescription('Initialize a new Doctrine entity inside a bundle.') - ->addOption('bundle', null, InputOption::PARAMETER_REQUIRED, 'The bundle to initialize the entity in.') - ->addOption('entity', null, InputOption::PARAMETER_REQUIRED, 'The entity class to initialize.') - ->setHelp(' -The doctrine:init-entity task initializes a new Doctrine entity inside a bundle: - - php console doctrine:init-entity --bundle="Bundle\MyCustomBundle" --entity="User\Group" - -The above would initialize a new entity in the following entity namespace Bundle\MyCustomBundle\Entities\User\Group. - -You can now build your entities and update your database schema: - - php console doctrine:build --entities --and-update-schema - -Now you have a new entity and your database has been updated. - ') - ; - } - - /** - * @see Command - * - * @throws \InvalidArgumentException When the bundle doesn't end with Bundle (Example: "Bundle\MySampleBundle") - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - if (!preg_match('/Bundle$/', $bundle = $input->getOption('bundle'))) - { - throw new \InvalidArgumentException('The bundle name must end with Bundle. Example: "Bundle\MySampleBundle".'); - } - - $dirs = $this->container->getKernelService()->getBundleDirs(); - - $tmp = str_replace('\\', '/', $bundle); - $namespace = str_replace('/', '\\', dirname($tmp)); - $bundle = basename($tmp); - - if (!isset($dirs[$namespace])) - { - throw new \InvalidArgumentException(sprintf('Unable to initialize the bundle entity (%s not defined).', $namespace)); - } - - $entity = $input->getOption('entity'); - $entityNamespace = $namespace.'\\'.$bundle.'\\Entities'; - $fullEntityClassName = $entityNamespace.'\\'.$entity; - $tmp = str_replace('\\', '/', $fullEntityClassName); - $tmp = str_replace('/', '\\', dirname($tmp)); - $className = basename($tmp); - - $extends = null; - $path = $dirs[$namespace].'/'.$bundle.'/Resources/config/doctrine/metadata/'.str_replace('\\', '.', $fullEntityClassName).'.dcm.xml'; - - $xml = sprintf(' - - - - - - - - - -', - $fullEntityClassName, - str_replace('\\', '_', strtolower($entity)) - ); - - if (!is_dir($dir = dirname($path))) - { - mkdir($dir, 0777, true); - } - - file_put_contents($path, $xml); - $this->runCommand('doctrine:build-entities'); - } -} diff --git a/src/Symfony/Framework/DoctrineBundle/Command/RunDqlDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/RunDqlDoctrineCommand.php index 9604b7396f..7ee074f6cd 100644 --- a/src/Symfony/Framework/DoctrineBundle/Command/RunDqlDoctrineCommand.php +++ b/src/Symfony/Framework/DoctrineBundle/Command/RunDqlDoctrineCommand.php @@ -7,9 +7,7 @@ use Symfony\Components\Console\Input\InputOption; use Symfony\Components\Console\Input\InputInterface; use Symfony\Components\Console\Output\OutputInterface; use Symfony\Components\Console\Output\Output; -use Symfony\Framework\WebBundle\Util\Filesystem; -use Doctrine\Common\Cli\Configuration; -use Doctrine\Common\Cli\CliController as DoctrineCliController; +use Doctrine\ORM\Tools\Console\Command\RunDqlCommand; /* * This file is part of the Symfony framework. @@ -28,20 +26,16 @@ use Doctrine\Common\Cli\CliController as DoctrineCliController; * @author Fabien Potencier * @author Jonathan H. Wage */ -class RunDqlDoctrineCommand extends DoctrineCommand +class RunDqlDoctrineCommand extends RunDqlCommand { /** * @see Command */ protected function configure() { - $this - ->setName('doctrine:run-dql') - ->setDescription('Executes arbitrary DQL directly from the command line.') - ->addOption('dql', null, null, 'The DQL query to run.') - ->addOption('depth', null, null, 'The depth to output the data to.') - ->addOption('connection', null, null, 'The connection to use.') - ; + parent::configure(); + $this->setName('doctrine:run-dql'); + $this->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to execute the DQL query on.'); } /** @@ -49,9 +43,8 @@ class RunDqlDoctrineCommand extends DoctrineCommand */ protected function execute(InputInterface $input, OutputInterface $output) { - $options = $this->buildDoctrineCliTaskOptions($input, array( - 'dql', 'depth' - )); - $this->runDoctrineCliTask('orm:run-dql', $options); + DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); + + return parent::execute($input, $output); } } \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/RunSqlDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/RunSqlDoctrineCommand.php index 4f147a0f1a..16afad28ae 100644 --- a/src/Symfony/Framework/DoctrineBundle/Command/RunSqlDoctrineCommand.php +++ b/src/Symfony/Framework/DoctrineBundle/Command/RunSqlDoctrineCommand.php @@ -7,9 +7,7 @@ use Symfony\Components\Console\Input\InputOption; use Symfony\Components\Console\Input\InputInterface; use Symfony\Components\Console\Output\OutputInterface; use Symfony\Components\Console\Output\Output; -use Symfony\Framework\WebBundle\Util\Filesystem; -use Doctrine\Common\Cli\Configuration; -use Doctrine\Common\Cli\CliController as DoctrineCliController; +use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; /* * This file is part of the Symfony framework. @@ -28,31 +26,25 @@ use Doctrine\Common\Cli\CliController as DoctrineCliController; * @author Fabien Potencier * @author Jonathan H. Wage */ -class RunSqlDoctrineCommand extends DoctrineCommand +class RunSqlDoctrineCommand extends RunSqlCommand { /** - * @see Command + * @see RunSqlCommand */ protected function configure() { - $this - ->setName('doctrine:run-sql') - ->setDescription('Executes arbitrary SQL from a file or directly from the command line.') - ->addOption('sql', null, null, 'The SQL query to run.') - ->addOption('file', null, null, 'Path to a SQL file to run.') - ->addOption('depth', null, null, 'The depth to output the data to.') - ->addOption('connection', null, null, 'The connection to use.') - ; + parent::configure(); + $this->setName('doctrine:run-sql'); + $this->addOption('connection', null, null, 'The connection to execute the SQL query on.'); } /** - * @see Command + * @see RunSqlCommand */ protected function execute(InputInterface $input, OutputInterface $output) { - $options = $this->buildDoctrineCliTaskOptions($input, array( - 'sql', 'file', 'depth' - )); - $this->runDoctrineCliTask('dbal:run-sql', $options); + DoctrineCommand::setApplicationConnection($this->application, $input->getOption('connection')); + + return parent::execute($input, $output); } } \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/SchemaToolDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/SchemaToolDoctrineCommand.php deleted file mode 100644 index b3e33e2f0a..0000000000 --- a/src/Symfony/Framework/DoctrineBundle/Command/SchemaToolDoctrineCommand.php +++ /dev/null @@ -1,88 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -/** - * Create, drop, and update your Doctrine ORM schema in the DBMS. - * - * @package Symfony - * @subpackage Framework_DoctrineBundle - * @author Fabien Potencier - * @author Jonathan H. Wage - */ -class SchemaToolDoctrineCommand extends DoctrineCommand -{ - /** - * @see Command - */ - protected function configure() - { - $this - ->setName('doctrine:schema-tool') - ->setDescription('Processes the schema and either apply it directly on EntityManager or generate the SQL output.') - ->addOption('create', null, null, 'Create your database schema.') - ->addOption('drop', null, null, 'Drop your database schema.') - ->addOption('update', null, null, 'Update your database schema and add anything that is not in your database but exists in your schema.') - ->addOption('complete-update', null, null, 'Complete update and drop anything that is not in your schema.') - ->addOption('re-create', null, null, 'Drop and re-create your database schema.') - ->addOption('dump-sql', null, null, 'Dump the SQL instead of executing it.') - ->addOption('connection', null, null, 'The connection to use.') - ; - } - - /** - * @see Command - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $options = $this->buildDoctrineCliTaskOptions($input, array( - 'create', 'drop', 'update', 'complete-update', 're-create', 'dump-sql' - )); - - $entityDirs = $this->container->getParameter('doctrine.orm.entity_dirs'); - $options['class-dir'] = implode(', ', $entityDirs); - - $found = false; - $ems = $this->getDoctrineEntityManagers(); - foreach ($ems as $name => $em) - { - if ($input->getOption('connection') && $name !== $input->getOption('connection')) - { - continue; - } - $this->em = $em; - $this->runDoctrineCliTask('orm:schema-tool', $options); - $found = true; - } - - if ($found === false) - { - if ($input->getOption('connection')) - { - $output->writeln(sprintf('Could not find a connection named %s', $input->getOption('connection'))); - } - else - { - $output->writeln(sprintf('Could not find any configured connections', $input->getOption('connection'))); - } - } - } -} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/Command/UpdateSchemaDoctrineCommand.php b/src/Symfony/Framework/DoctrineBundle/Command/UpdateSchemaDoctrineCommand.php new file mode 100644 index 0000000000..2b55739190 --- /dev/null +++ b/src/Symfony/Framework/DoctrineBundle/Command/UpdateSchemaDoctrineCommand.php @@ -0,0 +1,50 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Command to update the database schema for a set of classes based on their mappings. + * + * @package Symfony + * @subpackage Framework_DoctrineBundle + * @author Fabien Potencier + * @author Jonathan H. Wage + */ +class UpdateSchemaDoctrineCommand extends UpdateCommand +{ + /** + * @see Command + */ + protected function configure() + { + parent::configure(); + $this->setName('doctrine:update-schema'); + $this->addOption('em', null, InputOption::PARAMETER_OPTIONAL, 'The entity manager to update the schema for.'); + } + + /** + * @see Command + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + DoctrineCommand::setApplicationEntityManager($this->application, $input->getOption('em')); + + parent::execute($input, $output); + } +} \ No newline at end of file diff --git a/src/Symfony/Framework/DoctrineBundle/DependencyInjection/DoctrineExtension.php b/src/Symfony/Framework/DoctrineBundle/DependencyInjection/DoctrineExtension.php index aeb54aaa37..367d4e0df6 100644 --- a/src/Symfony/Framework/DoctrineBundle/DependencyInjection/DoctrineExtension.php +++ b/src/Symfony/Framework/DoctrineBundle/DependencyInjection/DoctrineExtension.php @@ -220,8 +220,10 @@ class DoctrineExtension extends LoaderExtension if (is_dir($dir = $bundleDirs[$namespace].'/'.$class.'/Entities')) { - $type = 'annotation'; - + if ($type === false) + { + $type = 'annotation'; + } $aliasMap[$class] = $namespace.'\\'.$class.'\\Entities'; }