Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verification of unique node type in support of real outer joins #226

Merged
merged 2 commits into from
Nov 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions CacheWarmer/UniqueNodeTypeCacheWarmer.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
6 changes: 4 additions & 2 deletions DoctrinePHPCRBundle.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 claiming to have unique node types are truly unique')
->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 claiming to use unique node types are truly 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
Original file line number Diff line number Diff line change
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