/**
  * @param HasNodeInterface $hasNode         The object
  * @param NodeTranslation  $nodeTranslation The node translation
  * @param BaseUser         $owner           The user
  * @param NodeVersion      $origin          The nodeVersion this nodeVersion originated from
  * @param string           $type            (public|draft)
  * @param DateTime         $created         The date this node version is created
  *
  * @return NodeVersion
  */
 public function createNodeVersionFor(HasNodeInterface $hasNode, NodeTranslation $nodeTranslation, BaseUser $owner, NodeVersion $origin = null, $type = 'public', $created = null)
 {
     $em = $this->getEntityManager();
     $nodeVersion = new NodeVersion();
     $nodeVersion->setNodeTranslation($nodeTranslation);
     $nodeVersion->setType($type);
     $nodeVersion->setOwner($owner);
     $nodeVersion->setRef($hasNode);
     $nodeVersion->setOrigin($origin);
     if (!is_null($created)) {
         $nodeVersion->setCreated($created);
     }
     $em->persist($nodeVersion);
     $em->flush();
     $em->refresh($nodeVersion);
     return $nodeVersion;
 }
 /**
  * Create a search document for a page
  *
  * @param NodeTranslation  $nodeTranslation
  * @param Node             $node
  * @param NodeVersion      $publicNodeVersion
  * @param HasNodeInterface $page
  */
 protected function addPageToIndex(NodeTranslation $nodeTranslation, Node $node, NodeVersion $publicNodeVersion, HasNodeInterface $page)
 {
     $rootNode = $this->currentTopNode;
     if (!$rootNode) {
         // Fetch main parent of current node...
         $rootNode = $this->em->getRepository('KunstmaanNodeBundle:Node')->getRootNodeFor($node, $nodeTranslation->getLang());
     }
     $doc = array('root_id' => $rootNode->getId(), 'node_id' => $node->getId(), 'node_translation_id' => $nodeTranslation->getId(), 'node_version_id' => $publicNodeVersion->getId(), 'title' => $nodeTranslation->getTitle(), 'lang' => $nodeTranslation->getLang(), 'slug' => $nodeTranslation->getFullSlug(), 'page_class' => ClassLookup::getClass($page), 'created' => $this->getUTCDateTime($nodeTranslation->getCreated())->format(\DateTime::ISO8601), 'updated' => $this->getUTCDateTime($nodeTranslation->getUpdated())->format(\DateTime::ISO8601));
     if ($this->logger) {
         $this->logger->info('Indexing document : ' . implode(', ', $doc));
     }
     // Permissions
     $this->addPermissions($node, $doc);
     // Search type
     $this->addSearchType($page, $doc);
     // Analyzer field
     $this->addAnalyzer($nodeTranslation, $doc);
     // Parent and Ancestors
     $this->addParentAndAncestors($node, $doc);
     // Content
     $this->addPageContent($nodeTranslation, $page, $doc);
     // Add document to index
     $uid = 'nodetranslation_' . $nodeTranslation->getId();
     $this->addBoost($node, $page, $doc);
     $this->addCustomData($page, $doc);
     $this->documents[] = $this->searchProvider->createDocument($uid, $doc, $this->indexName, $this->indexType . '_' . $nodeTranslation->getLang());
 }
