Sulu\Bundle\RouteBundle\Manager\RouteManager::update PHP Method

update() public method

public update ( Sulu\Bundle\RouteBundle\Model\RoutableInterface $entity, $path = null )
$entity Sulu\Bundle\RouteBundle\Model\RoutableInterface
    public function update(RoutableInterface $entity, $path = null)
    {
        if (null === $entity->getRoute()) {
            throw new RouteNotCreatedException($entity);
        }
        $config = $this->getClassMappingConfiguration(get_class($entity));
        if (null === $path) {
            $path = $this->routeGenerators[$config['generator']]->generate($entity, $config['options']);
        }
        if ($path === $entity->getRoute()->getPath()) {
            return $entity->getRoute();
        }
        $route = $this->routeRepository->createNew()->setPath($path)->setEntityClass(get_class($entity))->setEntityId($entity->getId())->setLocale($entity->getLocale());
        $route = $this->conflictResolver->resolve($route);
        // path haven't changed after conflict resolving
        if ($route->getPath() === $entity->getRoute()->getPath()) {
            return $entity->getRoute();
        }
        $historyRoute = $entity->getRoute()->setHistory(true)->setTarget($route);
        $route->addHistory($historyRoute);
        foreach ($historyRoute->getHistories() as $historyRoute) {
            if ($historyRoute->getPath() === $route->getPath()) {
                // the history route will be restored
                $historyRoute->removeTarget()->setHistory(false);
                continue;
            }
            $route->addHistory($historyRoute);
            $historyRoute->setTarget($route);
        }
        $entity->setRoute($route);
        return $route;
    }