Development

#1796 ([PATCH] Missing Criteria for deleteDescendants in sfPropelActAsNestedSetBehaviorPlugin)

You must first sign up to be able to contribute.

Ticket #1796 (new enhancement)

Opened 1 year ago

Last modified 11 months ago

[PATCH] Missing Criteria for deleteDescendants in sfPropelActAsNestedSetBehaviorPlugin

Reported by: Piers.Warmers Assigned to: trivoallan
Priority: minor Milestone: plugins
Component: sfPropelActAsNestedSetBehaviorPlugin Version: 1.0.0
Keywords: "comented line" sfPropelActAsNestedSetBehaviorPlugin deleteDescendants Cc: hello@pierswarmers.com
Qualification:

Description

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!

Attachments

sfPropelActAsNestedSetBehavior.class.php (36.8 kB) - added by Goulwen.REBOUX on 06/29/07 15:14:55.
New deleteDescendants method

Change History

05/28/07 05:54:43 changed by Piers.Warmers

  • keywords changed from "comented line" to "comented line" sfPropelActAsNestedSetBehaviorPlugin deleteDescendants.

05/28/07 05:55:05 changed by Piers.Warmers

  • cc set to hello@pierswarmers.com.

06/29/07 15:14:55 changed by Goulwen.REBOUX

  • attachment sfPropelActAsNestedSetBehavior.class.php added.

New deleteDescendants method

06/29/07 15:15:23 changed by Goulwen.REBOUX

  • type changed from defect to enhancement.

I have completely rewrite the deleteDescendants method.

I've had the scope so only the current tree nodes are deleted.

Additonally, I have notice some problems in the renumbering of left and right values so I've also change the preDelete() method, add a postDelete().

And, as I need to delete big trees (>500 nodes) and that the current way of delete nodes requires 3 queries per node deletion, I've implemented a direct delete of all nodes, so delete all whole tree require only 6 queries (3 for descendants and 3 for the node itself.) There's eventually a BC issue if an action should be launched when a node is deleted.

Currently, these changes pass unit-tests only if we specify the scope in the test.

07/17/07 16:25:08 changed by trivoallan

  • summary changed from Missing Criteria for deleteDescendants in sfPropelActAsNestedSetBehaviorPlugin to [sfPropelActAsNestedSetBehavior] Missing Criteria for deleteDescendants in sfPropelActAsNestedSetBehaviorPlugin.

07/20/07 14:14:17 changed by trivoallan

hi

@piers : your fix will be included in forthcoming 0.9.1

@goulwen : your reimplementation of the method looks promising, but i really need a patch (svn diff output) to review changes. A few questions :

  • how do you trigger the postDelete method without registering it in config.php
  • i'm not sure to understand what you mean with : "Currently, these changes pass unit-tests only if we specify the scope in the test."

07/20/07 14:17:14 changed by tristan

(In [4687]) sfPropelActAsNestedSetBehaviorPlugin : fixed scope handling in deleteDescendants() (Piers.Warmers). refs #1796

09/08/07 15:48:37 changed by DrCore

  • qualification set to Unreviewed.
  • summary changed from [sfPropelActAsNestedSetBehavior] Missing Criteria for deleteDescendants in sfPropelActAsNestedSetBehaviorPlugin to [PATCH] Missing Criteria for deleteDescendants in sfPropelActAsNestedSetBehaviorPlugin.

Added patch to title