/**
  * {@inheritDoc}
  */
 public function registerNodeTypes($types, $allowUpdate)
 {
     $builtinTypes = StandardNodeTypes::getNodeTypeData();
     /* @var $type NodeTypeDefinition */
     foreach ($types as $type) {
         if (isset($builtinTypes[$type->getName()])) {
             throw new RepositoryException(sprintf('%s: can\'t reregister built-in node type.', $type->getName()));
         }
         if ($allowUpdate) {
             $query = "SELECT * FROM phpcr_type_nodes WHERE name = ?";
             $result = $this->getConnection()->fetchColumn($query, array($type->getName()));
             if ($result) {
                 $this->getConnection()->delete('phpcr_type_nodes', array('node_type_id' => $result));
                 $this->getConnection()->delete('phpcr_type_props', array('node_type_id' => $result));
                 $this->getConnection()->delete('phpcr_type_childs', array('node_type_id' => $result));
             }
         }
         try {
             $this->getConnection()->insert('phpcr_type_nodes', array('name' => $type->getName(), 'supertypes' => implode(' ', $type->getDeclaredSuperTypeNames()), 'is_abstract' => $type->isAbstract() ? 1 : 0, 'is_mixin' => $type->isMixin() ? 1 : 0, 'queryable' => $type->isQueryable() ? 1 : 0, 'orderable_child_nodes' => $type->hasOrderableChildNodes() ? 1 : 0, 'primary_item' => $type->getPrimaryItemName()));
         } catch (DBALException $e) {
             throw new NodeTypeExistsException("Could not register node type with the name '" . $type->getName() . "'");
         }
         $nodeTypeId = $this->getConnection()->lastInsertId($this->sequenceTypeName);
         if ($propDefs = $type->getDeclaredPropertyDefinitions()) {
             foreach ($propDefs as $propertyDef) {
                 /* @var $propertyDef PropertyDefinitionInterface */
                 $this->getConnection()->insert('phpcr_type_props', array('node_type_id' => $nodeTypeId, 'name' => $propertyDef->getName(), 'protected' => $propertyDef->isProtected() ? 1 : 0, 'mandatory' => $propertyDef->isMandatory() ? 1 : 0, 'auto_created' => $propertyDef->isAutoCreated() ? 1 : 0, 'on_parent_version' => $propertyDef->getOnParentVersion(), 'multiple' => $propertyDef->isMultiple() ? 1 : 0, 'fulltext_searchable' => $propertyDef->isFullTextSearchable() ? 1 : 0, 'query_orderable' => $propertyDef->isQueryOrderable() ? 1 : 0, 'required_type' => $propertyDef->getRequiredType(), 'query_operators' => 0, 'default_value' => $propertyDef->getDefaultValues() ? current($propertyDef->getDefaultValues()) : null));
             }
         }
         if ($childDefs = $type->getDeclaredChildNodeDefinitions()) {
             foreach ($childDefs as $childDef) {
                 /* @var $childDef NodeDefinitionInterface */
                 $this->getConnection()->insert('phpcr_type_childs', array('node_type_id' => $nodeTypeId, 'name' => $childDef->getName(), 'protected' => $childDef->isProtected() ? 1 : 0, 'mandatory' => $childDef->isMandatory() ? 1 : 0, 'auto_created' => $childDef->isAutoCreated() ? 1 : 0, 'on_parent_version' => $childDef->getOnParentVersion(), 'primary_types' => implode(' ', $childDef->getRequiredPrimaryTypeNames() ?: array()), 'default_type' => $childDef->getDefaultPrimaryTypeName()));
             }
         }
     }
 }
Example #2
0
 public function registerNodeTypes($types, $allowUpdate)
 {
     $standartTypes = StandardNodeTypes::getNodeTypeData();
     foreach ($types as $type) {
         if (isset($standartTypes[$type->getName()])) {
             throw new RepositoryException(sprintf('%s: can\'t reregister built-in node type.', $type->getName()));
         }
         if ($allowUpdate) {
             $coll = $this->db->selectCollection(self::COLLNAME_TYPE_NODES);
             $qb = $coll->createQueryBuilder()->field('name')->equals(array($type->getName()));
             $query = $qb->getQuery();
             $result = $query->getIterator();
             if ($result) {
                 $qb = $coll->createQueryBuilder()->field('name')->findAndRemove()->equals(array($type->getName()));
             }
         }
         try {
             $coll = $this->db->selectCollection(self::COLLNAME_TYPE_NODES);
             $node_type = array('name' => $type->getName(), 'supertypes' => implode(' ', $type->getDeclaredSuperTypeNames()), 'is_abstract' => $type->isAbstract() ? 1 : 0, 'is_mixin' => $type->isMixin() ? 1 : 0, 'queryable' => $type->isQueryable() ? 1 : 0, 'orderable_child_nodes' => $type->hasOrderableChildNodes() ? 1 : 0, 'primary_item' => $type->getPrimaryItemName());
             $coll->insert($node_type);
         } catch (\Exception $e) {
             throw new NodeTypeExistsException("Could not register node type with the name '" . $type->getName() . "'");
         }
         // Need 'phpcr_type_props' and 'phpcr_type_childs' collections
     }
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 public function getNodeTypes($nodeTypes = array())
 {
     $standardTypes = StandardNodeTypes::getNodeTypeData();
     $userTypes = $this->fetchUserNodeTypes();
     if ($nodeTypes) {
         $nodeTypes = array_flip($nodeTypes);
         return array_values(array_intersect_key($standardTypes, $nodeTypes) + array_intersect_key($userTypes, $nodeTypes));
     }
     return array_values($standardTypes + $userTypes);
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function getNodeTypes($nodeTypes = array())
 {
     $types = array_merge(StandardNodeTypes::getNodeTypeData(), $this->nodeTypeStorage->getNodeTypes($this->workspaceName));
     return $types;
 }