Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 404874b

Browse files
committed
Merge pull request #159 from WouterJ/issue_145
Make sure locale doesn't change after flush is called
2 parents 5af0bd2 + 62a0ead commit 404874b

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Adapter/PhpcrOdmAdapter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ public function getLocales($contentDocument)
7171
public function translateObject($contentDocument, $locale)
7272
{
7373
$meta = $this->dm->getMetadataFactory()->getMetadataFor(get_class($contentDocument));
74-
$contentDocument = $this->dm->findTranslation($meta->getName(), $meta->getIdentifierValue($contentDocument), $locale);
7574

76-
return $contentDocument;
75+
return $this->dm->findTranslation($meta->getName(), $meta->getIdentifierValue($contentDocument), $locale);
7776
}
7877

7978
/**

Doctrine/Phpcr/AutoRouteListener.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function onFlush(ManagerEventArgs $args)
6363
$autoRoute = null;
6464
foreach ($updates as $document) {
6565
if ($this->isAutoRouteable($document)) {
66+
$locale = $uow->getCurrentLocale($document);
6667

6768
$uriContextCollection = new UriContextCollection($document);
6869
$arm->buildUriContextCollection($uriContextCollection);
@@ -73,6 +74,11 @@ public function onFlush(ManagerEventArgs $args)
7374
$dm->persist($autoRoute);
7475
$uow->computeChangeSets();
7576
}
77+
78+
// reset locale to the original locale
79+
if (null !== $locale) {
80+
$dm->findTranslation(get_class($document), $uow->getDocumentId($document), $locale);
81+
}
7682
}
7783
}
7884

Tests/Functional/EventListener/AutoRouteListenerTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212

13-
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Functional\Subscriber;
13+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Functional\EventListener;
1414

1515
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Functional\BaseTestCase;
1616
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Blog;
@@ -229,7 +229,6 @@ public function testMultilangArticle($data, $expectedPaths)
229229
$this->getDm()->flush();
230230
$this->getDm()->clear();
231231

232-
$articleTitles = array_values($data);
233232
$locales = array_keys($data);
234233

235234
foreach ($expectedPaths as $i => $expectedPath) {
@@ -271,6 +270,29 @@ public function provideUpdateMultilangArticle()
271270
);
272271
}
273272

273+
public function testMultilangArticleRemainsSameLocale()
274+
{
275+
$article = new Article;
276+
$article->path = '/test/article-1';
277+
$article->title = 'Good Day';
278+
$this->getDm()->persist($article);
279+
$this->getDm()->flush();
280+
281+
$article->title = 'Hello everybody!';
282+
$this->getDm()->bindTranslation($article, 'en');
283+
284+
$article->title = 'Bonjour le monde!';
285+
$this->getDm()->bindTranslation($article, 'fr');
286+
287+
// let current article be something else than the last bound locale
288+
$this->getDm()->findTranslation(get_class($article), $this->getDm()->getUnitOfWork()->getDocumentId($article), 'en');
289+
290+
$this->getDm()->flush();
291+
$this->getDm()->clear();
292+
293+
$this->assertEquals('Hello everybody!', $article->title);
294+
}
295+
274296
/**
275297
* @dataProvider provideUpdateMultilangArticle
276298
*/

0 commit comments

Comments
 (0)