DDC-1034 - Fix bug where callbacks where registered multiple times in inheritance hierachies.
This commit is contained in:
parent
c0d26f2308
commit
67ae22b911
@ -377,7 +377,8 @@ class AnnotationDriver implements Driver
|
||||
// Evaluate @HasLifecycleCallbacks annotation
|
||||
if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
|
||||
foreach ($class->getMethods() as $method) {
|
||||
if ($method->isPublic()) {
|
||||
// filter for the declaring class only, callbacks from parents will already be registered.
|
||||
if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) {
|
||||
$annotations = $this->_reader->getMethodAnnotations($method);
|
||||
|
||||
if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) {
|
||||
|
@ -167,6 +167,26 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
|
||||
"superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'.");
|
||||
$usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1034
|
||||
*/
|
||||
public function testInheritanceSkipsParentLifecycleCallbacks()
|
||||
{
|
||||
$annotationDriver = $this->_loadDriver();
|
||||
|
||||
$cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\AnnotationChild');
|
||||
$em = $this->_getTestEntityManager();
|
||||
$em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
|
||||
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
|
||||
$factory->setEntityManager($em);
|
||||
|
||||
$cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationChild');
|
||||
$this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks);
|
||||
|
||||
$cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationParent');
|
||||
$this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -208,4 +228,43 @@ class UsingInvalidMappedSuperClass extends InvalidMappedSuperClass
|
||||
class MappedSuperClassInheritence
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorMap({"parent" = "AnnotationParent", "child" = "AnnotationChild"})
|
||||
* @HasLifecycleCallbacks
|
||||
*/
|
||||
class AnnotationParent
|
||||
{
|
||||
/**
|
||||
* @Id @Column(type="integer") @GeneratedValue
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @PostLoad
|
||||
*/
|
||||
public function postLoad()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @PreUpdate
|
||||
*/
|
||||
public function preUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @HasLifecycleCallbacks
|
||||
*/
|
||||
class AnnotationChild extends AnnotationParent
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user