示例#3
0
 public function postFlushBuild(Fixture $fixture)
 {
     $entities = $fixture->getAdditionalEntities();
     $fixtureParams = $fixture->getParameters();
     foreach ($fixture->getTranslations() as $language => $data) {
         /** @var HasNodeInterface $page */
         $page = $entities[$fixture->getName() . '_' . $language];
         /** @var NodeTranslation $translationNode */
         $translationNode = $entities['translationNode_' . $language];
         $pagecreator = array_key_exists('creator', $fixtureParams) ? $fixtureParams['creator'] : 'pagecreator';
         $creator = $this->userRepo->findOneBy(array('username' => $pagecreator));
         $nodeVersion = new NodeVersion();
         $nodeVersion->setNodeTranslation($translationNode);
         $nodeVersion->setType('public');
         $nodeVersion->setOwner($creator);
         $nodeVersion->setRef($page);
         $translationNode->setPublicNodeVersion($nodeVersion);
         if (isset($fixtureParams['template'])) {
             $pageTemplateConfiguration = new PageTemplateConfiguration();
             $pageTemplateConfiguration->setPageId($page->getId());
             $pageTemplateConfiguration->setPageEntityName(ClassLookup::getClass($page));
             $pageTemplateConfiguration->setPageTemplate($fixtureParams['template']);
             $this->manager->persist($pageTemplateConfiguration);
         }
         $this->manager->persist($nodeVersion);
         $this->manager->persist($translationNode);
     }
     $this->manager->flush();
 }
 /**
  * @covers Kunstmaan\NodeBundle\Entity\NodeTranslation::addNodeVersion
  * @covers Kunstmaan\NodeBundle\Entity\NodeTranslation::getNodeVersion
  */
 public function testAddGetNodeVersion()
 {
     $nodeVersion1 = new NodeVersion();
     $nodeVersion1->setType('public');
     $this->object->addNodeVersion($nodeVersion1);
     $nodeVersion2 = new NodeVersion();
     $nodeVersion2->setType('draft');
     $this->object->addNodeVersion($nodeVersion2);
     $this->assertEquals($nodeVersion1, $this->object->getNodeVersion('public'));
     $this->assertEquals($nodeVersion2, $this->object->getNodeVersion('draft'));
 }
 /**
  * Add nodeVersion
  *
  * @param NodeVersion $nodeVersion
  *
  * @return NodeTranslation
  */
 public function addNodeVersion(NodeVersion $nodeVersion)
 {
     $this->nodeVersions[] = $nodeVersion;
     $nodeVersion->setNodeTranslation($this);
     if ($nodeVersion->getType() == 'public') {
         $this->publicNodeVersion = $nodeVersion;
     }
     return $this;
 }
 /**
  * @covers Kunstmaan\NodeBundle\Entity\NodeVersion::getDefaultAdminType
  */
 public function testGetDefaultAdminType()
 {
     $this->assertNull($this->object->getDefaultAdminType());
 }
 /**
  * @param HasNodeInterface $page            The page
  * @param NodeTranslation  $nodeTranslation The node translation
  * @param NodeVersion      $nodeVersion     The node version
  *
  * @return NodeVersion
  */
 private function createDraftVersion(HasNodeInterface $page, NodeTranslation $nodeTranslation, NodeVersion $nodeVersion)
 {
     $publicPage = $this->get('kunstmaan_admin.clone.helper')->deepCloneAndSave($page);
     /* @var NodeVersion $publicNodeVersion */
     $publicNodeVersion = $this->em->getRepository('KunstmaanNodeBundle:NodeVersion')->createNodeVersionFor($publicPage, $nodeTranslation, $this->user, $nodeVersion->getOrigin(), 'public', $nodeVersion->getCreated());
     $nodeTranslation->setPublicNodeVersion($publicNodeVersion);
     $nodeVersion->setType('draft');
     $nodeVersion->setOrigin($publicNodeVersion);
     $nodeVersion->setCreated(new DateTime());
     $this->em->persist($nodeTranslation);
     $this->em->persist($nodeVersion);
     $this->em->flush();
     $this->get('event_dispatcher')->dispatch(Events::CREATE_DRAFT_VERSION, new NodeEvent($nodeTranslation->getNode(), $nodeTranslation, $nodeVersion, $page));
     return $nodeVersion;
 }
 /**
  * @covers Kunstmaan\NodeBundle\Helper\Menu\ActionsMenuBuilder::createActionsMenu
  */
 public function testShouldShowDeleteButtonWhenTheNodeHasAParent()
 {
     $nodeTranslation = new NodeTranslation();
     $node = new Node();
     $node->setParent(new Node());
     $nodeTranslation->setNode($node);
     $nodeVersion = new NodeVersion();
     $nodeVersion->setType('public');
     $nodeVersion->setNodeTranslation($nodeTranslation);
     $this->builder->setActiveNodeVersion($nodeVersion);
     $menu = $this->builder->createActionsMenu();
     $this->assertNotNull($menu->getChild('action.delete'));
     $this->assertEquals('page-main-actions js-auto-collapse-buttons', $menu->getChildrenAttribute('class'));
 }
 /**
  * @covers Kunstmaan\NodeBundle\Helper\Menu\ActionsMenuBuilder::createActionsMenu
  */
 public function testShouldShowRecopyButtonWhenTheNodeHasTranslations()
 {
     $node = new Node();
     $nodeTranslation = new NodeTranslation();
     $nodeTranslation->setLang('en');
     $node->addNodeTranslation($nodeTranslation);
     $nodeVersion = new NodeVersion();
     $nodeVersion->setType("public");
     $nodeVersion->setNodeTranslation($nodeTranslation);
     $this->builder->setActiveNodeVersion($nodeVersion);
     $nodeTranslation = new NodeTranslation();
     $nodeTranslation->setLang('nl');
     $node->addNodeTranslation($nodeTranslation);
     $nodeVersion = new NodeVersion();
     $nodeVersion->setType("public");
     $nodeVersion->setNodeTranslation($nodeTranslation);
     $this->builder->setActiveNodeVersion($nodeVersion);
     $menu = $this->builder->createActionsMenu();
     $this->assertNotNull($menu->getChild('action.recopyfromlanguage'));
     $this->assertEquals('page-main-actions js-auto-collapse-buttons', $menu->getChildrenAttribute('class'));
 }
 /**
  * Add nodeVersion
  *
  * @param NodeVersion $nodeVersion
  *
  * @return NodeTranslation
  */
 public function addNodeVersion(NodeVersion $nodeVersion)
 {
     $this->nodeVersions[] = $nodeVersion;
     $nodeVersion->setNodeTranslation($this);
     return $this;
 }