propelorm/sfPropelORMPlugin — pull request #118 by rozwell (2012-02-29 15:00:25+00:00)
Title: Nested batch delete

When removing nested set objects via batchDelete, there can be possible tree corruption.

Objects are retrieved only once and every time one of them is deleted, nested structure changes but it's not updated for objects in memory:

```php

dispatcher->notify(new sfEvent($this, 'admin.delete_object', array('object' => $object)));

$object->delete();
if ($object->isDeleted())
{
$count++;
}
}
```

The simple fix is to reload each object before deletion:

```php

dispatcher->notify(new sfEvent($this, 'admin.delete_object', array('object' => $object)));

// reload the object if it's in a tree to avoid breaking nested set structure
if ($count && method_exists($object, 'isInTree') && $object->isInTree())
{
$object->reload();
}

$object->delete();
if ($object->isDeleted())
{
$count++;
}
}
```
Note: we don't need to reload first object since there were no changes yet.