Skip to content

Commit

Permalink
Implemented verification of unique node type mappings.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarcher committed Nov 2, 2015
1 parent 168087e commit d6c1d66
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 2 deletions.
69 changes: 69 additions & 0 deletions CacheWarmer/UniqueNodeTypeCacheWarmer.php
@@ -0,0 +1,69 @@
<?php

/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

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);

This comment has been minimized.

Copy link
@coudenysj

coudenysj Dec 11, 2015

Looks like this is not a static method (doctrine/phpcr-odm@1.2.6...1.3.0#diff-21d202058a853ef0902f2a7f4c84e2d7R41).

Should I create a fix PR for this?

This comment has been minimized.

Copy link
@sarcher

sarcher Dec 13, 2015

Author Contributor

Good catch -- this was originally a static method, but was changed per one of the review comments, and it looks like I missed the reference in the bundle.

You are welcome to submit a PR to fix, or if you'd prefer I can. Just let me know!

This comment has been minimized.

Copy link
@coudenysj

coudenysj Dec 13, 2015

I'll submit a PR for it! Thanks for the feedback.

This comment has been minimized.

Copy link
@dbu

dbu Dec 14, 2015

Member

@wouterj already did the PR, see #245

i will investigate #244 and then release a patch version with the 2 things.

}
}
}
6 changes: 4 additions & 2 deletions DoctrinePHPCRBundle.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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')) {
Expand Down
64 changes: 64 additions & 0 deletions OptionalCommand/ODM/VerifyUniqueNodeTypesMappingCommand.php
@@ -0,0 +1,64 @@
<?php

/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

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(<<<EOT
The <info>%command.name%</info> 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);
}
}
7 changes: 7 additions & 0 deletions Resources/config/odm.xml
Expand Up @@ -37,6 +37,7 @@
<parameter key="doctrine_phpcr.odm.metadata.yml.class">Doctrine\Bundle\PHPCRBundle\Mapping\Driver\YamlDriver</parameter>
<parameter key="doctrine_phpcr.odm.metadata.php.class">Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver</parameter>
<parameter key="doctrine_phpcr.odm.proxy_cache_warmer.class">Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer</parameter>
<parameter key="doctrine_phpcr.odm.unique_node_type_cache_warmer.class">Doctrine\Bundle\PHPCRBundle\CacheWarmer\UniqueNodeTypeCacheWarmer</parameter>

<!-- validator -->
<parameter key="doctrine_phpcr.odm.validator.valid_phpcr_odm.class">Doctrine\Bundle\PHPCRBundle\Validator\Constraints\ValidPhpcrOdmValidator</parameter>
Expand All @@ -50,6 +51,12 @@
<argument type="service" id="doctrine_phpcr"/>
</service>

<service id="doctrine_phpcr.odm.unique_node_type_cache_warmer" class="%doctrine_phpcr.odm.unique_node_type_cache_warmer.class%"
public="false">
<tag name="kernel.cache_warmer"/>
<argument type="service" id="doctrine_phpcr"/>
</service>

<service id="doctrine_phpcr.odm.metadata.annotation_reader" alias="annotation_reader" public="false" />

<service
Expand Down

0 comments on commit d6c1d66

Please sign in to comment.