diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/CreateSchemaDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/CreateSchemaDoctrineODMCommand.php new file mode 100644 index 0000000000..37ca66dae7 --- /dev/null +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/CreateSchemaDoctrineODMCommand.php @@ -0,0 +1,44 @@ + + */ +class CreateSchemaDoctrineODMCommand extends CreateCommand +{ + protected function configure() + { + parent::configure(); + + $this + ->setName('doctrine:odm:schema:create') + ->addOption('dm', null, InputOption::PARAMETER_OPTIONAL, 'The document manager to use for this command.') + ->setHelp(<<doctrine:odm:schema:create command creates the default document manager's schema: + + ./symfony doctrine:odm:schema:create + +You can also optionally specify the name of a document manager to create the schema for: + + ./symfony doctrine:odm:schema:create --dm=default +EOT + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + DoctrineODMCommand::setApplicationDocumentManager($this->application, $input->getOption('dm')); + + parent::execute($input, $output); + } +} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php new file mode 100644 index 0000000000..aaa11726b5 --- /dev/null +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php @@ -0,0 +1,29 @@ + + */ +abstract class DoctrineODMCommand extends Command +{ + public static function setApplicationDocumentManager(Application $application, $dmName) + { + $container = $application->getKernel()->getContainer(); + $dmName = $dmName ? $dmName : 'default'; + $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName); + if (!$container->has($dmServiceName)) { + throw new \InvalidArgumentException(sprintf('Could not find Doctrine ODM DocumentManager named "%s"', $dmName)); + } + + $dm = $container->get($dmServiceName); + $helperSet = $application->getHelperSet(); + $helperSet->set(new DocumentManagerHelper($dm), 'dm'); + } +} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DropSchemaDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DropSchemaDoctrineODMCommand.php new file mode 100644 index 0000000000..69cc9a6e5c --- /dev/null +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DropSchemaDoctrineODMCommand.php @@ -0,0 +1,44 @@ + + */ +class DropSchemaDoctrineODMCommand extends DropCommand +{ + protected function configure() + { + parent::configure(); + + $this + ->setName('doctrine:odm:schema:drop') + ->addOption('dm', null, InputOption::PARAMETER_OPTIONAL, 'The document manager to use for this command.') + ->setHelp(<<doctrine:odm:schema:drop command drops the default document manager's schema: + + ./symfony doctrine:odm:schema:drop + +You can also optionally specify the name of a document manager to drop the schema for: + + ./symfony doctrine:odm:schema:drop --dm=default +EOT + ); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + DoctrineODMCommand::setApplicationDocumentManager($this->application, $input->getOption('dm')); + + parent::execute($input, $output); + } +} \ No newline at end of file