-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #667 from sarcher/left-join
Specify unique node types via mapping to allow proper outer joins
- Loading branch information
Showing
18 changed files
with
467 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,9 @@ class Document | |
* @var boolean | ||
*/ | ||
public $referenceable; | ||
|
||
/** | ||
* @var boolean | ||
*/ | ||
public $uniqueNodeType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
lib/Doctrine/ODM/PHPCR/Tools/Console/Command/VerifyUniqueNodeTypesMappingCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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\ODM\PHPCR\Tools\Console\Command; | ||
|
||
use Doctrine\ODM\PHPCR\Tools\Helper\UniqueNodeTypeHelper; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Verify that any documents which are mapped as having unique | ||
* node types are truly unique. | ||
*/ | ||
class VerifyUniqueNodeTypesMappingCommand extends Command | ||
{ | ||
/** | ||
* {@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') | ||
->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) | ||
{ | ||
$documentManager = $this->getHelper('phpcr')->getDocumentManager(); | ||
$uniqueNodeTypeHelper = new UniqueNodeTypeHelper(); | ||
|
||
$debugInformation = $uniqueNodeTypeHelper->checkNodeTypeMappings($documentManager); | ||
|
||
if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) { | ||
foreach ($debugInformation as $className => $debug) { | ||
$output->writeln(sprintf( | ||
'The document <info>%s</info> uses %snode type <info>%s</info>', | ||
$className, | ||
$debug['unique_node_type'] ? '<comment>uniquely mapped</comment> ' : '', | ||
$debug['node_type'] | ||
)); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
lib/Doctrine/ODM/PHPCR/Tools/Helper/UniqueNodeTypeHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?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\ODM\PHPCR\Tools\Helper; | ||
|
||
use Doctrine\ODM\PHPCR\DocumentManagerInterface; | ||
use Doctrine\ODM\PHPCR\Mapping\MappingException; | ||
|
||
/** | ||
* Provides unique node type mapping verification. | ||
*/ | ||
class UniqueNodeTypeHelper | ||
{ | ||
/** | ||
* Check each mapped PHPCR-ODM document for the given document manager, | ||
* throwing an exception if any document is set to use a unique node | ||
* type but the node type is re-used. Returns an array of debug information. | ||
* | ||
* @param DocumentManagerInterface $documentManager The document manager to check mappings for. | ||
* | ||
* @return array | ||
* | ||
* @throws MappingException | ||
*/ | ||
public function checkNodeTypeMappings(DocumentManagerInterface $documentManager) | ||
{ | ||
$knownNodeTypes = array(); | ||
$debugInformation = array(); | ||
$allMetadata = $documentManager->getMetadataFactory()->getAllMetadata(); | ||
|
||
foreach ($allMetadata as $classMetadata) { | ||
if ($classMetadata->hasUniqueNodeType() && isset($knownNodeTypes[$classMetadata->getNodeType()])) { | ||
throw new MappingException(sprintf( | ||
'The class "%s" is mapped with uniqueNodeType set to true, but the node type "%s" is used by "%s" as well.', | ||
$classMetadata->name, | ||
$classMetadata->getNodeType(), | ||
$knownNodeTypes[$classMetadata->getNodeType()] | ||
)); | ||
} | ||
|
||
$knownNodeTypes[$classMetadata->getNodeType()] = $classMetadata->name; | ||
|
||
$debugInformation[$classMetadata->name] = array( | ||
'unique_node_type' => $classMetadata->hasUniqueNodeType(), | ||
'node_type' => $classMetadata->getNodeType() | ||
); | ||
} | ||
|
||
return $debugInformation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\CMS; | ||
|
||
use Doctrine\ODM\PHPCR\DocumentRepository; | ||
use Doctrine\ODM\PHPCR\Id\RepositoryIdInterface; | ||
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM; | ||
|
||
/** | ||
* @PHPCRODM\Document( | ||
* nodeType="phpcr:cms_profile", | ||
* referenceable=true, | ||
* repositoryClass="Doctrine\Tests\Models\CMS\CmsProfileRepository", | ||
* uniqueNodeType=true | ||
* ) | ||
*/ | ||
class CmsProfile | ||
{ | ||
/** @PHPCRODM\Id(strategy="repository") */ | ||
public $id; | ||
|
||
/** @PHPCRODM\Uuid */ | ||
public $uuid; | ||
|
||
/** @PHPCRODM\Field(type="string") */ | ||
public $data; | ||
|
||
/** @PHPCRODM\ReferenceOne(targetDocument="CmsUser", cascade="persist") */ | ||
public $user; | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getUuid() | ||
{ | ||
return $this->uuid; | ||
} | ||
|
||
public function setData($data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
public function getData() | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function setUser(CmsUser $user) | ||
{ | ||
$this->user = $user; | ||
} | ||
|
||
public function getUser() | ||
{ | ||
return $this->user; | ||
} | ||
} | ||
|
||
class CmsProfileRepository extends DocumentRepository implements RepositoryIdInterface | ||
{ | ||
/** | ||
* Generate a document id | ||
* | ||
* @param object $document | ||
* @return string | ||
*/ | ||
public function generateId($document, $parent = null) | ||
{ | ||
return '/functional/' . $document->user->username . '/' . $document->data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.