/**
  * @return StructureInterface[]
  */
 private function prepareData()
 {
     $data = [['title' => 'Test1', 'url' => '/test-1', 'article' => 'Lorem Ipsum dolorem apsum', 'block' => [['type' => 'type1', 'title' => 'Block-Title-1', 'article' => ['Block-Article-1-1', 'Block-Article-1-2']], ['type' => 'type1', 'title' => 'Block-Title-2', 'article' => ['Block-Article-2-1', 'Block-Article-2-2']]]], ['title' => 'Test2', 'url' => '/test-2', 'article' => 'asdfasdf', 'block' => [['type' => 'type1', 'title' => 'Block-Title-2', 'article' => ['Block-Article-2-1', 'Block-Article-2-2']]]]];
     $data[0] = $this->mapper->save($data[0], 'overview', 'sulu_io', 'en', 1);
     $data[1] = $this->mapper->save($data[1], 'overview', 'sulu_io', 'en', 1);
     return $data;
 }
 public function testLoadSnippetLocale()
 {
     $dataDe = ['title' => 'de-test-title', 'description' => 'de-test-description'];
     $dataDe = $this->contentMapper->save($dataDe, 'car', 'default', 'de', 1, true, null, null, Structure::STATE_PUBLISHED, null, null, Structure::TYPE_SNIPPET);
     $dataEn = ['title' => 'en-test-title', 'description' => 'en-test-description'];
     $dataEn = $this->contentMapper->save($dataEn, 'car', 'default', 'en', 1, true, $dataDe->getUuid(), null, Structure::STATE_PUBLISHED, null, null, Structure::TYPE_SNIPPET);
     $snippet = $this->extension->loadSnippet($dataDe->getUuid(), 'en');
     $this->assertArrayHasKey('content', $snippet);
     $this->assertArrayHasKey('view', $snippet);
     $this->assertArrayHasKey('uuid', $snippet);
     $this->assertArrayHasKey('created', $snippet);
     $this->assertArrayHasKey('creator', $snippet);
     $this->assertArrayHasKey('changed', $snippet);
     $this->assertArrayHasKey('changer', $snippet);
     $this->assertCount(2, $snippet['view']);
     $this->assertCount(2, $snippet['content']);
     $this->assertEquals('en-test-title', $snippet['content']['title']);
     $this->assertEquals('en-test-description', $snippet['content']['description']);
     $this->assertEquals([], $snippet['view']['title']);
     $this->assertEquals([], $snippet['view']['description']);
     $snippet = $this->extension->loadSnippet($dataDe->getUuid(), 'de');
     $this->assertArrayHasKey('content', $snippet);
     $this->assertArrayHasKey('view', $snippet);
     $this->assertArrayHasKey('uuid', $snippet);
     $this->assertArrayHasKey('created', $snippet);
     $this->assertArrayHasKey('creator', $snippet);
     $this->assertArrayHasKey('changed', $snippet);
     $this->assertArrayHasKey('changer', $snippet);
     $this->assertCount(2, $snippet['view']);
     $this->assertCount(2, $snippet['content']);
     $this->assertEquals('de-test-title', $snippet['content']['title']);
     $this->assertEquals('de-test-description', $snippet['content']['description']);
     $this->assertEquals([], $snippet['view']['title']);
     $this->assertEquals([], $snippet['view']['description']);
 }
Exemple #3
0
 /**
  * @dataProvider provideSaveSnippetPage
  */
 public function testSaveLoadSnippetPage($webspaceKey, $templateKey, $locale, $data)
 {
     foreach ($data['hotels'] as &$varName) {
         $varName = $this->{$varName}->getUUid();
     }
     $req = ContentMapperRequest::create()->setType(Structure::TYPE_PAGE)->setWebspaceKey($webspaceKey)->setTemplateKey($templateKey)->setLocale($locale)->setState(StructureInterface::STATE_PUBLISHED)->setUserId(1)->setData($data);
     $page = $this->contentMapper->saveRequest($req);
     foreach ($data as $key => $value) {
         $this->assertEquals($value, $page->getPropertyValue($key));
     }
     $this->assertInstanceOf(PageBridge::class, $page);
     $this->assertEquals($templateKey, $page->getKey());
     $page = $this->contentMapper->load($page->getUuid(), $webspaceKey, $locale);
     $this->assertInstanceOf(PageBridge::class, $page);
     $this->assertEquals($templateKey, $page->getKey());
     foreach ($data as $key => $value) {
         if ($key === 'hotels') {
             continue;
         }
         $this->assertEquals($value, $page->getPropertyValue($key), 'Checking property "' . $key . '"');
     }
     $hotels = $page->getPropertyValue('hotels');
     $this->assertCount(count($data['hotels']), $hotels);
     $this->assertEquals($data['hotels'], $hotels);
 }
 /**
  * @return StructureInterface[]
  */
 private function prepareData()
 {
     $data = [['title' => 'Testtitle', 'tags' => ['tag1', 'tag2'], 'url' => '/news/test', 'article' => ['Test-1', 'Test-2']], ['title' => 'Testtitle2', 'tags' => ['tag1', 'tag2'], 'url' => '/news/test2', 'article' => ['Test-1', 'Test-2']]];
     $data[0] = $this->mapper->save($data[0], 'overview', 'sulu_io', 'en', 1);
     $data[1] = $this->mapper->save($data[1], 'overview', 'sulu_io', 'en', 1);
     return $data;
 }
 public function testSerialize()
 {
     $pageDocument = $this->createPage();
     $managedPage = $this->contentMapper->load($pageDocument->getUuid(), 'sulu_io', 'fr');
     $this->assertInstanceOf(StructureBridge::class, $managedPage);
     $result = $this->serializer->serialize($managedPage, 'json');
     return $result;
 }
 private function upgradeByParent(StructureBridge $parent, Webspace $webspace, Localization $localization, ContentMapperInterface $contentMapper, OutputInterface $output)
 {
     $pages = $contentMapper->loadByParent($parent->getUuid(), $webspace->getKey(), $localization->getLocalization(), 1);
     /** @var Page $page */
     foreach ($pages as $page) {
         $this->upgradeNode($page, $webspace, $localization, $output, substr_count($page->getPath(), '/'));
         $this->upgradeByParent($page, $webspace, $localization, $contentMapper, $output);
     }
 }
 /**
  * @return \Sulu\Component\Content\Compat\StructureInterface
  */
 private function prepareHistoryTestData()
 {
     $structure = $this->mapper->save(['title' => 'test-1', 'url' => '/test'], 'overview', 'sulu_io', 'en', 1);
     sleep(1);
     $structure = $this->mapper->save(['title' => 'test-1', 'url' => '/test-1'], 'overview', 'sulu_io', 'en', 1, true, $structure->getUuid());
     sleep(1);
     $structure = $this->mapper->save(['title' => 'test-1', 'url' => '/test-2'], 'overview', 'sulu_io', 'en', 1, true, $structure->getUuid());
     return $structure;
 }
