diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b7d9c0aa..45e21eb5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +* **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 + 1.2.0-rc5 --------- diff --git a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php index cedbe9640..ee74ab8b4 100644 --- a/lib/Doctrine/ODM/PHPCR/UnitOfWork.php +++ b/lib/Doctrine/ODM/PHPCR/UnitOfWork.php @@ -2233,7 +2233,6 @@ public function commit($document = null) $this->invokeGlobalEvent(Event::postFlush, new ManagerEventArgs($this->dm)); if (null === $document) { - $this->documentTranslations = array(); foreach ($this->documentLocales as $oid => $locales) { $this->documentLocales[$oid]['original'] = $locales['current']; } @@ -2241,7 +2240,6 @@ public function commit($document = null) $documents = is_array($document) ? $document : array($document); foreach ($documents as $doc) { $oid = spl_object_hash($doc); - unset($this->documentTranslations[$oid]); if (isset($this->documentLocales[$oid])) { $this->documentLocales[$oid]['original'] = $this->documentLocales[$oid]['current']; } @@ -3376,8 +3374,15 @@ public function doLoadTranslation($document, ClassMetadata $metadata, $locale = $currentLocale = $this->getCurrentLocale($document, $metadata); - // if no locale is specified, we reset the current translation - $locale = $locale ?: $currentLocale; + $oid = spl_object_hash($document); + if (null === $locale || $locale === $currentLocale) { + // current locale is already loaded and not removed + if (!$refresh && isset($this->documentTranslations[$oid][$currentLocale])) { + return; + } + + $locale = $currentLocale; + } if (!$refresh && $this->doLoadPendingTranslation($document, $metadata, $locale)) { $localeUsed = $locale; @@ -3387,7 +3392,6 @@ public function doLoadTranslation($document, ClassMetadata $metadata, $locale = $this->doBindTranslation($document, $localeUsed, $metadata); - $oid = spl_object_hash($document); foreach ($metadata->translatableFields as $fieldName) { $this->originalData[$oid][$fieldName] = $this->originalTranslatedData[$oid][$localeUsed][$fieldName] = $metadata->getFieldValue($document, $fieldName); diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php index 26ec386ce..16d08b319 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/EventManagerTest.php @@ -184,8 +184,9 @@ public function testTriggerTranslationEvents() $this->assertFalse($this->listener->postRemoveTranslation); $this->dm->flush(); + $this->dm->clear(); - $this->dm->findTranslation('Doctrine\Tests\Models\CMS\CmsPageTranslatable', $page->id, 'en'); + $page = $this->dm->findTranslation('Doctrine\Tests\Models\CMS\CmsPageTranslatable', $page->id, 'en'); $this->assertTrue($this->listener->postLoadTranslation); diff --git a/tests/Doctrine/Tests/ODM/PHPCR/Functional/Translation/DocumentManagerTest.php b/tests/Doctrine/Tests/ODM/PHPCR/Functional/Translation/DocumentManagerTest.php index 1df828d62..5efa45cc5 100644 --- a/tests/Doctrine/Tests/ODM/PHPCR/Functional/Translation/DocumentManagerTest.php +++ b/tests/Doctrine/Tests/ODM/PHPCR/Functional/Translation/DocumentManagerTest.php @@ -862,4 +862,24 @@ public function testAssocWithNulls() $a = $this->dm->find(null, '/functional/' . $this->testNodeName); $this->assertEquals($assoc, $a->assoc); } + + public function testAdditionalFindCallsDoNotRefresh() + { + $a = new Article(); + $a->id = '/functional/' . $this->testNodeName; + $a->topic = 'Hello'; + $a->text = 'Some text'; + $this->dm->persist($a); + $this->dm->flush(); + + $a->topic = 'Guten tag'; + + $trans = $this->dm->findTranslation( + null, + '/functional/' . $this->testNodeName, + 'en' + ); + + $this->assertEquals('Guten tag', $trans->topic); + } }