Skip to content

Commit

Permalink
DoctrineDBAL\Client::getNodeTypes() needs to return all the types whe…
Browse files Browse the repository at this point in the history
…n $nodeTypes is empty.
  • Loading branch information
damz committed Jan 16, 2012
1 parent 486059e commit 20b238c
Showing 1 changed file with 72 additions and 78 deletions.
150 changes: 72 additions & 78 deletions src/Jackalope/Transport/DoctrineDBAL/Client.php
Expand Up @@ -1157,23 +1157,20 @@ public function getNodePathForIdentifier($uuid)
*/
public function getNodeTypes($nodeTypes = array())
{
$nodeTypes = array_flip($nodeTypes);

$data = StandardNodeTypes::getNodeTypeData();
$filteredData = array();
foreach ($data as $nodeTypeData) {
if (isset($nodeTypes[$nodeTypeData['name']])) {
$filteredData[$nodeTypeData['name']] = $nodeTypeData;
}
$standardTypes = array();
foreach (StandardNodeTypes::getNodeTypeData() as $nodeTypeData) {
$standardTypes[$nodeTypeData['name']] = $nodeTypeData;
}
$userTypes = $this->fetchUserNodeTypes();

foreach ($nodeTypes as $type => $val) {
if (!isset($filteredData[$type]) && $result = $this->fetchUserNodeType($type)) {
$filteredData[$type] = $result;
}
if ($nodeTypes) {
$nodeTypes = array_flip($nodeTypes);
// TODO: check if user types can override standard types.
return array_values(array_intersect_key($standardTypes, $nodeTypes) + array_intersect_key($userTypes, $nodeTypes));
}
else {
return array_values($standardTypes + $userTypes);
}

return array_values($filteredData);
}

/**
Expand All @@ -1182,79 +1179,76 @@ public function getNodeTypes($nodeTypes = array())
* @param string $name
* @return array
*/
private function fetchUserNodeType($name)
private function fetchUserNodeTypes()
{
if ($result = $this->cache->fetch('phpcr_nodetype_' . $name)) {
if ($result = $this->cache->fetch('phpcr_nodetypes')) {
return $result;
}

$query = "SELECT * FROM phpcr_type_nodes WHERE name = ?";
$data = $this->conn->fetchAssoc($query, array($name));

if (!$data) {
$this->cache->save('phpcr_nodetype_' . $name, false);

return false;
}
$result = array();
$query = "SELECT * FROM phpcr_type_nodes";
foreach ($this->conn->fetchAll($query) as $data) {
$name = $data['name'];
$result[$name] = array(
'name' => $name,
'isAbstract' => (bool)$data['is_abstract'],
'isMixin' => (bool)($data['is_mixin']),
'isQueryable' => (bool)$data['queryable'],
'hasOrderableChildNodes' => (bool)$data['orderable_child_nodes'],
'primaryItemName' => $data['primary_item'],
'declaredSuperTypeNames' => array_filter(explode(' ', $data['supertypes'])),
'declaredPropertyDefinitions' => array(),
'declaredNodeDefinitions' => array(),
);

$result = array(
'name' => $data['name'],
'isAbstract' => (bool)$data['is_abstract'],
'isMixin' => (bool)($data['is_mixin']),
'isQueryable' => (bool)$data['is_queryable'],
'hasOrderableChildNodes' => (bool)$data['orderable_child_nodes'],
'primaryItemName' => $data['primary_item'],
'declaredSuperTypeNames' => array_filter(explode(' ', $data['supertypes'])),
'declaredPropertyDefinitions' => array(),
'declaredNodeDefinitions' => array(),
);
$query = "SELECT * FROM phpcr_type_props WHERE node_type_id = ?";
$props = $this->conn->fetchAll($query, array($data['node_type_id']));

foreach ($props as $propertyData) {
$result[$name]['declaredPropertyDefinitions'][] = array(
'declaringNodeType' => $data['name'],
'name' => $propertyData['name'],
'isAutoCreated' => (bool)$propertyData['auto_created'],
'isMandatory' => (bool)$propertyData['mandatory'],
'isProtected' => (bool)$propertyData['protected'],
'onParentVersion' => $propertyData['on_parent_version'],
'requiredType' => $propertyData['required_type'],
'multiple' => (bool)$propertyData['multiple'],
'isFulltextSearchable' => (bool)$propertyData['fulltext_searchable'],
'isQueryOrderable' => (bool)$propertyData['query_orderable'],
'queryOperators' => array (
0 => 'jcr.operator.equal.to',
1 => 'jcr.operator.not.equal.to',
2 => 'jcr.operator.greater.than',
3 => 'jcr.operator.greater.than.or.equal.to',
4 => 'jcr.operator.less.than',
5 => 'jcr.operator.less.than.or.equal.to',
6 => 'jcr.operator.like',
),
'defaultValue' => array($propertyData['default_value']),
);
}

$query = "SELECT * FROM phpcr_type_props WHERE node_type_id = ?";
$props = $this->conn->fetchAll($query, array($data['node_type_id']));

foreach ($props as $propertyData) {
$result['declaredPropertyDefinitions'][] = array(
'declaringNodeType' => $data['name'],
'name' => $propertyData['name'],
'isAutoCreated' => (bool)$propertyData['auto_created'],
'isMandatory' => (bool)$propertyData['mandatory'],
'isProtected' => (bool)$propertyData['protected'],
'onParentVersion' => $propertyData['on_parent_version'],
'requiredType' => $propertyData['required_type'],
'multiple' => (bool)$propertyData['multiple'],
'isFulltextSearchable' => (bool)$propertyData['fulltext_searchable'],
'isQueryOrderable' => (bool)$propertyData['query_orderable'],
'queryOperators' => array (
0 => 'jcr.operator.equal.to',
1 => 'jcr.operator.not.equal.to',
2 => 'jcr.operator.greater.than',
3 => 'jcr.operator.greater.than.or.equal.to',
4 => 'jcr.operator.less.than',
5 => 'jcr.operator.less.than.or.equal.to',
6 => 'jcr.operator.like',
),
'defaultValue' => array($propertyData['default_value']),
);
}
$query = "SELECT * FROM phpcr_type_childs WHERE node_type_id = ?";
$childs = $this->conn->fetchAll($query, array($data['node_type_id']));

foreach ($childs as $childData) {
$result[$name]['declaredNodeDefinitions'][] = array(
'declaringNodeType' => $data['name'],
'name' => $childData['name'],
'isAutoCreated' => (bool)$childData['auto_created'],
'isMandatory' => (bool)$childData['mandatory'],
'isProtected' => (bool)$childData['protected'],
'onParentVersion' => $childData['on_parent_version'],
'allowsSameNameSiblings' => false,
'defaultPrimaryTypeName' => $childData['default_type'],
'requiredPrimaryTypeNames' => array_filter(explode(" ", $childData['primary_types'])),
);
}

$query = "SELECT * FROM phpcr_type_childs WHERE node_type_id = ?";
$childs = $this->conn->fetchAll($query, array($data['node_type_id']));

foreach ($childs as $childData) {
$result['declaredNodeDefinitions'][] = array(
'declaringNodeType' => $data['name'],
'name' => $childData['name'],
'isAutoCreated' => (bool)$childData['auto_created'],
'isMandatory' => (bool)$childData['mandatory'],
'isProtected' => (bool)$childData['protected'],
'onParentVersion' => $childData['on_parent_version'],
'allowsSameNameSiblings' => false,
'defaultPrimaryTypeName' => $childData['default_type'],
'requiredPrimaryTypeNames' => array_filter(explode(" ", $childData['primary_types'])),
);
}

$this->cache->save('phpcr_nodetype_' . $name, $result);
$this->cache->save('phpcr_nodetype', $result);

return $result;
}
Expand Down

0 comments on commit 20b238c

Please sign in to comment.