Exemple #8
0
 /**
  * {@inheritdoc}
  */
 public function loadSnippet($uuid, $locale = null)
 {
     if ($locale === null) {
         $locale = $this->requestAnalyzer->getCurrentLocalization()->getLocalization();
     }
     try {
         $snippet = $this->contentMapper->load($uuid, $this->requestAnalyzer->getWebspace()->getKey(), $locale);
         return $this->structureResolver->resolve($snippet);
     } catch (DocumentNotFoundException $ex) {
         return;
     }
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function execute($webspaceKey, $locales, ContentQueryBuilderInterface $contentQueryBuilder, $flat = true, $depth = -1, $limit = null, $offset = null, $moveUp = false)
 {
     if ($this->stopwatch) {
         $this->stopwatch->start('ContentQuery::execute.build-query');
     }
     list($sql2, $fields) = $contentQueryBuilder->build($webspaceKey, $locales);
     if ($this->stopwatch) {
         $this->stopwatch->stop('ContentQuery::execute.build-query');
         $this->stopwatch->start('ContentQuery::execute.execute-query');
     }
     $query = $this->createSql2Query($sql2, $limit, $offset);
     $queryResult = $query->execute();
     if ($this->stopwatch) {
         $this->stopwatch->stop('ContentQuery::execute.execute-query');
         $this->stopwatch->start('ContentQuery::execute.preload-nodes.get-paths');
     }
     // this preloads all node which should are selected in the statement before
     // prevent the system to load each node individual
     $rootDepth = substr_count($this->sessionManager->getContentPath($webspaceKey), '/');
     $paths = [];
     /** @var Row $row */
     foreach ($queryResult as $row) {
         $pageDepth = substr_count($row->getPath('page'), '/') - $rootDepth;
         if ($depth === null || $depth < 0 || $depth > 0 && $pageDepth <= $depth) {
             $paths[] = $row->getPath('page');
         }
     }
     if ($this->stopwatch) {
         $this->stopwatch->stop('ContentQuery::execute.preload-nodes.get-paths');
         $this->stopwatch->start('ContentQuery::execute.preload-nodes.execute');
     }
     $this->sessionManager->getSession()->getNodes($paths);
     if ($this->stopwatch) {
         $this->stopwatch->stop('ContentQuery::execute.preload-nodes.execute');
         $this->stopwatch->start('ContentQuery::execute.rowsToList');
     }
     $result = $this->contentMapper->convertQueryResultToArray($queryResult, $webspaceKey, $locales, $fields, $depth, $contentQueryBuilder->getPublished());
     if ($this->stopwatch) {
         $this->stopwatch->stop('ContentQuery::execute.rowsToList');
     }
     if (!$flat) {
         if ($this->stopwatch) {
             $this->stopwatch->start('ContentQuery::execute.build-tree');
         }
         $converter = new ListToTreeConverter($moveUp);
         $result = $converter->convert($result);
         if ($this->stopwatch) {
             $this->stopwatch->stop('ContentQuery::execute.build-tree');
         }
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function warmUp($userId, $contentUuid, $webspaceKey, $locale)
 {
     $this->delete($userId, $contentUuid, $webspaceKey, $locale);
     $page = $this->contentMapper->load($contentUuid, $webspaceKey, $locale);
     $this->saveStructure($page, $userId, $contentUuid, $webspaceKey, $locale);
     $this->saveChanges([], $userId, $contentUuid, $webspaceKey, $locale);
     return $this->fetchStructure($userId, $contentUuid, $webspaceKey, $locale);
 }
 private function save($data, $locale, $uuid = null, $parent = null, $isShadow = false, $shadowLocale = '', $state = Structure::STATE_PUBLISHED)
 {
     $node = $this->mapper->save($data, 'simple', 'sulu_io', $locale, 1, true, $uuid, $parent, $state);
     if ($isShadow) {
         $node = $this->mapper->save(['title' => $data['title']], 'simple', 'sulu_io', $locale, 1, true, $uuid, $parent, $state, $isShadow, $shadowLocale);
     }
     return [$node->getPropertyValue('url') => $node];
 }
 /**
  * Finds the correct route for the current request.
  * It loads the correct data with the content mapper.
  *
  * @param Request $request A request against which to match.
  *
  * @return \Symfony\Component\Routing\RouteCollection with all Routes that
  *                                                    could potentially match $request. Empty collection if nothing can
  *                                                    match.
  */
 public function getRouteCollectionForRequest(Request $request)
 {
     $collection = new RouteCollection();
     $htmlExtension = '.html';
     $resourceLocator = $this->requestAnalyzer->getResourceLocator();
     if ($this->requestAnalyzer->getMatchType() == RequestAnalyzerInterface::MATCH_TYPE_REDIRECT || $this->requestAnalyzer->getMatchType() == RequestAnalyzerInterface::MATCH_TYPE_PARTIAL) {
         // redirect webspace correctly with language
         $collection->add('redirect_' . uniqid(), $this->getRedirectWebSpaceRoute($request));
     } elseif ($request->getRequestFormat() === 'html' && substr($request->getPathInfo(), -strlen($htmlExtension)) === $htmlExtension) {
         // redirect *.html to * (without url)
         $collection->add('redirect_' . uniqid(), $this->getRedirectRoute($request, $this->getUrlWithoutEndingTrailingSlash($resourceLocator)));
     } else {
         // just show the page
         $portal = $this->requestAnalyzer->getPortal();
         $language = $this->requestAnalyzer->getCurrentLocalization()->getLocalization();
         try {
             // load content by url ignore ending trailing slash
             $content = $this->contentMapper->loadByResourceLocator(rtrim($resourceLocator, '/'), $portal->getWebspace()->getKey(), $language);
             if (preg_match('/\\/$/', $resourceLocator) && $this->requestAnalyzer->getResourceLocatorPrefix() && $content->getNodeState() === StructureInterface::STATE_PUBLISHED) {
                 // redirect page to page without slash at the end
                 $collection->add('redirect_' . uniqid(), $this->getRedirectWebSpaceRoute($request));
             } elseif ($content->getNodeType() === Structure::NODE_TYPE_INTERNAL_LINK && $content->getNodeState() === StructureInterface::STATE_PUBLISHED) {
                 // redirect internal link
                 $collection->add($content->getKey() . '_' . uniqid(), $this->getRedirectRoute($request, $this->requestAnalyzer->getResourceLocatorPrefix() . $content->getResourceLocator()));
             } elseif ($content->getNodeType() === Structure::NODE_TYPE_EXTERNAL_LINK && $content->getNodeState() === StructureInterface::STATE_PUBLISHED) {
                 $collection->add($content->getKey() . '_' . uniqid(), $this->getRedirectRoute($request, $content->getResourceLocator()));
             } elseif ($content->getNodeState() === StructureInterface::STATE_TEST || !$content->getHasTranslation() || !$this->checkResourceLocator()) {
                 // error 404 page not published
                 throw new ResourceLocatorNotFoundException();
             } else {
                 // show the page
                 $collection->add($content->getKey() . '_' . uniqid(), $this->getStructureRoute($request, $content));
             }
         } catch (ResourceLocatorNotFoundException $exc) {
             // just do not add any routes to the collection
         } catch (ResourceLocatorMovedException $exc) {
             // old url resource was moved
             $collection->add($exc->getNewResourceLocatorUuid() . '_' . uniqid(), $this->getRedirectRoute($request, $this->requestAnalyzer->getResourceLocatorPrefix() . $exc->getNewResourceLocator()));
         } catch (RepositoryException $exc) {
             // just do not add any routes to the collection
         }
     }
     return $collection;
 }
Exemple #13
0
 /**
  * {@inheritdoc}
  */
 public function getBreadcrumb($uuid, $webspace, $language)
 {
     $breadcrumbItems = $this->contentMapper->loadBreadcrumb($uuid, $language, $webspace);
     $result = [];
     foreach ($breadcrumbItems as $item) {
         $result[] = $this->contentMapper->load($item->getUuid(), $webspace, $language);
     }
     $result[] = $this->contentMapper->load($uuid, $webspace, $language);
     return $this->generateNavigation($result, $webspace, $language, false, null, true, false);
 }
Exemple #14
0
 /**
  * {@inheritdoc}
  */
 public function resolve($uuids, $webspaceKey, $locale, $shadowLocale = null)
 {
     $snippets = [];
     foreach ($uuids as $uuid) {
         if (!array_key_exists($uuid, $this->snippetCache)) {
             $snippet = $this->contentMapper->load($uuid, $webspaceKey, $locale);
             if (!$snippet->getHasTranslation() && $shadowLocale !== null) {
                 $snippet = $this->contentMapper->load($uuid, $webspaceKey, $shadowLocale);
             }
             $snippet->setIsShadow($shadowLocale !== null);
             $snippet->setShadowBaseLanguage($shadowLocale);
             $resolved = $this->structureResolver->resolve($snippet);
             $resolved['view']['template'] = $snippet->getKey();
             $resolved['view']['uuid'] = $snippet->getUuid();
             $this->snippetCache[$uuid] = $resolved;
         }
         $snippets[] = $this->snippetCache[$uuid];
     }
     return $snippets;
 }
Exemple #15
0
 public function testGetReferencedUuids()
 {
     $pageNode = $this->session->getNode('/cmf/sulu_io/contents/hotels');
     $pageStructure = $this->contentMapper->loadByNode($pageNode, 'en', 'sulu_io', true, false, false);
     $property = $pageStructure->getProperty('hotels');
     $uuids = $this->contentType->getReferencedUuids($property);
     $this->assertCount(2, $uuids);
     foreach ($uuids as $uuid) {
         $this->assertTrue(UUIDHelper::isUuid($uuid));
     }
 }
 private function copyNode($srcLocale, $destLocale, StructureInterface $structure, $overwrite = false)
 {
     if (!$overwrite) {
         $destStructure = $this->contentMapper->load($structure->getUuid(), null, $destLocale, true);
         if (!($destStructure->getType() && $destStructure->getType()->getName() === 'ghost')) {
             $this->output->writeln('<info>Processing aborted: </info>' . $structure->getNodeName() . ' <comment>(use overwrite option to force)</comment>');
             return;
         }
     }
     $this->contentMapper->copyLanguage($structure->getUuid(), $structure->getChanger(), null, $srcLocale, $destLocale, Structure::TYPE_SNIPPET);
     $this->output->writeln('<info>Processing: </info>' . $structure->getNodeName());
 }
 /**
  * {@inheritdoc}
  */
 public function treeNavigationFunction($uuid, $context = null, $depth = 1, $loadExcerpt = false, $level = null)
 {
     $webspaceKey = $this->requestAnalyzer->getWebspace()->getKey();
     $locale = $this->requestAnalyzer->getCurrentLocalization()->getLocalization();
     if ($level !== null) {
         $breadcrumb = $this->contentMapper->loadBreadcrumb($uuid, $locale, $webspaceKey);
         // return empty array if level does not exists
         if (!isset($breadcrumb[$level])) {
             return [];
         }
         $uuid = $breadcrumb[$level]->getUuid();
     }
     return $this->navigationMapper->getNavigation($uuid, $webspaceKey, $locale, $depth, false, $context, $loadExcerpt);
 }
Exemple #18
0
 /**
  * load snippet and serialize them.
  *
  * additionally cache it by id in this class
  */
 private function loadSnippets($ids, $webspaceKey, $locale, $shadowLocale = null)
 {
     $snippets = [];
     foreach ($ids as $i => $ref) {
         if (!array_key_exists($ref, $this->snippetCache)) {
             $snippet = $this->contentMapper->load($ref, $webspaceKey, $locale);
             if (!$snippet->getHasTranslation() && $shadowLocale !== null) {
                 $snippet = $this->contentMapper->load($ref, $webspaceKey, $shadowLocale);
             }
             $resolved = $this->structureResolver->resolve($snippet);
             $resolved['view']['template'] = $snippet->getKey();
             $this->snippetCache[$ref] = $resolved;
         }
         $snippets[] = $this->snippetCache[$ref];
     }
     return $snippets;
 }
 private function copyNode($webspaceKey, $srcLocale, $destLocale, StructureInterface $structure, $overwrite = false)
 {
     if (!$overwrite) {
         $destStructure = $this->contentMapper->load($structure->getUuid(), $webspaceKey, $destLocale, true);
         if (!($destStructure->getType() && $destStructure->getType()->getName() === 'ghost')) {
             $this->output->writeln('<info>Processing aborted: </info>' . $structure->getPath() . ' <comment>(use overwrite option to force)</comment>');
             return;
         }
     }
     if ($structure->getType() && $structure->getType()->getName() === 'ghost') {
         $this->output->writeln('<info>Processing aborted: </info>' . $structure->getPath() . ' <comment>(source language does not exist)</comment>');
         return;
     }
     try {
         $this->contentMapper->copyLanguage($structure->getUuid(), $structure->getChanger(), $webspaceKey, $srcLocale, $destLocale);
         $this->output->writeln('<info>Processing: </info>' . $structure->getPath());
     } catch (ResourceLocatorAlreadyExistsException $e) {
         $this->output->writeln(sprintf('<info>Processing aborted: </info> %s <comment>Resource Locator "%s" already exists', $structure->getPath(), $structure->getResourceLocator()));
     }
 }
 /**
  * Start preview session.
  *
  * @param ConnectionInterface   $conn
  * @param MessageHandlerContext $context
  * @param array                 $msg
  *
  * @return array
  *
  * @throws MissingParameterException
  */
 private function start(ConnectionInterface $conn, MessageHandlerContext $context, $msg)
 {
     // locale
     if (!array_key_exists('locale', $msg)) {
         throw new MissingParameterException('locale');
     }
     $locale = $msg['locale'];
     $context->set('locale', $locale);
     // webspace key
     if (!array_key_exists('webspaceKey', $msg)) {
         throw new MissingParameterException('webspaceKey');
     }
     $webspaceKey = $msg['webspaceKey'];
     $context->set('webspaceKey', $webspaceKey);
     // user id
     if (!array_key_exists('user', $msg)) {
         throw new MissingParameterException('user');
     }
     $user = $msg['user'];
     $context->set('user', $user);
     // content uuid
     if (!array_key_exists('content', $msg)) {
         throw new MissingParameterException('content');
     }
     $contentUuid = $msg['content'];
     // filter index page
     if ($contentUuid === 'index') {
         $startPage = $this->contentMapper->loadStartPage($webspaceKey, $locale);
         $contentUuid = $startPage->getUuid();
     }
     $context->set('content', $contentUuid);
     // init message vars
     $template = array_key_exists('template', $msg) ? $msg['template'] : null;
     $data = array_key_exists('data', $msg) ? $msg['data'] : null;
     // start preview
     $this->preview->start($user, $contentUuid, $webspaceKey, $locale, $data, $template);
     return ['command' => 'start', 'content' => $contentUuid, 'msg' => 'OK'];
 }
Exemple #21
0
 /**
  * Return the structure which was deleted.
  *
  * @return StructureInterface
  */
 public function getStructure($locale)
 {
     return $this->contentMapper->loadShallowStructureByNode($this->node, $locale, $this->webspace);
 }
 public function testLoadParentStartPage()
 {
     $this->setExpectedException('Sulu\\Bundle\\WebsiteBundle\\Twig\\Exception\\ParentNotFoundException', 'Parent for "321-321-321" not found (perhaps it is the startpage?)');
     $extension = new ContentTwigExtension($this->contentMapper->reveal(), $this->structureResolver, $this->sessionManager->reveal(), $this->requestAnalyzer->reveal());
     $extension->loadParent('321-321-321');
 }
 /**
  * {@inheritdoc}
  */
 public function restore($path, $userId, $webspaceKey, $languageCode, $segmentKey = null)
 {
     $this->contentMapper->restoreHistoryPath($path, $userId, $webspaceKey, $languageCode, $segmentKey);
     return ['resourceLocator' => $path, '_links' => []];
 }
 /**
  * @param string $uuid
  * @return array
  */
 public function load($uuid)
 {
     $contentStructure = $this->contentMapper->load($uuid, $this->requestAnalyzer->getWebspace()->getKey(), $this->requestAnalyzer->getCurrentLocalization()->getLocalization());
     return $this->structureResolver->resolve($contentStructure);
 }