Browse Source

Merge remote branch 'jwage/master'

Fabien Potencier 14 years ago
parent
commit
f4b8066acd

+ 10 - 1
src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php

@@ -58,7 +58,16 @@ EOT
                                           ->getMetadataDriverImpl()
                                           ->getMetadataDriverImpl()
                                           ->getAllClassNames();
                                           ->getAllClassNames();
 
 
-        $output->write(sprintf("Found %d entities mapped in entity manager '%s':",
+        if (!$entityClassNames) {
+            throw new \Exception(
+                'You do not have any mapped Doctrine ORM entities for any of your bundles. '.
+                'Create a class inside the Entity namespace of any of your bundles and provide '.
+                'mapping information for it with Annotations directly in the classes doc blocks '.
+                'or with XML/YAML in your bundles Resources/config/doctrine/metadata/orm directory.'
+            );
+        }
+
+        $output->write(sprintf("Found <info>%d</info> entities mapped in entity manager <info>%s</info>:\n",
             count($entityClassNames), $entityManagerName), true);
             count($entityClassNames), $entityManagerName), true);
         
         
         foreach ($entityClassNames as $entityClassName) {
         foreach ($entityClassNames as $entityClassName) {

+ 16 - 0
src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php

@@ -24,6 +24,7 @@ use Doctrine\Common\DataFixtures\Purger\ORMPurger;
 use Doctrine\ORM\EntityManager;
 use Doctrine\ORM\EntityManager;
 use Doctrine\ORM\Internal\CommitOrderCalculator;
 use Doctrine\ORM\Internal\CommitOrderCalculator;
 use Doctrine\ORM\Mapping\ClassMetadata;
 use Doctrine\ORM\Mapping\ClassMetadata;
+use InvalidArgumentException;
 
 
 /**
 /**
  * Load data fixtures from bundles.
  * Load data fixtures from bundles.
@@ -62,6 +63,16 @@ EOT
         $emName = $input->getOption('em');
         $emName = $input->getOption('em');
         $emName = $emName ? $emName : 'default';
         $emName = $emName ? $emName : 'default';
         $emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
         $emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
+
+        if (!$this->container->has($emServiceName)) {
+            throw new InvalidArgumentException(
+                sprintf(
+                    'Could not find an entity manager configured with the name "%s". Check your '.
+                    'application configuration to configure your Doctrine entity managers.', $emName
+                )
+            );
+        }
+
         $em = $this->container->get($emServiceName);
         $em = $this->container->get($emServiceName);
         $dirOrFile = $input->getOption('fixtures');
         $dirOrFile = $input->getOption('fixtures');
         if ($dirOrFile) {
         if ($dirOrFile) {
@@ -80,6 +91,11 @@ EOT
             }
             }
         }
         }
         $fixtures = $loader->getFixtures();
         $fixtures = $loader->getFixtures();
+        if (!$fixtures) {
+            throw new InvalidArgumentException(
+                sprintf('Could not find any fixtures to load in: %s', "\n\n- ".implode("\n- ", $paths))
+            );
+        }
         $purger = new ORMPurger($em);
         $purger = new ORMPurger($em);
         $executor = new ORMExecutor($em, $purger);
         $executor = new ORMExecutor($em, $purger);
         $executor->setLogger(function($message) use ($output) {
         $executor->setLogger(function($message) use ($output) {

+ 85 - 0
src/Symfony/Bundle/DoctrineMongoDBBundle/Command/InfoDoctrineODMCommand.php

@@ -0,0 +1,85 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bundle\DoctrineMongoDBBundle\Command;
+
+use Doctrine\ODM\MongoDB\Mapping\MappingException;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Show information about mapped documents
+ *
+ * @author Benjamin Eberlei <kontakt@beberlei.de>
+ * @author Jonathan H. Wage <jonwage@gmail.com>
+ */
+class InfoDoctrineODMCommand extends DoctrineODMCommand
+{
+    protected function configure()
+    {
+        $this
+            ->setName('doctrine:mongodb:mapping:info')
+            ->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.')
+            ->setDescription('Show basic information about all mapped documents.')
+            ->setHelp(<<<EOT
+The <info>doctrine:mapping:info</info> shows basic information about which
+documents exist and possibly if their mapping information contains errors or not.
+
+  <info>./app/console doctrine:mapping:info</info>
+
+If you are using multiple document managers you can pick your choice with the <info>--dm</info> option:
+
+  <info>./app/console doctrine:mapping:info --dm=default</info>
+EOT
+        );
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $documentManagerName = $input->getOption('dm') ?
+            $input->getOption('dm') :
+            $this->container->getParameter('doctrine.odm.mongodb.default_document_manager');
+
+        $documentManagerService = sprintf('doctrine.odm.mongodb.%s_document_manager', $documentManagerName);
+
+        /* @var $documentManager Doctrine\ODM\MongoDB\DocumentManager */
+        $documentManager = $this->container->get($documentManagerService);
+
+        $documentClassNames = $documentManager->getConfiguration()
+                                          ->getMetadataDriverImpl()
+                                          ->getAllClassNames();
+
+        if (!$entityClassNames) {
+            throw new \Exception(
+                'You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles. '.
+                'Create a class inside the Document namespace of any of your bundles and provide '.
+                'mapping information for it with Annotations directly in the classes doc blocks '.
+                'or with XML/YAML in your bundles Resources/config/doctrine/metadata/mongodb directory.'
+            );
+        }
+
+        $output->write(sprintf("Found <info>%d</info> documents mapped in document manager <info>%s</info>:\n",
+            count($documentClassNames), $documentManagerName), true);
+
+        foreach ($documentClassNames AS $documentClassName) {
+            try {
+                $cm = $documentManager->getClassMetadata($documentClassName);
+                $output->write("<info>[OK]</info>   " . $documentClassName, true);
+            } catch(MappingException $e) {
+                $output->write("<error>[FAIL]</error> " . $documentClassName, true);
+                $output->write("<comment>" . $e->getMessage()."</comment>", true);
+                $output->write("", true);
+            }
+        }
+    }
+}

+ 16 - 0
src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php

@@ -24,6 +24,7 @@ use Doctrine\Common\DataFixtures\Purger\MongoDBPurger;
 use Doctrine\ODM\MongoDB\DocumentManager;
 use Doctrine\ODM\MongoDB\DocumentManager;
 use Doctrine\ODM\MongoDB\Internal\CommitOrderCalculator;
 use Doctrine\ODM\MongoDB\Internal\CommitOrderCalculator;
 use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
 use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
+use InvalidArgumentException;
 
 
 /**
 /**
  * Load data fixtures from bundles.
  * Load data fixtures from bundles.
@@ -62,6 +63,16 @@ EOT
         $dmName = $input->getOption('dm');
         $dmName = $input->getOption('dm');
         $dmName = $dmName ? $dmName : 'default';
         $dmName = $dmName ? $dmName : 'default';
         $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName);
         $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName);
+
+        if (!$this->container->has($dmServiceName)) {
+            throw new InvalidArgumentException(
+                sprintf(
+                    'Could not find a document manager configured with the name "%s". Check your '.
+                    'application configuration to configure your Doctrine document managers.', $emName
+                )
+            );
+        }
+
         $dm = $this->container->get($dmServiceName);
         $dm = $this->container->get($dmServiceName);
         $dirOrFile = $input->getOption('fixtures');
         $dirOrFile = $input->getOption('fixtures');
         if ($dirOrFile) {
         if ($dirOrFile) {
@@ -79,6 +90,11 @@ EOT
                 $loader->loadFromDirectory($path);
                 $loader->loadFromDirectory($path);
             }
             }
         }
         }
+        if (!$fixtures) {
+            throw new InvalidArgumentException(
+                sprintf('Could not find any fixtures to load in: %s', "\n\n- ".implode("\n- ", $paths))
+            );
+        }
         $fixtures = $loader->getFixtures();
         $fixtures = $loader->getFixtures();
         $purger = new MongoDBPurger($dm);
         $purger = new MongoDBPurger($dm);
         $executor = new MongoDBExecutor($dm, $purger);
         $executor = new MongoDBExecutor($dm, $purger);