Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
7583a8d8
Commit
7583a8d8
authored
Jul 29, 2007
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preliminary fix for a bug that occurs when using NestedSet + Column aggregation inheritance
parent
15e43b61
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
11 deletions
+34
-11
NestedSet.php
lib/Doctrine/Node/NestedSet.php
+7
-7
Tree.php
lib/Doctrine/Tree.php
+20
-0
NestedSet.php
lib/Doctrine/Tree/NestedSet.php
+1
-2
SingleRootTestCase.php
tests/NestedSet/SingleRootTestCase.php
+6
-2
No files found.
lib/Doctrine/Node/NestedSet.php
View file @
7583a8d8
...
...
@@ -527,7 +527,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
// Relocate descendants of the node
$diff
=
$this
->
getLeftValue
()
-
$oldLft
;
$componentName
=
$this
->
record
->
getTable
()
->
getComponentName
();
$componentName
=
$this
->
_tree
->
getBaseComponent
();
$rootColName
=
$this
->
record
->
getTable
()
->
getTree
()
->
getAttribute
(
'rootColumnName'
);
// Update lft/rgt/root/level for all descendants
...
...
@@ -652,7 +652,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
// Update descendants lft/rgt/root/level values
$diff
=
1
-
$oldLft
;
$newRoot
=
$newRootId
;
$componentName
=
$this
->
record
->
getTable
()
->
getComponentName
();
$componentName
=
$this
->
_tree
->
getBaseComponent
();
$rootColName
=
$this
->
record
->
getTable
()
->
getTree
()
->
getAttribute
(
'rootColumnName'
);
$q
=
new
Doctrine_Query
(
$conn
);
$q
=
$q
->
update
(
$componentName
)
...
...
@@ -763,7 +763,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
$oldRoot
=
$this
->
getRootValue
();
$q
=
$this
->
_tree
->
getBaseQuery
();
$componentName
=
$this
->
record
->
getTable
()
->
getComponentName
();
$componentName
=
$this
->
_tree
->
getBaseComponent
();
$q
=
$q
->
addWhere
(
'base.lft >= ? AND base.rgt <= ?'
,
array
(
$this
->
getLeftValue
(),
$this
->
getRightValue
()));
...
...
@@ -802,7 +802,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
*/
private
function
updateNode
(
$destLeft
,
$levelDiff
)
{
$componentName
=
$this
->
record
->
getTable
()
->
getComponentName
();
$componentName
=
$this
->
_tree
->
getBaseComponent
();
$left
=
$this
->
getLeftValue
();
$right
=
$this
->
getRightValue
();
$rootId
=
$this
->
getRootValue
();
...
...
@@ -848,7 +848,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
$qRight
=
new
Doctrine_Query
();
// shift left columns
$componentName
=
$this
->
record
->
getTable
()
->
getComponentName
();
$componentName
=
$this
->
_tree
->
getBaseComponent
();
$qLeft
=
$qLeft
->
update
(
$componentName
)
->
set
(
$componentName
.
'.lft'
,
'lft + ?'
,
$delta
)
->
where
(
$componentName
.
'.lft >= ?'
,
$first
);
...
...
@@ -881,7 +881,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
$qRight
=
new
Doctrine_Query
();
// shift left column values
$componentName
=
$this
->
record
->
getTable
()
->
getComponentName
();
$componentName
=
$this
->
_tree
->
getBaseComponent
();
$qLeft
=
$qLeft
->
update
(
$componentName
)
->
set
(
$componentName
.
'.lft'
,
'lft + ?'
,
$delta
)
->
where
(
$componentName
.
'.lft >= ? AND '
.
$componentName
.
'.lft <= ?'
,
array
(
$first
,
$last
));
...
...
@@ -948,7 +948,7 @@ class Doctrine_Node_NestedSet extends Doctrine_Node implements Doctrine_Node_Int
public
function
getLevel
()
{
if
(
!
isset
(
$this
->
record
[
'level'
]))
{
$componentName
=
$this
->
record
->
getTable
()
->
getComponentName
();
$componentName
=
$this
->
_tree
->
getBaseComponent
();
$q
=
$this
->
_tree
->
getBaseQuery
();
$q
=
$q
->
addWhere
(
'base.lft < ? AND base.rgt > ?'
,
array
(
$this
->
getLeftValue
(),
$this
->
getRightValue
()));
...
...
lib/Doctrine/Tree.php
View file @
7583a8d8
...
...
@@ -40,6 +40,8 @@ class Doctrine_Tree
* @param array $options
*/
protected
$options
=
array
();
protected
$_baseComponent
;
/**
* constructor, creates tree with reference to table and any options
...
...
@@ -51,6 +53,16 @@ class Doctrine_Tree
{
$this
->
table
=
$table
;
$this
->
options
=
$options
;
$this
->
_baseComponent
=
$table
->
getComponentName
();
$class
=
$this
->
_baseComponent
;
if
(
$table
->
getOption
(
'inheritanceMap'
))
{
$subclasses
=
$table
->
getOption
(
'subclasses'
);
while
(
in_array
(
$class
,
$subclasses
))
{
$class
=
get_parent_class
(
$class
);
}
$this
->
_baseComponent
=
$class
;
}
//echo $this->_baseComponent;
}
/**
...
...
@@ -107,4 +119,12 @@ class Doctrine_Tree
{
$this
->
options
[
$name
]
=
$value
;
}
/**
* Returns the base tree component.
*/
public
function
getBaseComponent
()
{
return
$this
->
_baseComponent
;
}
}
lib/Doctrine/Tree/NestedSet.php
View file @
7583a8d8
...
...
@@ -142,7 +142,6 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
{
// fetch tree
$q
=
$this
->
getBaseQuery
();
$componentName
=
$this
->
table
->
getComponentName
();
$q
=
$q
->
addWhere
(
"base.lft >= ?"
,
1
);
...
...
@@ -277,7 +276,7 @@ class Doctrine_Tree_NestedSet extends Doctrine_Tree implements Doctrine_Tree_Int
private
function
_createBaseQuery
()
{
$q
=
new
Doctrine_Query
();
$q
->
select
(
"base.*"
)
->
from
(
$this
->
table
->
getComponentName
()
.
" base"
);
$q
->
select
(
"base.*"
)
->
from
(
$this
->
getBaseComponent
()
.
" base"
);
return
$q
;
}
...
...
tests/NestedSet/SingleRootTestCase.php
View file @
7583a8d8
...
...
@@ -48,6 +48,10 @@ class Doctrine_NestedSet_SingleRoot_TestCase extends Doctrine_UnitTestCase
$node2
=
new
NestedSetTest_SingleRootNode
();
$node2
->
name
=
'node2'
;
$node2
->
getNode
()
->
insertAsLastChildOf
(
$node
);
$node3
=
new
NestedSetTest_SingleRootNode
();
$node3
->
name
=
'node3'
;
$node3
->
getNode
()
->
insertAsLastChildOf
(
$node2
);
}
public
function
testLftRgtValues
()
...
...
@@ -55,7 +59,7 @@ class Doctrine_NestedSet_SingleRoot_TestCase extends Doctrine_UnitTestCase
$treeMngr
=
$this
->
conn
->
getTable
(
'NestedSetTest_SingleRootNode'
)
->
getTree
();
$root
=
$treeMngr
->
fetchRoot
();
$this
->
assertEqual
(
1
,
$root
[
'lft'
]);
$this
->
assertEqual
(
4
,
$root
[
'rgt'
]);
$this
->
assertEqual
(
6
,
$root
[
'rgt'
]);
}
public
function
testGetDescendants
()
...
...
@@ -64,7 +68,7 @@ class Doctrine_NestedSet_SingleRoot_TestCase extends Doctrine_UnitTestCase
$root
=
$treeMngr
->
fetchRoot
();
$desc
=
$root
->
getNode
()
->
getDescendants
();
$this
->
assertTrue
(
$desc
!==
false
);
$this
->
assertEqual
(
1
,
count
(
$desc
));
$this
->
assertEqual
(
2
,
count
(
$desc
));
$this
->
assertEqual
(
'node2'
,
$desc
[
0
][
'name'
]);
$this
->
assertEqual
(
1
,
$desc
[
0
][
'level'
]);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment