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()); }
/** * 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; }
/** * Clear the register on the "clear" event. * * @param ClearEvent $event */ public function handleClear(ClearEvent $event) { $this->documentRegistry->clear(); }