예제 #1
0
 /**
  * Copy or move a node by UUID to a detination parent.
  *
  * Note that the bulk of this method is about the resource locator and can
  * be removed if we integrate the RoutingAuto component.
  *
  * @param string $webspaceKey
  * @param string $locale
  * @param bool $move
  *
  * @return StructureInterface
  */
 private function copyOrMove($uuid, $destParentUuid, $userId, $webspaceKey, $locale, $move = true)
 {
     // find localizations
     $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey);
     $localizations = $webspace->getAllLocalizations();
     // load from phpcr
     $document = $this->documentManager->find($uuid, $locale);
     $parentDocument = $this->documentManager->find($destParentUuid, $locale);
     if ($move) {
         // move node
         $this->documentManager->move($document, $destParentUuid);
     } else {
         // copy node
         $copiedPath = $this->documentManager->copy($document, $destParentUuid);
         $document = $this->documentManager->find($copiedPath, $locale);
         $this->documentManager->refresh($parentDocument);
     }
     $originalLocale = $locale;
     // modifiy the resource locators -- note this can be removed once the routing auto
     // system is implemented.
     foreach ($localizations as $locale) {
         $locale = $locale->getLocalization();
         if (!$document instanceof ResourceSegmentBehavior) {
             break;
         }
         // prepare parent content node
         // finding the document will update the locale without reloading from PHPCR
         $this->documentManager->find($document->getUuid(), $locale);
         $this->documentManager->find($parentDocument->getUuid(), $locale);
         $parentResourceLocator = '/';
         if ($parentDocument instanceof ResourceSegmentBehavior) {
             $parentResourceLocator = $parentDocument->getResourceSegment();
         }
         // TODO: This could be optimized
         $localizationState = $this->inspector->getLocalizationState($document);
         if ($localizationState !== LocalizationState::LOCALIZED) {
             continue;
         }
         if ($document->getRedirectType() !== RedirectType::NONE) {
             continue;
         }
         $strategy = $this->getResourceLocator()->getStrategy();
         $nodeName = PathHelper::getNodeName($document->getResourceSegment());
         $newResourceLocator = $strategy->generate($nodeName, $parentDocument->getResourceSegment(), $webspaceKey, $locale);
         $document->setResourceSegment($newResourceLocator);
         $this->documentManager->persist($document, $locale, array('user' => $userId));
     }
     $this->documentManager->flush();
     //
     $this->documentManager->find($document->getUuid(), $originalLocale);
     return $this->documentToStructure($document);
 }