Ejemplo n.º 1
0
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof PathBehavior) {
         return;
     }
     $event->getAccessor()->set('path', $this->documentInspector->getPath($document));
 }
Ejemplo n.º 2
0
 /**
  * Return a structure bridge corresponding to the given document.
  *
  * @param BasePageDocument $document
  *
  * @return PageBridge
  */
 protected function documentToStructure(BasePageDocument $document)
 {
     $structure = $this->inspector->getStructureMetadata($document);
     $documentAlias = $this->inspector->getMetadata($document)->getAlias();
     $structureBridge = $this->structureManager->wrapStructure($documentAlias, $structure);
     $structureBridge->setDocument($document);
     return $structureBridge;
 }
Ejemplo n.º 3
0
 private function initializeWebspace(OutputInterface $output, Webspace $webspace)
 {
     $homePath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%content%']);
     $routesPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%route%']);
     $webspaceLocales = [];
     foreach ($webspace->getAllLocalizations() as $localization) {
         $webspaceLocales[] = $localization->getLocale();
     }
     $homeType = $webspace->getDefaultTemplate('home');
     $existingLocales = [];
     $homeDocument = null;
     if ($this->nodeManager->has($homePath)) {
         $homeDocument = $this->documentManager->find($homePath, null, ['load_ghost_content' => false, 'auto_create' => true, 'path' => $homePath]);
         $existingLocales = $this->inspector->getLocales($homeDocument);
     }
     foreach ($webspaceLocales as $webspaceLocale) {
         if (in_array($webspaceLocale, $existingLocales)) {
             $output->writeln(sprintf('  [ ] <info>homepage</info>: %s (%s)', $homePath, $webspaceLocale));
             continue;
         }
         $output->writeln(sprintf('  [+] <info>homepage</info>: [%s] %s (%s)', $homeType, $homePath, $webspaceLocale));
         $persistOptions = ['ignore_required' => true];
         if (!$homeDocument) {
             $homeDocument = new HomeDocument();
             $persistOptions['path'] = $homePath;
             $persistOptions['auto_create'] = true;
         } else {
             $homeDocument = $this->documentManager->find($homePath, $webspaceLocale, ['load_ghost_content' => false]);
         }
         $homeDocument->setTitle('Homepage');
         $homeDocument->setStructureType($homeType);
         $this->documentManager->persist($homeDocument, $webspaceLocale, $persistOptions);
         $this->documentManager->publish($homeDocument, $webspaceLocale);
         $routePath = $routesPath . '/' . $webspaceLocale;
         try {
             $routeDocument = $this->documentManager->find($routePath);
         } catch (DocumentNotFoundException $e) {
             $routeDocument = $this->documentManager->create('route');
         }
         $routeDocument->setTargetDocument($homeDocument);
         $this->documentManager->persist($routeDocument, $webspaceLocale, ['path' => $routePath, 'auto_create' => true]);
         $this->documentManager->publish($routeDocument, $webspaceLocale);
     }
     $this->documentManager->flush();
 }
Ejemplo n.º 4
0
 public function __construct(DocumentRegistry $documentRegistry, PathSegmentRegistry $pathSegmentRegistry, NamespaceRegistry $namespaceRegistry, ProxyFactory $proxyFactory, MetadataFactoryInterface $metadataFactory, StructureMetadataFactoryInterface $structureFactory, PropertyEncoder $encoder, WebspaceManagerInterface $webspaceManager)
 {
     parent::__construct($documentRegistry, $pathSegmentRegistry, $proxyFactory);
     $this->metadataFactory = $metadataFactory;
     $this->structureFactory = $structureFactory;
     $this->namespaceRegistry = $namespaceRegistry;
     $this->encoder = $encoder;
     $this->webspaceManager = $webspaceManager;
 }
 /**
  * @param PersistEvent $event
  */
 public function handleChangeParent(PersistEvent $event)
 {
     $document = $event->getDocument();
     $node = $this->inspector->getNode($document);
     $parentNode = $event->getParentNode();
     if ($parentNode->getPath() === $node->getParent()->getPath()) {
         return;
     }
     $this->documentManager->move($document, $parentNode->getPath());
 }
Ejemplo n.º 6
0
 /**
  * Sets the workflow properties on the given document.
  *
  * @param WorkflowStageBehavior $document
  * @param DocumentAccessor $accessor
  * @param string $workflowStage
  * @param string $locale
  * @param string $live
  *
  * @throws \Sulu\Component\DocumentManager\Exception\DocumentManagerException
  */
 private function setWorkflowStage(WorkflowStageBehavior $document, DocumentAccessor $accessor, $workflowStage, $locale, $live)
 {
     $path = $this->documentInspector->getPath($document);
     $document->setWorkflowStage($workflowStage);
     $updatePublished = !$document->getPublished() && $workflowStage === WorkflowStage::PUBLISHED;
     if ($updatePublished) {
         $accessor->set(self::PUBLISHED_FIELD, new \DateTime());
     }
     $defaultNode = $this->defaultSession->getNode($path);
     $this->setWorkflowStageOnNode($defaultNode, $locale, $workflowStage, $updatePublished);
     if ($live) {
         $liveNode = $this->liveSession->getNode($path);
         $this->setWorkflowStageOnNode($liveNode, $locale, $workflowStage, $updatePublished);
     }
 }
 /**
  * @param $template
  * @param $data
  * @param $parent
  *
  * @return PageDocument
  */
 private function savePage($template, $data, $parent, $tags = [])
 {
     $data = array_merge(['structureType' => $template, 'parent' => $parent, 'workflowStage' => 2, 'webspace_key' => 'sulu_io'], $data);
     $document = $this->documentManager->create('page');
     $options = ['csrf_protection' => false, 'webspace_key' => 'sulu_io'];
     $form = $this->formFactory->create('page', $document, $options);
     $clearMissing = false;
     $form->submit($data, $clearMissing);
     $this->documentManager->persist($document, 'en', ['user' => 1]);
     $this->documentManager->flush();
     $node = $this->inspector->getNode($document);
     $node->setProperty('i18n:en-excerpt-tags', $tags);
     $node->getSession()->save();
     return $document;
 }
Ejemplo n.º 8
0
 private function hasTitle($document)
 {
     $structure = $this->inspector->getStructureMetadata($document);
     return $structure->hasProperty('title');
 }
Ejemplo n.º 9
0
 /**
  * @param AbstractMappingEvent|HydrateEvent $event
  *
  * @throws \Sulu\Component\DocumentManager\Exception\DocumentManagerException
  */
 public function doHydrate(AbstractMappingEvent $event)
 {
     $document = $event->getDocument();
     $webspaceName = $this->inspector->getWebspace($document);
     $event->getAccessor()->set('webspaceName', $webspaceName);
 }
Ejemplo n.º 10
0
 private function removeReferences($document)
 {
     $node = $this->documentInspector->getNode($document);
     $this->removeReferencesForNode($this->defaultSession->getNode($node->getPath()));
     $this->removeReferencesForNode($this->liveSession->getNode($node->getPath()));
 }