diff --git a/CHANGELOG.md b/CHANGELOG.md index 45e21eb5f..1222fc0d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ Changelog ========= +* **2014-10-07**: **BC break** dropped the pre/postBindTranslation events as they were previously + not clearly defined when they would be triggered. they are replaced by + preCreateTranslation which is triggered only before a new translation is added. * **2014-10-06**: we no longer unload translations after flush(). furthermore when doing multiple find() calls on a translated document we no longer fresh the state, so any changes to the document state that have not been persisted will no longer be lost diff --git a/lib/Doctrine/ODM/PHPCR/Event.php b/lib/Doctrine/ODM/PHPCR/Event.php index 90ab4e5dd..ca4ebf8ae 100644 --- a/lib/Doctrine/ODM/PHPCR/Event.php +++ b/lib/Doctrine/ODM/PHPCR/Event.php @@ -39,8 +39,7 @@ final class Event const loadClassMetadata = 'loadClassMetadata'; const postLoadTranslation = 'postLoadTranslation'; - const preBindTranslation = 'preBindTranslation'; - const postBindTranslation = 'postBindTranslation'; + const preCreateTranslation = 'preCreateTranslation'; const preRemoveTranslation = 'preRemoveTranslation'; const postRemoveTranslation = 'postRemoveTranslation'; @@ -55,8 +54,7 @@ final class Event self::postMove => self::postMove, self::postLoad => self::postLoad, self::postLoadTranslation => self::postLoadTranslation, - self::preBindTranslation => self::preBindTranslation, - self::postBindTranslation => self::postBindTranslation, + self::preCreateTranslation => self::preCreateTranslation, self::preRemoveTranslation => self::preRemoveTranslation, self::postRemoveTranslation => self::postRemoveTranslation, ); diff --git a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php index ee74ab8b4..7875bffe4 100644 --- a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php +++ b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php @@ -730,12 +730,12 @@ private function doBindTranslation($document, $locale, ClassMetadata $class) $oid = spl_object_hash($document); // only trigger the events if we bind a new translation - $suppressEvents = isset($this->documentTranslations[$oid][$locale]); - - if (!$suppressEvents && $invoke = $this->eventListenersInvoker->getSubscribedSystems($class, Event::preBindTranslation)) { + if (empty($this->documentTranslations[$oid][$locale]) + && $invoke = $this->eventListenersInvoker->getSubscribedSystems($class, Event::preCreateTranslation) + ) { $this->eventListenersInvoker->invoke( $class, - Event::preBindTranslation, + Event::preCreateTranslation, $document, new LifecycleEventArgs($document, $this->dm), $invoke @@ -747,16 +747,6 @@ private function doBindTranslation($document, $locale, ClassMetadata $class) foreach ($class->translatableFields as $field) { $this->documentTranslations[$oid][$locale][$field] = $class->reflFields[$field]->getValue($document); } - - if (!$suppressEvents && $invoke = $this->eventListenersInvoker->getSubscribedSystems($class, Event::postBindTranslation)) { - $this->eventListenersInvoker->invoke( - $class, - Event::postBindTranslation, - $document, - new LifecycleEventArgs($document, $this->dm), - $invoke - ); - } } /** diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventComputingTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventComputingTest.php index 3c9066002..cc4145d7f 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventComputingTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventComputingTest.php @@ -115,8 +115,7 @@ public function testComputingBetweenEventsWithTranslation() ->getEventManager() ->addEventListener( array( - Event::preBindTranslation, - Event::postBindTranslation, + Event::preCreateTranslation, Event::postLoadTranslation, Event::preRemoveTranslation, Event::postRemoveTranslation, @@ -132,11 +131,6 @@ public function testComputingBetweenEventsWithTranslation() $user->status = 'active'; $this->dm->persist($user); - - // postBindTranslation event should change the name to bindTranslation - $this->dm->bindTranslation($user, 'en'); - $this->assertEquals('postBindTranslation', $user->username); - $this->dm->flush(); $this->dm->clear(); @@ -146,7 +140,7 @@ public function testComputingBetweenEventsWithTranslation() $this->assertEquals('loadTranslation', $user->username); // name had been changed pre binding translation - $this->assertEquals('preBindTranslation', $user->name); + $this->assertEquals('preCreateTranslation', $user->name); $this->dm->name = 'neuer Name'; $this->dm->bindTranslation($user, 'de'); @@ -215,16 +209,10 @@ public function postMove(LifecycleEventArgs $e) $document->username .= '-postmove'; } - public function preBindTranslation(LifecycleEventArgs $e) - { - $document = $e->getObject(); - $document->name = 'preBindTranslation'; - } - - public function postBindTranslation(LifecycleEventArgs $e) + public function preCreateTranslation(LifecycleEventArgs $e) { $document = $e->getObject(); - $document->username = 'postBindTranslation'; + $document->name = 'preCreateTranslation'; } public function postLoadTranslation(LifecycleEventArgs $e) diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php index 16d08b319..05a5ad6c9 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php @@ -155,8 +155,7 @@ public function testTriggerTranslationEvents() ->getEventManager() ->addEventListener( array( - Event::preBindTranslation, - Event::postBindTranslation, + Event::preCreateTranslation, Event::postLoadTranslation, Event::preRemoveTranslation, Event::postRemoveTranslation, @@ -170,16 +169,14 @@ public function testTriggerTranslationEvents() $page->content = "long story"; $this->dm->persist($page); - $this->assertFalse($this->listener->postBindTranslation); - $this->assertFalse($this->listener->preBindTranslation); + $this->assertFalse($this->listener->preCreateTranslation); $this->assertFalse($this->listener->postLoadTranslation); $this->assertFalse($this->listener->postRemoveTranslation); $this->assertFalse($this->listener->postRemoveTranslation); $this->dm->bindTranslation($page, 'en'); - $this->assertTrue($this->listener->preBindTranslation); - $this->assertTrue($this->listener->postBindTranslation); + $this->assertTrue($this->listener->preCreateTranslation); $this->assertFalse($this->listener->postLoadTranslation); $this->assertFalse($this->listener->postRemoveTranslation); @@ -227,8 +224,7 @@ class TestPersistenceListener public $pagePostMove = false; public $postLoadTranslation = false; - public $preBindTranslation = false; - public $postBindTranslation = false; + public $preCreateTranslation = false; public $preRemoveTranslation = false; public $postRemoveTranslation = false; @@ -341,14 +337,9 @@ public function preFlush(ManagerEventArgs $e) $this->preFlush = true; } - public function preBindTranslation(LifecycleEventArgs $e) + public function preCreateTranslation(LifecycleEventArgs $e) { - $this->preBindTranslation = true; - } - - public function postBindTranslation(LifecycleEventArgs $e) - { - $this->postBindTranslation = true; + $this->preCreateTranslation = true; } public function postLoadTranslation(LifecycleEventArgs $e)