/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { $webspaceKey = $input->getArgument('webspaceKey'); $locale = $input->getArgument('locale'); $basePath = $input->getOption('base-path'); $dryRun = $input->getOption('dry-run'); $this->session = $this->getContainer()->get('doctrine_phpcr')->getManager()->getPhpcrSession(); $this->sessionManager = $this->getContainer()->get('sulu.phpcr.session'); $this->output = $output; $path = $this->sessionManager->getRoutePath($webspaceKey, $locale); $relativePath = $basePath !== null ? '/' . ltrim($basePath, '/') : '/'; $fullPath = rtrim($path . $relativePath, '/'); if (!$this->session->nodeExists($fullPath)) { $this->output->write('<error>Resource-Locator "' . $relativePath . '" not found</error>'); return; } $node = $this->session->getNode($fullPath); $this->cleanup($node, $path, $dryRun); if (false === $dryRun) { $this->output->writeln('<info>Saving ...</info>'); $this->session->save(); $this->output->writeln('<info>Done</info>'); } else { $this->output->writeln('<info>Dry run complete</info>'); } }
/** * Updates the route for the given document and creates history routes if necessary. * * @param PersistEvent $event */ 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); } }
private function exists($webspace, $locale, $route) { if ($route === '/') { return true; } $session = $this->sessionManager->getSession(); $fullPath = sprintf('%s/%s', $this->sessionManager->getRoutePath($webspace, $locale), ltrim($route, '/')); return $session->nodeExists($fullPath); }
/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { $webspaceKey = $input->getArgument('webspaceKey'); $locale = $input->getArgument('locale'); $basePath = $input->getOption('base-path'); $dryRun = $input->getOption('dry-run'); $path = $this->sessionManager->getRoutePath($webspaceKey, $locale); $relativePath = $basePath !== null ? '/' . ltrim($basePath, '/') : '/'; $fullPath = rtrim($path . $relativePath, '/'); $this->cleanSession($output, $this->defaultSession, $fullPath, $dryRun); $this->cleanSession($output, $this->liveSession, $fullPath, $dryRun); if (false === $dryRun) { $this->defaultSession->save(); $this->liveSession->save(); $output->writeln('<info>Save complete</info>'); } else { $output->writeln('<info>Dry run complete</info>'); } }
private function upgradeNode(NodeInterface $node, Webspace $webspace, Localization $localization, OutputInterface $output, $depth = 0) { $locale = $localization->getLocale(); $localizedTemplatePropertyName = $this->propertyEncoder->localizedSystemName('template', $locale); if (!$node->hasProperty($localizedTemplatePropertyName)) { return; } $structureMetadata = $this->structureMetadataFactory->getStructureMetadata($this->metadataFactory->getMetadataForPhpcrNode($node)->getAlias(), $node->getPropertyValue($localizedTemplatePropertyName)); $property = $structureMetadata->getPropertyByTagName('sulu.rlp'); if (!$property) { return; } $nodeType = $node->getPropertyValue($this->propertyEncoder->localizedSystemName('nodeType', $locale)); if ($property->getContentTypeName() !== 'resource_locator' && $nodeType !== Structure::NODE_TYPE_CONTENT) { return; } $baseRoutePath = $this->sessionManager->getRoutePath($webspace->getKey(), $localization->getLocale()); foreach ($node->getReferences('sulu:content') as $routeProperty) { if (strpos($routeProperty->getPath(), $baseRoutePath) !== 0) { continue; } $routeNode = $routeProperty->getParent(); if ($routeNode->getPropertyValue('sulu:history') === true) { continue; } $resourceLocator = substr($routeNode->getPath(), strlen($baseRoutePath)); if ($resourceLocator) { // only set if resource locator is not empty // if the resource locator is empty it is the homepage, whose url should not be changed $node->setProperty($this->propertyEncoder->localizedContentName($property->getName(), $locale), $resourceLocator); $prefix = ' '; for ($i = 0; $i < $depth; ++$i) { $prefix .= '-'; } $title = $node->getPropertyValue($this->propertyEncoder->localizedContentName('title', $locale)); $output->writeln($prefix . '> "' . $title . '": ' . $resourceLocator); } break; } }
/** * returns base path of routes from phpcr. * * @param string $webspaceKey current session * @param string $languageCode * @param string $segmentKey * * @return string */ private function getWebspaceRouteNodeBasePath($webspaceKey, $languageCode, $segmentKey) { return $this->sessionManager->getRoutePath($webspaceKey, $languageCode, $segmentKey); }
/** * Return the node in the content repository which contains all of the routes. * * @param $webspaceKey * @param string $locale * @param string $segment * * @return NodeInterface */ protected function getRootRouteNode($webspaceKey, $locale, $segment) { return $this->documentManager->find($this->sessionManager->getRoutePath($webspaceKey, $locale, $segment)); }