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

Commit 59aae79

Browse files
committed
[#145] Make sure locale doesn't change after flush is called
1 parent 91c2df4 commit 59aae79

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ public function onFlush(ManagerEventArgs $args)
6161
$updates = array_merge($scheduledInserts, $scheduledUpdates);
6262

6363
$autoRoute = null;
64+
$locale = null;
6465
foreach ($updates as $document) {
6566
if ($this->isAutoRouteable($document)) {
67+
$locale = $uow->getCurrentLocale($document);
6668

6769
$uriContextCollection = new UriContextCollection($document);
6870
$arm->buildUriContextCollection($uriContextCollection);
@@ -73,6 +75,14 @@ public function onFlush(ManagerEventArgs $args)
7375
$dm->persist($autoRoute);
7476
$uow->computeChangeSets();
7577
}
78+
79+
// reset locale to the original locale
80+
if (null !== $locale) {
81+
$meta = $dm->getMetadataFactory()->getMetadataFor(get_class($document));
82+
$dm->findTranslation($meta->getName(), $meta->getIdentifierValue($document), $locale);
83+
84+
$locale = null;
85+
}
7686
}
7787
}
7888

Tests/Functional/EventListener/AutoRouteListenerTest.php

Lines changed: 1 addition & 1 deletion
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;

0 commit comments

Comments
 (0)