From 63901399a950df8dd96ebc81e2afc328ec3363bc Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 2 Aug 2017 17:51:53 +0200 Subject: [PATCH] update content if it implements the addRoute method --- CHANGELOG.md | 6 ++++++ src/Adapter/PhpcrOdmAdapter.php | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b183ee4..3c00f24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========= +2.0.0-RC3 (unreleased) +---------------------- + +* PhpcrOdmAdapter now updates the content document with the new route, if the + content implements RouteReferrersInterface. + 2.0.0-RC1 --------- diff --git a/src/Adapter/PhpcrOdmAdapter.php b/src/Adapter/PhpcrOdmAdapter.php index 5a6ff94..d1fc707 100644 --- a/src/Adapter/PhpcrOdmAdapter.php +++ b/src/Adapter/PhpcrOdmAdapter.php @@ -14,6 +14,8 @@ use Doctrine\Common\Util\ClassUtils; use Doctrine\ODM\PHPCR\Document\Generic; use Doctrine\ODM\PHPCR\DocumentManager; +use Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRoute; +use Symfony\Cmf\Component\Routing\RouteReferrersInterface; use Symfony\Cmf\Component\RoutingAuto\AdapterInterface; use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface; use Symfony\Cmf\Component\RoutingAuto\UriContext; @@ -157,6 +159,7 @@ public function createAutoRoute(UriContext $uriContext, $contentDocument, $local ); } + /** @var AutoRoute $headRoute */ $headRoute = new $this->autoRouteFqcn(); $headRoute->setContent($contentDocument); $headRoute->setName($headName); @@ -164,6 +167,10 @@ public function createAutoRoute(UriContext $uriContext, $contentDocument, $local $headRoute->setLocale($locale); $headRoute->setType(AutoRouteInterface::TYPE_PRIMARY); + if ($contentDocument instanceof RouteReferrersInterface) { + $contentDocument->addRoute($headRoute); + } + foreach ($uriContext->getDefaults() as $key => $value) { $headRoute->setDefault($key, $value); } @@ -256,6 +263,7 @@ private function migrateGenericToAutoRoute(Generic $document, $contentDocument, $this->dm->getPhpcrSession()->save(); // Detach is needed to force Doctrine to re-load the node $this->dm->detach($document); + /** @var AutoRoute $autoRoute */ $autoRoute = $this->dm->find(null, $document->getId()); if (!$autoRoute instanceof $autoRouteClassName) { @@ -272,6 +280,9 @@ private function migrateGenericToAutoRoute(Generic $document, $contentDocument, $autoRoute->setContent($contentDocument); $autoRoute->setLocale($locale); $autoRoute->setType($routeType); + if ($contentDocument instanceof RouteReferrersInterface) { + $contentDocument->addRoute($autoRoute); + } return $autoRoute; }