Merge branch 'DDC-2895' into 2.4
This commit is contained in:
commit
3764e49e6c
@ -2488,6 +2488,10 @@ class ClassMetadataInfo implements ClassMetadata
|
|||||||
*/
|
*/
|
||||||
public function addLifecycleCallback($callback, $event)
|
public function addLifecycleCallback($callback, $event)
|
||||||
{
|
{
|
||||||
|
if(isset($this->lifecycleCallbacks[$event]) && in_array($callback, $this->lifecycleCallbacks[$event])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->lifecycleCallbacks[$event][] = $callback;
|
$this->lifecycleCallbacks[$event][] = $callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,12 +450,9 @@ class AnnotationDriver extends AbstractAnnotationDriver
|
|||||||
if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
|
if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
|
||||||
/* @var $method \ReflectionMethod */
|
/* @var $method \ReflectionMethod */
|
||||||
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
|
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
|
||||||
// filter for the declaring class only, callbacks from parents will already be registered.
|
|
||||||
if ($method->getDeclaringClass()->name !== $class->name) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($this->getMethodCallbacks($method) as $value) {
|
foreach ($this->getMethodCallbacks($method) as $value) {
|
||||||
|
|
||||||
$metadata->addLifecycleCallback($value[0], $value[1]);
|
$metadata->addLifecycleCallback($value[0], $value[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
112
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php
Normal file
112
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DDC2895Test
|
||||||
|
* @package Doctrine\Tests\ORM\Functional\Ticket
|
||||||
|
* @author http://github.com/gwagner
|
||||||
|
*/
|
||||||
|
class DDC2895Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
try {
|
||||||
|
$this->_schemaTool->createSchema(array(
|
||||||
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2895'),
|
||||||
|
));
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPostLoadOneToManyInheritance()
|
||||||
|
{
|
||||||
|
$cm = $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC2895');
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array(
|
||||||
|
"prePersist" => array("setLastModifiedPreUpdate"),
|
||||||
|
"preUpdate" => array("setLastModifiedPreUpdate"),
|
||||||
|
),
|
||||||
|
$cm->lifecycleCallbacks
|
||||||
|
);
|
||||||
|
|
||||||
|
$ddc2895 = new DDC2895();
|
||||||
|
|
||||||
|
$this->_em->persist($ddc2895);
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
/** @var DDC2895 $ddc2895 */
|
||||||
|
$ddc2895 = $this->_em->find(get_class($ddc2895), $ddc2895->id);
|
||||||
|
|
||||||
|
$this->assertNotNull($ddc2895->getLastModified());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @MappedSuperclass
|
||||||
|
* @HasLifecycleCallbacks
|
||||||
|
*/
|
||||||
|
abstract class AbstractDDC2895
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Column(name="last_modified", type="datetimetz", nullable=false)
|
||||||
|
* @var \DateTime
|
||||||
|
*/
|
||||||
|
protected $lastModified;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @PrePersist
|
||||||
|
* @PreUpdate
|
||||||
|
*/
|
||||||
|
public function setLastModifiedPreUpdate()
|
||||||
|
{
|
||||||
|
$this->setLastModified(new \DateTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \DateTime $lastModified
|
||||||
|
*/
|
||||||
|
public function setLastModified( $lastModified )
|
||||||
|
{
|
||||||
|
$this->lastModified = $lastModified;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \DateTime
|
||||||
|
*/
|
||||||
|
public function getLastModified()
|
||||||
|
{
|
||||||
|
return $this->lastModified;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @HasLifecycleCallbacks
|
||||||
|
*/
|
||||||
|
class DDC2895 extends AbstractDDC2895
|
||||||
|
{
|
||||||
|
/** @Id @GeneratedValue @Column(type="integer") */
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $id
|
||||||
|
*/
|
||||||
|
public function setId( $id )
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user