Hi,
I've just noticed what I think is an omission in the deleteDescendants method.
I've currently been using version 0.8.2 and noticed an odd behaviour. When I used the deleteDescendants method on structures with more than one tree, items from other trees would be deleted. I looked at the code and found that line 874 had been commented:
// $c->add(self::getColumnConstant($stub_name, 'scope'), $node->getScopeIdValue());
So that looks like the scope limiting criteria. I uncommented it, and all worked perfectly. I went to add this ticket when I noticed a new release was available. However when I look at the 0.9.0 version of the plug-in, it looks like that line has been removed all-together, and the behaviour is still there.
Is that intentional?
I've added the line into the 0.9.0 release and all seems to work as expected. Can we have that added in again please?
Here is my altered version:
public function deleteDescendants(BaseObject $node)
{
$peer_name = get_class($node->getPeer());
$stub_name = get_class($node);
$c = new Criteria();
$c1 = $c->getNewCriterion(self::getColumnConstant($stub_name, 'left'), $node->getLeftValue(), Criteria::GREATER_THAN);
$c2 = $c->getNewCriterion(self::getColumnConstant($stub_name, 'right'), $node->getRightValue(), Criteria::LESS_THAN);
$c1->addAnd($c2);
$c->add($c1);
$c->add(self::getColumnConstant($stub_name, 'scope'), $node->getScopeIdValue());
$c->addDescendingOrderByColumn(self::getColumnConstant($stub_name, 'right'));
// Nodes are not directly deleted because we need to maintain adjacency list properties
$descendants = call_user_func(array($peer_name, 'doSelect'), $c);
foreach ($descendants as $descendant)
{
$descendant->delete();
}
/*
* This is somewhat hackish...
*
* This implementation is probably more elegant :
* http://propel.phpdb.org/trac/browser/branches/1.3/generator/classes/propel/engine/builder/om/php5/PHP5NestedSetPeerBuilder.php?rev=501#L1139
*/
$node = $node->reload();
$node->setRightValue($node->getRightValue() - 1);
$node->save();
}
PS. This plug-in is great and has saved me so much time - I can't wait for the 1.x release :) Keep up the great work!