Updates the route for the given document and creates history routes if necessary.

@param PersistEvent $event
554771
public function handlePersist(PersistEvent $event)
    {
        $document = $event->getDocument();

        if (!$document instanceof RouteBehavior) {
            return;
        }

        $node = $event->getNode();
        $node->setProperty(self::NODE_HISTORY_FIELD, $document->isHistory());

        $targetDocument = $document->getTargetDocument();

        if ($targetDocument instanceof HomeDocument
            || !$targetDocument instanceof WebspaceBehavior
            || !$targetDocument instanceof ResourceSegmentBehavior
        ) {
            return;
        }

        // copy new route to old position
        $webspaceKey = $targetDocument->getWebspaceName();
        $locale = $this->documentInspector->getLocale($document);

        $routePath = $this->sessionManager->getRoutePath($webspaceKey, $locale, null)
            . $targetDocument->getResourceSegment();

        // create a route node if it is not a new document and the path changed
        $documentPath = $this->documentInspector->getPath($document);
        if ($documentPath && $documentPath != $routePath) {
            /** @var RouteDocument $newRouteDocument */
            $newRouteDocument = $this->documentManager->create('route');
            $newRouteDocument->setTargetDocument($targetDocument);
            $this->documentManager->persist(
                $newRouteDocument,
                $locale,
                [
                    'path' => $routePath,
                    'auto_create' => true,
                ]
            );
            $this->documentManager->publish($newRouteDocument, $locale);

            // change routes in old position to history
            $this->changeOldPathToHistoryRoutes($document, $newRouteDocument);
        }
    }
519602
public function refresh(object $document) : void
    {
        assert($this->collection instanceof Collection);
        $query = $this->getQueryForDocument($document);
        $data  = $this->collection->findOne($query);
        if ($data === null) {
            throw MongoDBException::cannotRefreshDocument();
        }
        $data = $this->hydratorFactory->hydrate($document, (array) $data);
        $this->uow->setOriginalDocumentData($document, $data);
    }
480851
public function handleScheduleRename(PersistEvent $event)
    {
        $document = $event->getDocument();

        if (!$event->getOption('auto_name')
            || !$document instanceof AutoNameBehavior
            || $event->getOption('auto_name_locale') !== $event->getLocale()
            || !$event->hasNode()
            || $event->getNode()->isNew()
        ) {
            return;
        }

        $node = $event->getNode();
        $name = $this->getName($document, $event->getParentNode(), $event->getOption('auto_rename'), $node);

        if ($name === $node->getName()) {
            return;
        }

        $uuid = $event->getNode()->getIdentifier();
        $this->scheduledRename[] = ['uuid' => $uuid, 'name' => $name, 'locale' => $event->getLocale()];
    }
289153
private function updateCounter(ModelEvent $event, $action)
    {
        if (!$this->constraint->isVersioningService()) {
            return;
        }

        $qb = $this->documentManager->createQueryBuilder($event->getCollectionClass());
        if ('update' == $action) {
            $qb->findAndUpdate()
                ->field('id')->equals($event->getCollectionId())
                ->field(VersionServiceConstraint::FIELD_NAME)->inc(1)
                ->getQuery()->execute();
        } else {
            $qb->findAndUpdate()
                ->field('id')->equals($event->getCollectionId())
                ->field(VersionServiceConstraint::FIELD_NAME)->set(1)
                ->getQuery()->execute();
        }
    }
649858
public function handlePublish(PublishEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof RoutableBehavior) {
            return;
        }

        $node = $this->documentInspector->getNode($document);

        try {
            $route = $this->createOrUpdateRoute($document, $event->getLocale());
        } catch (RouteIsNotUniqueException $exception) {
            throw new ResourceLocatorAlreadyExistsException($exception->getRoute()->getPath(), $document->getPath());
        }

        $document->setRoutePath($route->getPath());
        $this->entityManager->persist($route);

        $node->setProperty(
            $this->getRoutePathPropertyName($document->getStructureType(), $event->getLocale()),
            $route->getPath()
        );

        $propertyName = $this->getPropertyName($event->getLocale(), self::ROUTES_PROPERTY);

        // check if nodes previous generated routes exists and remove them if not
        $oldRoutes = $event->getNode()->getPropertyValueWithDefault($propertyName, []);
        $this->removeOldChildRoutes($event->getNode()->getSession(), $oldRoutes, $event->getLocale());

        $routes = [];
        if ($document instanceof ChildrenBehavior) {
            // generate new routes of children
            $routes = $this->generateChildRoutes($document, $event->getLocale());
        }

        // save the newly generated routes of children
        $event->getNode()->setProperty($propertyName, $routes);
        $this->entityManager->flush();
    }
