Skip to content

Commit

Permalink
Merge pull request doctrine#546 from ElectricMaxxx/less-nodes-then-ids
Browse files Browse the repository at this point in the history
remove not found uuids from documents to fetch
  • Loading branch information
lsmith77 committed Aug 16, 2014
2 parents 37eeb85 + 37c7324 commit 031f53a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Doctrine/ODM/PHPCR/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,18 @@ public function findMany($className, array $ids)
if (!empty($uuids)) {
$nodes = $this->session->getNodesByIdentifier(array_keys($uuids));

$countNodes = 0;
foreach ($nodes as $node) {
/** @var $node \PHPCR\NodeInterface */
$ids[$uuids[$node->getIdentifier()]] = $node->getPath();
$countNodes++;
}

if ($countNodes < count($ids)) {
// skip not found ids
$ids = array_filter($ids, function ($id) {
return !UUIDHelper::isUUID($id);
});
}
}

Expand Down
77 changes: 77 additions & 0 deletions tests/Doctrine/Tests/ODM/PHPCR/Functional/DocumentManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php


namespace Doctrine\Tests\ODM\PHPCR\Functional;

use Doctrine\ODM\PHPCR\DocumentManager;
use Doctrine\Tests\ODM\PHPCR\PHPCRFunctionalTestCase;
use PHPCR\NodeInterface;
use PHPCR\Util\UUIDHelper;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;

class DocumentManagerTest extends PHPCRFunctionalTestCase
{
/**
* @var DocumentManager
*/
private $dm;

/**
* Class name of the document class
* @var string
*/
private $type;

/**
* @var NodeInterface
*/
private $node;

public function setUp()
{
$this->dm = $this->createDocumentManager(array(__DIR__));
$this->node = $this->resetFunctionalNode($this->dm);
}

public function testFindManyWithNonExistingUuuid()
{
$user = new TestUser();
$user->username = 'test-name';
$user->id = '/functional/test';
$this->dm->persist($user);
$this->dm->flush();
$this->dm->clear();

$actualUuid = $user->uuid;
$unusedUuid = UUIDHelper::generateUUID();

$this->assertNotNull($this->dm->find(get_class($user), $user->id));
$this->assertNotNull($this->dm->find(get_class($user), $actualUuid));
$this->assertNull($this->dm->find(get_class($user), $unusedUuid));

$uuids = array($actualUuid, $unusedUuid);

$documents = $this->dm->findMany(get_class($user), $uuids);
$this->assertEquals(1, count($documents));
}
}

/**
* @PHPCRODM\Document(referenceable=true)
*
*/
class TestUser
{
/** @PHPCRODM\Id */
public $id;

/** @PHPCRODM\Node */
public $node;

/** @PHPCRODM\String */
public $username;

/** @PHPCRODM\Uuid */
public $uuid;
}

0 comments on commit 031f53a

Please sign in to comment.