/** * It should return the resource locators including the reosurce locator * of the shadow page. */ public function testGetResourceLocatorsWithShadow() { $page = $this->documentManager->create('page'); $page->setStructureType('overview'); $page->setTitle('Beschreibung'); $page->setResourceSegment('/beschreibung'); $page->setWorkflowStage(WorkflowStage::PUBLISHED); $this->documentManager->persist($page, 'de', ['parent_path' => '/cmf/sulu_io/contents']); $this->documentManager->flush(); $page->setTitle('Description'); $page->setResourceSegment('/description'); $page->setWorkflowStage(WorkflowStage::TEST); $this->documentManager->persist($page, 'en', ['parent_path' => '/cmf/sulu_io/contents']); $this->documentManager->flush(); $page->setShadowLocaleEnabled(true); $page->setShadowLocale('de'); $this->documentManager->persist($page, 'en', ['parent_path' => '/cmf/sulu_io/contents']); $this->documentManager->flush(); $content = $this->mapper->load($page->getUuid(), 'sulu_io', 'en'); $urls = $content->getUrls(); $this->assertArrayHasKey('en', $urls); $this->assertEquals('/description', $urls['en']); $this->assertArrayNotHasKey('en_us', $urls); $this->assertArrayHasKey('de', $urls); $this->assertEquals('/beschreibung', $urls['de']); $this->assertArrayNotHasKey('de_at', $urls); $this->assertArrayNotHasKey('es', $urls); }
public function testRun() { $this->initPhpcr(); $snippet = $this->documentManager->create('snippet'); $snippet->setStructureType('car'); $snippet->setTitle('Hallo'); $snippet->getStructure()->bind(['description' => 'This is a perfect description.']); $this->documentManager->persist($snippet, 'en', ['parent_path' => '/cmf/snippets/car']); $this->documentManager->flush(); $this->tester->execute(['srcLocale' => 'en', 'destLocale' => 'de']); $output = $this->tester->getDisplay(); $this->assertContains('Done', $output); $this->documentRegistry->clear(); $resultEN = $this->documentManager->find($snippet->getUuid(), 'en'); $resultDE = $this->documentManager->find($snippet->getUuid(), 'de'); $this->assertEquals('Hallo', $resultDE->getTitle()); $this->assertEquals('Hallo', $resultEN->getTitle()); $this->assertEquals('This is a perfect description.', $resultDE->getStructure()->getProperty('description')->getValue()); $this->assertEquals('This is a perfect description.', $resultEN->getStructure()->getProperty('description')->getValue()); }
public function testRun() { $this->initPhpcr(); $page = $this->documentManager->create('page'); $page->setStructureType('default'); $page->setTitle('Hallo'); $page->getStructure()->bind(['article' => 'This is a perfect description.']); $page->setResourceSegment('/hallo'); $this->documentManager->persist($page, 'de', ['parent_path' => '/cmf/sulu_io/contents']); $this->documentManager->flush(); $this->tester->execute(['webspaceKey' => 'sulu_io', 'srcLocale' => 'de', 'destLocale' => 'en']); $output = $this->tester->getDisplay(); $this->assertContains('Done', $output); $this->documentRegistry->clear(); $resultEN = $this->documentManager->find($page->getUuid(), 'en'); $resultDE = $this->documentManager->find($page->getUuid(), 'de'); $this->assertEquals('Hallo', $resultDE->getTitle()); $this->assertEquals('Hallo', $resultEN->getTitle()); $this->assertEquals('This is a perfect description.', $resultDE->getStructure()->getProperty('article')->getValue()); $this->assertEquals('This is a perfect description.', $resultEN->getStructure()->getProperty('article')->getValue()); $this->assertEquals('/hallo', $resultDE->getResourceSegment()); $this->assertEquals('/hallo', $resultEN->getResourceSegment()); }
private function processForm(Request $request, $document) { $locale = $this->getLocale($request); $data = $request->request->all(); $data['workflowStage'] = $request->get('state', WorkflowStage::PUBLISHED); $form = $this->formFactory->create('snippet', $document, ['csrf_protection' => false]); $form->submit($data, false); if (!$form->isValid()) { throw new InvalidFormException($form); } $this->documentManager->persist($document, $locale, ['user' => $this->getUser()->getId(), 'clear_missing_content' => false]); $this->documentManager->publish($document, $locale); $this->documentManager->flush(); return $form; }
/** * Import document by locale into given webspace. * * @param array $parsedData * @param string $webspaceKey * @param string $locale * * @return bool */ protected function importDocument(array $parsedData, $format, $webspaceKey, $locale, $overrideSettings) { $uuid = null; try { if (!isset($parsedData['uuid']) || !isset($parsedData['structureType']) || !isset($parsedData['data'])) { $this->addException('uuid, structureType or data for import not found.', 'ignore'); throw new \Exception('uuid, structureType or data for import not found.'); } $uuid = $parsedData['uuid']; $structureType = $parsedData['structureType']; $data = $parsedData['data']; $documentType = Structure::TYPE_PAGE; if ($this->getParser($format)->getPropertyData('url', $data) === '/') { $documentType = 'home'; // TODO no constant } /** @var BasePageDocument $document */ $document = $this->documentManager->find($uuid, $locale, ['type' => $documentType, 'load_ghost_content' => false]); $document->setStructureType($structureType); if ($document->getWebspaceName() != $webspaceKey) { $this->addException(sprintf('Document(%s) is part of another webspace: "%s"', $uuid, $document->getWebspaceName()), 'ignore'); throw new \Exception(sprintf('Document(%s) is part of another webspace: "%s"', $uuid, $document->getWebspaceName())); } if (!$document instanceof BasePageDocument) { throw new \Exception(sprintf('Document(%s) is not an instanecof BasePageDocument', $uuid)); } if (!$this->setDocumentData($document, $structureType, $webspaceKey, $locale, $format, $data)) { return false; } $this->setDocumentSettings($document, $structureType, $webspaceKey, $locale, $format, $data, $overrideSettings); // save document $this->documentManager->persist($document, $locale); $this->documentManager->publish($document, $locale); $this->documentManager->flush(); $this->documentRegistry->clear(); // FIXME else it failed on multiple page import return true; } catch (\Exception $e) { if ($e instanceof DocumentManagerException) { return; } $this->logger->error(sprintf('<info>%s</info>%s: <error>%s</error>%s', $uuid, PHP_EOL . get_class($e), $e->getMessage(), PHP_EOL . $e->getTraceAsString())); $this->documentManager->flush(); $this->documentManager->clear(); } return false; }
/** * 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); }
/** * 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->getUuid()); } $this->documentManager->flush(); return $this->documentToStructure($document); }