diff --git a/CacheWarmer/UniqueNodeTypeCacheWarmer.php b/CacheWarmer/UniqueNodeTypeCacheWarmer.php new file mode 100644 index 00000000..b911c1b9 --- /dev/null +++ b/CacheWarmer/UniqueNodeTypeCacheWarmer.php @@ -0,0 +1,69 @@ +. + */ + +namespace Doctrine\Bundle\PHPCRBundle\CacheWarmer; + +use Doctrine\Common\Persistence\ManagerRegistry; +use Doctrine\ODM\PHPCR\Tools\Helper\UniqueNodeTypeHelper; +use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; + +/** + * Hook the verification of uniquely mapped node types into the cache + * warming process, thereby providing a useful indication to the + * developer that something is wrong. + */ +class UniqueNodeTypeCacheWarmer implements CacheWarmerInterface +{ + /** + * @var ManagerRegistry + */ + private $registry; + + /** + * Constructor. + * + * @param ManagerRegistry $registry A ManagerRegistry instance + */ + public function __construct(ManagerRegistry $registry) + { + $this->registry = $registry; + } + + /** + * This cache warmer is optional as it is just for error + * checking and reporting back to the user. + * + * @return true + */ + public function isOptional() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function warmUp($cacheDir) + { + foreach ($this->registry->getManagers() as $documentManager) { + UniqueNodeTypeHelper::checkNodeTypeMappings($documentManager); + } + } +} diff --git a/DoctrinePHPCRBundle.php b/DoctrinePHPCRBundle.php index cb3c50b6..4ed30c3c 100644 --- a/DoctrinePHPCRBundle.php +++ b/DoctrinePHPCRBundle.php @@ -31,8 +31,9 @@ use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\InitializerPass; use Doctrine\Bundle\PHPCRBundle\OptionalCommand\Jackalope\InitDoctrineDbalCommand; use Doctrine\Bundle\PHPCRBundle\OptionalCommand\Jackalope\JackrabbitCommand; -use Doctrine\Bundle\PHPCRBundle\OptionalCommand\ODM\InfoDoctrineCommand; use Doctrine\Bundle\PHPCRBundle\OptionalCommand\ODM\DocumentMigrateClassCommand; +use Doctrine\Bundle\PHPCRBundle\OptionalCommand\ODM\InfoDoctrineCommand; +use Doctrine\Bundle\PHPCRBundle\OptionalCommand\ODM\VerifyUniqueNodeTypesMappingCommand; class DoctrinePHPCRBundle extends Bundle { @@ -62,8 +63,9 @@ public function registerCommands(Application $application) parent::registerCommands($application); if (class_exists('Doctrine\ODM\PHPCR\Version')) { - $application->add(new InfoDoctrineCommand()); $application->add(new DocumentMigrateClassCommand()); + $application->add(new InfoDoctrineCommand()); + $application->add(new VerifyUniqueNodeTypesMappingCommand()); } if (class_exists('\Jackalope\Tools\Console\Command\JackrabbitCommand')) { diff --git a/OptionalCommand/ODM/VerifyUniqueNodeTypesMappingCommand.php b/OptionalCommand/ODM/VerifyUniqueNodeTypesMappingCommand.php new file mode 100644 index 00000000..ea1559f5 --- /dev/null +++ b/OptionalCommand/ODM/VerifyUniqueNodeTypesMappingCommand.php @@ -0,0 +1,64 @@ +. + */ + +namespace Doctrine\Bundle\PHPCRBundle\OptionalCommand\ODM; + +use Doctrine\Bundle\PHPCRBundle\Command\DoctrineCommandHelper; +use Doctrine\ODM\PHPCR\Tools\Console\Command\VerifyUniqueNodeTypesMappingCommand as BaseVerifyUniqueNodeTypesMappingCommand; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Wrapper to use this command in the Symfony console with multiple sessions. + */ +class VerifyUniqueNodeTypesMappingCommand extends BaseVerifyUniqueNodeTypesMappingCommand +{ + /** + * {@inheritdoc} + */ + protected function configure() + { + parent::configure(); + + $this + ->setName('doctrine:phpcr:mapping:verify_unique_node_types') + ->setDescription('Verify that documents with unique node types are correctly mapped') + ->addOption('session', null, InputOption::VALUE_OPTIONAL, 'The session to use for this command') + ->setHelp(<<%command.name% command checks all mapped PHPCR-ODM documents +and verifies that any marked as having unique node types are, in fact, unique. +EOT + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + DoctrineCommandHelper::setApplicationDocumentManager( + $this->getApplication(), + $input->getOption('session') + ); + + parent::execute($input, $output); + } +} diff --git a/Resources/config/odm.xml b/Resources/config/odm.xml index cfc42ee8..abf483c1 100644 --- a/Resources/config/odm.xml +++ b/Resources/config/odm.xml @@ -37,6 +37,7 @@ Doctrine\Bundle\PHPCRBundle\Mapping\Driver\YamlDriver Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer + Doctrine\Bundle\PHPCRBundle\CacheWarmer\UniqueNodeTypeCacheWarmer Doctrine\Bundle\PHPCRBundle\Validator\Constraints\ValidPhpcrOdmValidator @@ -50,6 +51,12 @@ + + + + +