Example #1
0
 /**
  * Updates the route for the given document after a move or copy.
  *
  * @param object $document
  * @param bool $generateRoutes If set to true a route in the routing tree will also be created
  */
 private function updateRoute($document, $generateRoutes)
 {
     $locales = $this->documentInspector->getLocales($document);
     $webspaceKey = $this->documentInspector->getWebspace($document);
     $uuid = $this->documentInspector->getUuid($document);
     $path = $this->documentInspector->getPath($document);
     $parentUuid = $this->documentInspector->getUuid($this->documentInspector->getParent($document));
     $defaultNode = $this->defaultSession->getNode($path);
     $liveNode = $this->liveSession->getNode($path);
     $resourceLocatorStrategy = $this->resourceLocatorStrategyPool->getStrategyByWebspaceKey($webspaceKey);
     foreach ($locales as $locale) {
         $localizedDocument = $this->documentManager->find($uuid, $locale);
         if ($localizedDocument->getRedirectType() !== RedirectType::NONE) {
             continue;
         }
         $resourceSegmentPropertyName = $this->encoder->localizedSystemName($this->getResourceSegmentProperty($localizedDocument)->getName(), $locale);
         $this->updateResourceSegmentProperty($defaultNode, $resourceSegmentPropertyName, $parentUuid, $webspaceKey, $locale);
         if ($liveNode->hasProperty($resourceSegmentPropertyName)) {
             $this->updateResourceSegmentProperty($liveNode, $resourceSegmentPropertyName, $parentUuid, $webspaceKey, $locale);
             // if the method is called with the generateRoutes flag it will create a new route
             // this happens on a move, but not on copy, because copy results in a draft page without url
             if ($generateRoutes) {
                 $localizedDocument->setResourceSegment($liveNode->getPropertyValue($resourceSegmentPropertyName));
                 $resourceLocatorStrategy->save($localizedDocument, null);
                 $localizedDocument->setResourceSegment($defaultNode->getPropertyValue($resourceSegmentPropertyName));
             }
         }
     }
 }
Example #2
0
 /**
  * Prefix url of document with current resourcelocator prefix.
  *
  * @param IndexRebuildEvent $event
  */
 public function onIndexRebuild(IndexRebuildEvent $event)
 {
     $output = $event->getOutput();
     $purge = $event->getPurge();
     $filter = $event->getFilter();
     $output->writeln('<info>Rebuilding content index</info>');
     // TODO: We cannot select all contents via. the parent type, see: https://github.com/jackalope/jackalope-doctrine-dbal/issues/217
     $query = $this->documentManager->createQuery('SELECT * FROM [nt:unstructured] AS a WHERE [jcr:mixinTypes] = "sulu:page" or [jcr:mixinTypes] = "sulu:snippet"');
     $count = [];
     if ($purge) {
         $this->purgeContentIndexes($output);
     }
     $documents = $query->execute();
     $progress = new ProgressHelper();
     $progress->start($output, count($documents));
     foreach ($documents as $document) {
         $locales = $this->inspector->getLocales($document);
         foreach ($locales as $locale) {
             try {
                 $this->documentManager->find($document->getUuid(), $locale);
                 $documentClass = get_class($document);
                 if ($filter && !preg_match('{' . $filter . '}', $documentClass)) {
                     continue;
                 }
                 $this->searchManager->index($document, $locale);
                 if (!isset($count[$documentClass])) {
                     $count[$documentClass] = 0;
                 }
                 ++$count[$documentClass];
             } catch (\Exception $e) {
                 $output->writeln(sprintf('<error>Error indexing or de-indexing page (path: %s locale: %s)</error>: %s', $this->inspector->getPath($document), $locale, $e->getMessage()));
             }
         }
         $progress->advance();
     }
     $output->writeln('');
     foreach ($count as $className => $count) {
         if ($count == 0) {
             continue;
         }
         $output->writeln(sprintf('<comment>Content</comment>: %s <info>%s</info> indexed', $className, $count));
     }
 }
 private function validateShadow(ShadowLocaleBehavior $document)
 {
     if ($document->getLocale() === $document->getShadowLocale()) {
         throw new \RuntimeException(sprintf('Document cannot be a shadow of itself for locale "%s"', $document->getLocale()));
     }
     $locales = $this->inspector->getConcreteLocales($document);
     if (!in_array($document->getShadowLocale(), $locales)) {
         $this->inspector->getNode($document)->revert();
         throw new \RuntimeException(sprintf('Attempting to create shadow for "%s" on a non-concrete locale "%s" for document at "%s". Concrete languages are "%s"', $document->getLocale(), $document->getShadowLocale(), $this->inspector->getPath($document), implode('", "', $locales)));
     }
 }
