Example #1
0
 /**
  * @test
  */
 public function createNodeFromTemplateUsesIdentifierFromTemplate()
 {
     $identifier = \TYPO3\Flow\Utility\Algorithms::generateUUID();
     $template = new \TYPO3\TYPO3CR\Domain\Model\NodeTemplate();
     $template->setName('new-node');
     $template->setIdentifier($identifier);
     $rootNode = $this->context->getRootNode();
     $newNode = $rootNode->createNodeFromTemplate($template);
     $this->assertSame($identifier, $newNode->getIdentifier());
 }
 /**
  * Converts the specified node path into a Node.
  *
  * The node path must be an absolute context node path and can be specified as a string or as an array item with the
  * key "__contextNodePath". The latter case is for updating existing nodes.
  *
  * This conversion method supports creation of new nodes because new nodes
  *
  * Also note that the context's "current node" is not affected by this object converter, you will need to set it to
  * whatever node your "current" node is, if any.
  *
  * All elements in the source array which start with two underscores (like __contextNodePath) are specially treated
  * by this converter.
  *
  * All elements in the source array which start with a *single underscore (like _hidden) are *directly* set on the Node
  * object.
  *
  * All other elements, not being prefixed with underscore, are properties of the node.
  *
  *
  * @param string|array $source Either a string or array containing the absolute context node path which identifies the node. For example "/sites/mysitecom/homepage/about@user-admin"
  * @param string $targetType not used
  * @param array $subProperties not used
  * @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration not used
  * @return mixed An object or \TYPO3\Flow\Error\Error if the input format is not supported or could not be converted for other reasons
  * @throws \Exception
  */
 public function convertFrom($source, $targetType, array $subProperties = array(), \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = NULL)
 {
     $nodeTemplate = new \TYPO3\TYPO3CR\Domain\Model\NodeTemplate();
     $nodeType = $this->extractNodeType($targetType, $source);
     $nodeTemplate->setNodeType($nodeType);
     // we don't need a context or workspace for creating NodeTemplate objects, but in order to satisfy the method
     // signature of setNodeProperties(), we do need one:
     $context = $this->contextFactory->create($this->prepareContextProperties('live'));
     $this->setNodeProperties($nodeTemplate, $nodeTemplate->getNodeType(), $source, $context);
     return $nodeTemplate;
 }
 protected function importCategories($parentcategory = 0, $targetPath = '/sites/site')
 {
     $categoryNodeType = 'Sfi.Kateheo:Category';
     $sql = "SELECT * FROM tx_news_domain_model_category\n\t\t\tWHERE parentcategory=:parentcategory AND deleted=0 AND hidden=0\n\t\t\tORDER BY 'sorting'";
     $statement = $this->connection->prepare($sql);
     $params = array('parentcategory' => $parentcategory);
     $statement->execute($params);
     foreach ($statement->fetchAll(\PDO::FETCH_ASSOC) as $category) {
         $rootNode = $this->context->getNode($targetPath);
         $categoryNode = $this->getCategoryByOriginalId($category['uid']);
         if ($categoryNode) {
             echo "Node " . $category['uid'] . " already exists, skipped\n";
         } else {
             echo "{$parentcategory} -- {$targetPath}\n";
             $categoryNodeTemplate = new \TYPO3\TYPO3CR\Domain\Model\NodeTemplate();
             $categoryNodeTemplate->setNodeType($this->nodeTypeManager->getNodeType($categoryNodeType));
             $categoryNodeTemplate->setProperty('originalIdentifier', $category['uid']);
             $categoryNodeTemplate->setProperty('title', $category['title']);
             $categoryNode = $rootNode->createNodeFromTemplate($categoryNodeTemplate);
         }
         $this->importCategories($category['uid'], $categoryNode->getPath());
     }
 }
 /**
  * @test
  * @expectedException \InvalidArgumentException
  */
 public function setNameWithInvalidNameThrowsException()
 {
     $nodeTemplate = new \TYPO3\TYPO3CR\Domain\Model\NodeTemplate();
     $nodeTemplate->setName(',?/invalid-node-name');
 }