Jackalope\Transport\DoctrineDBAL\Client::registerNodeTypes PHP Method

registerNodeTypes() public method

{@inheritDoc}
public registerNodeTypes ( $types, $allowUpdate )
    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()));
                }
            }
        }
    }

Usage Example

Example #1
0
 /**
  * {@inheritDoc}
  */
 public function registerNodeTypes($types, $allowUpdate)
 {
     return $this->transport->registerNodeTypes($types, $allowUpdate);
 }
All Usage Examples Of Jackalope\Transport\DoctrineDBAL\Client::registerNodeTypes