Example #4
0
 /**
  * Prefix url of document with current resourcelocator prefix.
  *
  * @param IndexRebuildEvent $event
  */
 public function onIndexRebuild(IndexRebuildEvent $event)
 {
     $output = $event->getOutput();
     $filter = $event->getFilter();
     $output->writeln('<info>Rebuilding content index</info>');
     $typeMap = $this->baseMetadataFactory->getPhpcrTypeMap();
     $phpcrTypes = [];
     foreach ($typeMap as $type) {
         $phpcrType = $type['phpcr_type'];
         if ($phpcrType !== 'sulu:path') {
             $phpcrTypes[] = sprintf('[jcr:mixinTypes] = "%s"', $phpcrType);
         }
     }
     $condition = implode(' or ', $phpcrTypes);
     // TODO: We cannot select all contents via. the parent type, see: https://github.com/jackalope/jackalope-doctrine-dbal/issues/217
     $query = $this->documentManager->createQuery('SELECT * FROM [nt:unstructured] AS a WHERE ' . $condition);
     $count = [];
     $documents = $query->execute();
     $progress = new ProgressHelper();
     $progress->start($output, count($documents));
     foreach ($documents as $document) {
         if ($document instanceof SecurityBehavior && !empty($document->getPermissions())) {
             $progress->advance();
             continue;
         }
         $locales = $this->inspector->getLocales($document);
         foreach ($locales as $locale) {
             try {
                 $this->documentManager->find($document->getUuid(), $locale);
                 $documentClass = get_class($document);
                 if ($filter && !preg_match('{' . $filter . '}', $documentClass)) {
                     continue;
                 }
                 $this->searchManager->index($document, $locale);
                 if (!isset($count[$documentClass])) {
                     $count[$documentClass] = 0;
                 }
                 ++$count[$documentClass];
             } catch (\Exception $e) {
                 $output->writeln(sprintf('<error>Error indexing or de-indexing page (path: %s locale: %s)</error>: %s', $this->inspector->getPath($document), $locale, $e->getMessage()));
             }
         }
         $progress->advance();
     }
     $output->writeln('');
     foreach ($count as $className => $count) {
         if ($count == 0) {
             continue;
         }
         $output->writeln(sprintf('<comment>Content</comment>: %s <info>%s</info> indexed', $className, $count));
     }
 }
Example #5
0
 /**
  * Changes the old route to a history route and redirect to the new route.
  *
  * @param RouteBehavior $oldDocument
  * @param RouteBehavior $newDocument
  */
 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);
         }
     }
 }
Example #6
0
 /**
  * TODO: Move this logic to the DocumentManager
  * {@inheritDoc}
  */
 public function orderAt($uuid, $position, $userId, $webspaceKey, $locale)
 {
     $document = $this->documentManager->find($uuid, $locale);
     $parentDocument = $this->inspector->getParent($document);
     $siblingDocuments = $this->inspector->getChildren($parentDocument);
     $siblings = array_values($siblingDocuments->toArray());
     // get indexed array
     $countSiblings = count($siblings);
     $currentPosition = array_search($document, $siblings) + 1;
     if ($countSiblings < $position || $position <= 0) {
         throw new InvalidOrderPositionException(sprintf('Cannot order node "%s" at out-of-range position "%s", must be >= 0 && < %d"', $this->inspector->getPath($document), $position, $countSiblings));
     }
     if ($position === $countSiblings) {
         // move to the end
         $this->documentManager->reorder($document, null);
     } else {
         if ($currentPosition < $position) {
             $targetSibling = $siblings[$position];
         } elseif ($currentPosition > $position) {
             $targetSibling = $siblings[$position - 1];
         }
         $this->documentManager->reorder($document, $targetSibling->getPath());
     }
     $this->documentManager->persist($document, $locale);
     $this->documentManager->flush();
     return $this->documentToStructure($document);
 }