482757
public function handlePersist(AbstractMappingEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof RoutablePageBehavior) {
            return;
        }

        $document->setUuid($event->getNode()->getIdentifier());

        $propertyName = $this->getRoutePathPropertyName($document->getStructureType(), $event->getLocale());
        $routePath = $event->getNode()->getPropertyValueWithDefault($propertyName, null);

        $route = $this->conflictResolver->resolve($this->chainRouteGenerator->generate($document, $routePath));
        $document->setRoutePath($route->getPath());

        $event->getNode()->setProperty($propertyName, $route->getPath());

        if (!$document instanceof ChildrenBehavior) {
            return;
        }

        foreach ($document->getChildren() as $child) {
            if (!$child instanceof RoutablePageBehavior) {
                continue;
            }

            $route = $this->chainRouteGenerator->generate($child);
            $child->setRoutePath($route->getPath());

            $node = $this->documentInspector->getNode($child);
            $node->setProperty($propertyName, $route->getPath());
        }
    }
813123
public static function onFlushPage(Event $event)
    {
        if (self::$onFlushPageAlreadyCalled) {
            return;
        }

        $page = $event->getTarget();
        if (!($page instanceof Page)) {
            return;
        }

        $application = $event->getApplication();
        $em = $application->getEntityManager();
        $uow = $em->getUnitOfWork();
        if ($uow->isScheduledForDelete($page)) {
            return;
        }

        $metadata = $application->getContainer()->get('nestednode.metadata.resolver')->resolve($page);
        $page->setMetaData($metadata);

        if ($uow->isScheduledForInsert($page) || $uow->isScheduledForUpdate($page)) {
            $uow->recomputeSingleEntityChangeSet($em->getClassMetadata('BackBee\NestedNode\Page'), $page);
        } elseif (!$uow->isScheduledForDelete($page)) {
            $uow->computeChangeSet($em->getClassMetadata('BackBee\NestedNode\Page'), $page);
        }

        self::$onFlushPageAlreadyCalled = true;
    }
369797
public function addContextual($event)
    {
        $page = $event->getPage();
        $currentArticle = $event->getPage()->getBusinessEntity();

        $bottomRightNavbar = $this->menuBuilder->getBottomRightNavbar();

        $bottomRightNavbar->addChild('menu.page.settings',
            [
                'route'           => 'victoire_blog_article_settings',
                'routeParameters' => [
                    'id'      => $currentArticle->getId(),
                    'page_id' => $page->getId(),
                ],
                'linkAttributes' => [
                    'class' => 'v-btn v-btn--sm v-btn--transparent',
                    'id'    => 'v-settings-link',
                ],
            ]
        )->setLinkAttribute('data-toggle', 'vic-modal');
    }
1185264
public function onPostSerialize(ObjectEvent $event)
    {
        /** @var RedirectTypeBehavior $document */
        $document = $event->getObject();

        if (!$document instanceof RedirectTypeBehavior) {
            return;
        }

        $visitor = $event->getVisitor();

        $redirectType = $document->getRedirectType();

        if (RedirectType::INTERNAL == $redirectType && null !== $document->getRedirectTarget()) {
            $visitor->addData('linked', 'internal');
            $visitor->addData('internal_link', $document->getRedirectTarget()->getUuid());
        } elseif (RedirectType::EXTERNAL == $redirectType) {
            $visitor->addData('linked', 'external');
            $visitor->addData('external', $document->getRedirectExternal());
        } else {
            $visitor->addData('linked', null);
        }
    }
