/** * Schedule updates for routing * * @param EntityManager $em * @param UnitOfWork $uow */ protected function updateRouting(EntityManager $em, UnitOfWork $uow) { // 302 old routes to the new 200 foreach ($uow->getScheduledEntityUpdates() as $entity) { if ($entity instanceof FieldableEntity) { $changeSet = $uow->getEntityChangeSet($entity); $oldRoute = $entity->getRoute(); // Check if we have a route. If not, create one and continue if (!$oldRoute instanceof Route) { // create the new route $oldRoute = $this->getEntityRoute($entity); $entity->setRoute($oldRoute); $this->computeChangeSet($em, $oldRoute); $this->recomputeSingleEntityChangeSet($em, $entity); } // Check if the route has been manually updated $newRoute = $this->getEntityRoute($entity); // if the route changed, update it if ($newRoute->getPath() !== $oldRoute->getPath()) { // create the new route entity $entity->setRoute($newRoute); $this->computeChangeSet($em, $newRoute); // set any old route to redirect to the new route $this->redirectRoute($oldRoute); $this->recomputeSingleEntityChangeSet($em, $oldRoute); } if (isset($changeSet['deletedOn'])) { if ($changeSet['deletedOn'] instanceof \DateTime) { // delete $this->deletedRoute($oldRoute); $this->recomputeSingleEntityChangeSet($em, $oldRoute); } else { // un-delete $newRoute = $this->getEntityRoute($entity); $entity->setRoute($newRoute); $uow->scheduleForDelete($oldRoute); $this->computeChangeSet($em, $newRoute); $this->recomputeSingleEntityChangeSet($em, $oldRoute); } } $em->persist($entity); $this->recomputeSingleEntityChangeSet($em, $entity); } } }