diff --git a/lib/HireVoice/Neo4j/EntityManager.php b/lib/HireVoice/Neo4j/EntityManager.php index 8864394..418b72c 100644 --- a/lib/HireVoice/Neo4j/EntityManager.php +++ b/lib/HireVoice/Neo4j/EntityManager.php @@ -126,19 +126,23 @@ private function removeEntities() if ($id){ $node = $this->client->getNode($id); - $class = $meta->getName(); - $index = $this->getRepository($class)->getIndex(); - $index->remove($node); + if($node){ + $class = $meta->getName(); + $index = $this->getRepository($class)->getIndex(); + $index->remove($node); + + $relationships = $node->getRelationships(); + foreach ($relationships as $relationship){ + $relationship->delete(); + } - $relationships = $node->getRelationships(); - foreach ($relationships as $relationship){ - $relationship->delete(); + $node->delete(); } - - $node->delete(); } } + $this->entitiesToRemove = Array(); + $this->commit(); } diff --git a/lib/HireVoice/Neo4j/Tests/EntityManagerTest.php b/lib/HireVoice/Neo4j/Tests/EntityManagerTest.php index a114029..84b6288 100644 --- a/lib/HireVoice/Neo4j/Tests/EntityManagerTest.php +++ b/lib/HireVoice/Neo4j/Tests/EntityManagerTest.php @@ -712,6 +712,33 @@ function testStoreLabeledEntity() $this->assertEquals("Location", $city->offsetGet(0)); $this->assertEquals("City", $city->offsetGet(1)); } + + /** + * Check the fix of issue #54. + */ + function testRemoveEntity() + { + $entity = new Entity\Movie; + $entity->setTitle('Jules et Jim'); + + $em = $this->getEntityManager(); + $em->persist($entity); + $em->flush(); + + $em->remove($entity); + $em->flush(); + + $entity2 = new Entity\Movie; + $entity2->setTitle('Rois et reine'); + $em->persist($entity2); + $em->flush(); + + // one only checks that a second flush + // after a remove does not throw an exception + // if not the test is ok. + + $this->assertTrue(true); + } } /**