Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
---------

Expand Down
14 changes: 9 additions & 5 deletions lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -2233,15 +2233,13 @@ public function commit($document = null)
$this->invokeGlobalEvent(Event::postFlush, new ManagerEventArgs($this->dm));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we were clearing the loaded translations on flush, which I guess was a memory optimization but caused the translations to be loaded again either way.

if (null === $document) {
$this->documentTranslations = array();
foreach ($this->documentLocales as $oid => $locales) {
$this->documentLocales[$oid]['original'] = $locales['current'];
}
} else {
$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'];
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}