38717
public function setNodeOnPersist(PersistEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticlePageDocument || $event->hasNode()) {
            return;
        }

        $pageTitle = $this->getPageTitle($document);

        // if no page-title exists use a unique-id
        $nodeName = $this->slugifier->slugify($pageTitle ?: uniqid('page-', true));
        $nodeName = $this->resolver->resolveName($event->getParentNode(), $nodeName);
        $node = $event->getParentNode()->addNode($nodeName);

        $event->setNode($node);
    }
383604
private function changeOldPathToHistoryRoutes(RouteBehavior $oldDocument, RouteBehavior $newDocument)
    {
        $oldDocument->setTargetDocument($newDocument);
        $oldDocument->setHistory(true);
        $oldRouteNode = $this->documentInspector->getNode($oldDocument);
        $oldRouteNode->setProperty(self::NODE_HISTORY_FIELD, true);

        foreach ($this->documentInspector->getReferrers($oldDocument) as $referrer) {
            if ($referrer instanceof RouteBehavior) {
                $referrer->setTargetDocument($newDocument);
                $referrer->setHistory(true);
                $this->documentManager->persist(
                    $referrer,
                    null,
                    [
                        'path' => $this->documentInspector->getPath($referrer),
                    ]
                );
                $this->documentManager->publish($referrer, null);
            }
        }
    }
572409
public function setTimestampsOnNodeForPersist(PersistEvent $event)
    {
        $document = $event->getDocument();

        if (!$this->supports($document)) {
            return;
        }

        $this->setTimestampsOnNode(
            $document,
            $event->getNode(),
            $event->getAccessor(),
            $this->documentInspector->getOriginalLocale($document),
            new \DateTime()
        );
    }
566191
public function onPostSerialize(ObjectEvent $event)
    {
        if ($this->container->has('routing')) {
            $uri = $this->container->get('routing')->getUri($event->getObject()->getUrl());
            $event->getVisitor()->addData('uri', $uri);
        }
    }
325443
public static function updateConfig( Event $event )
	{
		$event->getIO()->write( 'Ensure existing config and routing for the shop bundle' );

		$options = self::getOptions( $event );

		if( isset( $options['symfony-app-dir'] ) )
		{
			self::updateConfigFile( $options['symfony-app-dir'] . '/config/config.yml' );
			self::updateRoutingFile( $options['symfony-app-dir'] . '/config/routing.yml' );
		}
	}
268391
public static function onPostLoad(Event $event)
    {
        $revision = $event->getTarget();
        $dispatcher = $event->getDispatcher();
        $application = $dispatcher->getApplication();

        if (null !== $application) {
            $em = $application->getEntityManager();
            $revision
                ->setEntityManager($em)
                ->setToken($application->getBBUserToken())
            ;

            if (null === $revision->getContent()) {
                $db = $em->getConnection();
                $stmt = $db->executeQuery(
                    'SELECT `content_uid`, `classname` FROM `revision` WHERE `uid` = ?',
                    [$revision->getUid()]
                );

                $items = $stmt->fetchAll();
                if ($items) {
                    foreach ($items as $item) {
                        $content = $em->find(Revision::getFullClassname($item['classname']), $item['content_uid']);
                        if ($content) {
                            $revision->setContent($content);
                        }
                    }
                }
            }
        }

        $revision->postLoad();
    }
1320603
protected function createRoute(
        $domain,
        CustomUrlBehavior $document,
        Localization $locale,
        $persistedLocale,
        $routesPath
    ) {
        $path = sprintf('%s/%s', $routesPath, $domain);
        $routeDocument = $this->findOrCreateRoute($path, $persistedLocale, $document, $domain);
        $routeDocument->setTargetDocument($document);
        $routeDocument->setLocale($locale->getLocale());
        $routeDocument->setHistory(false);

        $this->documentManager->persist(
            $routeDocument,
            $persistedLocale,
            [
                'path' => $path,
                'auto_create' => true,
            ]
        );
        $this->documentManager->publish($routeDocument, $persistedLocale);

        return $routeDocument;
    }
675761
public function handleNodeFromRegistry($event)
    {
        if ($event->hasNode()) {
            return;
        }

        $document = $event->getDocument();

        if (!$this->documentRegistry->hasDocument($document)) {
            return;
        }

        $node = $this->documentRegistry->getNodeForDocument($document);
        $event->setNode($node);
    }