[limb-svn] r6267 - in 3.x/trunk/limb/tree: src tests/cases
svn at limb-project.com
svn at limb-project.com
Thu Sep 6 13:49:41 MSD 2007
Author: pachanga
Date: 2007-09-06 13:49:40 +0400 (Thu, 06 Sep 2007)
New Revision: 6267
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6267
Modified:
3.x/trunk/limb/tree/src/lmbMPTree.class.php
3.x/trunk/limb/tree/tests/cases/lmbTreeTestBase.class.php
Log:
-- lmbMPTree::getNodeByPath() uses iterative sql query instead of one which allows to fix some nasty bugs
Modified: 3.x/trunk/limb/tree/src/lmbMPTree.class.php
===================================================================
--- 3.x/trunk/limb/tree/src/lmbMPTree.class.php 2007-09-06 08:28:31 UTC (rev 6266)
+++ 3.x/trunk/limb/tree/src/lmbMPTree.class.php 2007-09-06 09:49:40 UTC (rev 6267)
@@ -306,42 +306,23 @@
if(!$path_array)
return null;
- $level = sizeof($path_array);
+ if(!$root = $this->getRootNode())
+ return null;
- $in_condition = $this->_dbIn($this->_identifier, array_map(array($this->_conn, 'escape'), array_unique($path_array)));
- $sql = "SELECT " . $this->_getSelectFields() . "
- FROM {$this->_node_table}
- WHERE
- {$in_condition}
- AND {$this->_level} <= {$level}
- ORDER BY {$this->_path}";
-
- $stmt = $this->_conn->newStatement($sql);
- $rs = $stmt->getRecordSet();
-
- $curr_level = 0;
- $parent_id = null;
- $path_to_node = '';
-
- foreach($rs as $node)
+ $parent_id = $root['id'];
+ foreach($path_array as $path)
{
- if($node['level'] < $curr_level)
- continue;
-
- if($node['identifier'] == $path_array[$curr_level] &&
- (!$parent_id ||
- $node['parent_id'] == $parent_id))
- {
- $parent_id = $node['id'];
-
- $curr_level++;
- $path_to_node .= '/' . $node['identifier'];
-
- if($curr_level == $level)
- return $node;
- }
+ $path = $this->_conn->escape($path);
+ $sql = "SELECT " . $this->_getSelectFields() . "
+ FROM {$this->_node_table}
+ WHERE {$this->_parent_id}=$parent_id AND
+ {$this->_identifier}='$path'";
+ $stmt = $this->_conn->newStatement($sql);
+ if(!$node = $stmt->getOneRecord())
+ return null;
+ $parent_id = $node['id'];
}
- return null;
+ return $node;
}
function getPathToNode($node)
Modified: 3.x/trunk/limb/tree/tests/cases/lmbTreeTestBase.class.php
===================================================================
--- 3.x/trunk/limb/tree/tests/cases/lmbTreeTestBase.class.php 2007-09-06 08:28:31 UTC (rev 6266)
+++ 3.x/trunk/limb/tree/tests/cases/lmbTreeTestBase.class.php 2007-09-06 09:49:40 UTC (rev 6267)
@@ -385,6 +385,8 @@
$node_1 = $this->imp->createNode($root_id, array('identifier'=>'foo'));
$node_1_1 = $this->imp->createNode($node_1, array('identifier'=>'bar'));
$node_1_2 = $this->imp->createNode($node_1, array('identifier'=>'foo'));
+ $node_2 = $this->imp->createNode($root_id, array('identifier'=>'bar'));
+ $node_2_2 = $this->imp->createNode($node_2, array('identifier'=>'foo'));
$node = $this->imp->getNodeByPath('/');
$this->assertEqual($node['id'], $root_id);
@@ -397,6 +399,12 @@
$node = $this->imp->getNodeByPath('/foo/foo');
$this->assertEqual($node['id'], $node_1_2);
+
+ $node = $this->imp->getNodeByPath('/bar');
+ $this->assertEqual($node['id'], $node_2);
+
+ $node = $this->imp->getNodeByPath('/bar/foo');
+ $this->assertEqual($node['id'], $node_2_2);
}
function testGetPathToNodeFailed()
More information about the limb-svn
mailing list