public function handlePersist(PersistEvent $event)
 {
     $document = $event->getDocument();
     if (!$this->supports($document)) {
         return;
     }
     $parentName = $this->getParentName($document);
     $path = sprintf('%s/%s', $this->basePath, $parentName);
     $parentNode = $this->nodeManager->createPath($path);
     $event->setParentNode($parentNode);
 }
 /**
  * @param FindEvent $event
  *
  * @throws DocumentManagerException
  * @throws DocumentNotFoundException
  */
 public function handleFind(FindEvent $event)
 {
     $options = $event->getOptions();
     $aliasOrClass = $options['type'];
     $node = $this->nodeManager->find($event->getId());
     $hydrateEvent = new HydrateEvent($node, $event->getLocale(), $options);
     $this->eventDispatcher->dispatch(Events::HYDRATE, $hydrateEvent);
     $document = $hydrateEvent->getDocument();
     if ($aliasOrClass) {
         $this->checkAliasOrClass($aliasOrClass, $document);
     }
     $event->setDocument($hydrateEvent->getDocument());
 }
 private function resolveParent($parentPath, array $options)
 {
     $autoCreate = $options['auto_create'];
     if ($autoCreate) {
         return $this->nodeManager->createPath($parentPath);
     }
     return $this->nodeManager->find($parentPath);
 }
 private function resolveSiblingName($siblingId, NodeInterface $parentNode, NodeInterface $node)
 {
     if (null === $siblingId) {
         return;
     }
     $siblingPath = $siblingId;
     if (UUIDHelper::isUUID($siblingId)) {
         $siblingPath = $this->nodeManager->find($siblingId)->getPath();
     }
     if ($siblingPath !== null && PathHelper::getParentPath($siblingPath) !== $parentNode->getPath()) {
         throw new DocumentManagerException(sprintf('Cannot reorder documents which are not siblings. Trying to reorder "%s" to "%s"', $node->getPath(), $siblingPath));
     }
     if (null !== $siblingPath) {
         return PathHelper::getNodeName($siblingPath);
     }
     return $node->getName();
 }
Example #5
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();
 }
Example #6
0
 /**
  * Load the given fixture classes.
  *
  * @param array           $fixtures
  * @param mixed           $purge
  * @param mixed           $initialize
  * @param OutputInterface $output
  */
 public function execute(array $fixtures, $purge = true, $initialize = true, OutputInterface $output = null)
 {
     $output = $output ?: new NullOutput();
     if (true === $purge) {
         $output->writeln('<comment>Purging workspace</comment>');
         $this->nodeManager->purgeWorkspace();
         $this->nodeManager->save();
     }
     if (true === $initialize) {
         $output->writeln('<comment>Initializing repository</comment>');
         $this->initializer->initialize($output);
     }
     $output->writeln('<comment>Loading fixtures</comment>');
     foreach ($fixtures as $fixture) {
         $output->writeln(sprintf(' - %s<info>loading "</info>%s<info>"</info>', $fixture instanceof OrderedFixtureInterface ? '[' . $fixture->getOrder() . ']' : '', get_class($fixture)));
         $fixture->load($this->documentManager);
         $this->documentManager->clear();
     }
 }
 /**
  * It should set the parent document.
  */
 public function testSetParentDocument()
 {
     $this->persistEvent->getDocument()->willReturn($this->document->reveal());
     $this->persistEvent->getLocale()->willReturn('fr');
     $this->metadataFactory->getMetadataForClass(get_class($this->document->reveal()))->willReturn($this->metadata->reveal());
     $this->metadata->getAlias()->willReturn('test');
     $this->nodeManager->createPath('/')->willReturn($this->parentNode->reveal());
     $this->persistEvent->hasParentNode()->shouldBeCalled();
     $this->persistEvent->setParentNode($this->parentNode->reveal())->shouldBeCalled();
     $this->documentManager->find('/test', 'fr')->willReturn($this->parentDocument);
     $this->subscriber->handlePersist($this->persistEvent->reveal());
 }
 /**
  * Resolve the destination name on move and copy events.
  *
  * @param MoveEvent $event
  */
 private function handleMoveCopy(MoveEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof AutoNameBehavior) {
         return;
     }
     $destId = $event->getDestId();
     $node = $this->registry->getNodeForDocument($document);
     $destNode = $this->nodeManager->find($destId);
     $nodeName = $this->resolver->resolveName($destNode, $node->getName());
     $event->setDestName($nodeName);
 }
Example #9
0
 public function initialize(OutputInterface $output, $purge = false)
 {
     $nodeTypeManager = $this->sessionManager->getSession()->getWorkspace()->getNodeTypeManager();
     foreach ([new CustomUrlNodeType(), new CustomUrlRouteNodeType()] as $nodeType) {
         $nodeTypeManager->registerNodeType($nodeType, true);
     }
     /** @var Webspace $webspace */
     foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
         $itemsPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%custom_urls%', '%custom_urls_items%']);
         $routesPath = $this->pathBuilder->build(['%base%', $webspace->getKey(), '%custom_urls%', '%custom_urls_routes%']);
         $output->writeln(sprintf('  <info>%s</info>:', $webspace->getName()));
         if (true === $this->nodeManager->has($itemsPath)) {
             $output->writeln(sprintf('  [ ] <info>items path:</info>: %s ', $itemsPath));
         } else {
             $output->writeln(sprintf('  [+] <info>items path:</info>: %s ', $itemsPath));
             $this->nodeManager->createPath($itemsPath);
         }
         if (true === $this->nodeManager->has($routesPath)) {
             $output->writeln(sprintf('  [ ] <info>items path:</info>: %s ', $routesPath));
         } else {
             $output->writeln(sprintf('  [+] <info>items path:</info>: %s ', $routesPath));
             $this->nodeManager->createPath($routesPath);
         }
         $this->nodeManager->save();
     }
 }
Example #10
0
 /**
  * @param ObjectEvent $event
  */
 public function onPostDeserialize(ObjectEvent $event)
 {
     $document = $event->getObject();
     // only register documents
     if (!$this->metadataFactory->hasMetadataForClass(get_class($document))) {
         return;
     }
     if (!$document->getUuid()) {
         return;
     }
     try {
         $node = $this->nodeManager->find($document->getUuid());
     } catch (DocumentNotFoundException $e) {
         return;
     }
     if ($this->registry->hasNode($node, $document->getLocale())) {
         $registeredDocument = $this->registry->getDocumentForNode($node, $document->getLocale());
         $this->registry->deregisterDocument($registeredDocument);
     }
     // TODO use the original locale somehow
     if (!$this->registry->hasDocument($document)) {
         $this->registry->registerDocument($document, $node, $document->getLocale());
     }
 }
 /**
  * @param FlushEvent $event
  */
 public function handleFlush(FlushEvent $event)
 {
     $this->nodeManager->save();
 }