Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #118 from rozwell/nested_batch_delete

Batch deletetion of nested set objects
  • Loading branch information...
commit 8d55e004ea5a078ba8215fa2e888d8fb71dccae6 2 parents 1c91492 + b966056
William Durand willdurand authored
18 data/generator/sfPropelModule/admin/parts/batchAction.php
View
@@ -52,6 +52,24 @@ protected function executeBatchDelete(sfWebRequest $request)
{
$this->dispatcher->notify(new sfEvent($this, 'admin.delete_object', array('object' => $object)));
+ // check if object is in a tree
+ if ($count && method_exists($object, 'isInTree') && $object->isInTree())
+ {
+ // test if we can reload an object
+ try
+ {
+ $object->reload(); // reload to avoid breaking nested set structure
+ }
+ catch (Exception $e)
+ {
+ // will fail if object does not exist in the database anymore
+ // happens when trying to delete children of already deleted object
+ // so increase the counter and move on
+ $count++;
+ continue;
+ }
+ }
+
$object->delete();
if ($object->isDeleted())
{
18 data/generator/sfPropelModule/admin15/parts/batchAction.php
View
@@ -52,6 +52,24 @@ protected function executeBatchDelete(sfWebRequest $request)
{
$this->dispatcher->notify(new sfEvent($this, 'admin.delete_object', array('object' => $object)));
+ // check if object is in a tree
+ if ($count && method_exists($object, 'isInTree') && $object->isInTree())
+ {
+ // test if we can reload an object
+ try
+ {
+ $object->reload(); // reload to avoid breaking nested set structure
+ }
+ catch (Exception $e)
+ {
+ // will fail if object does not exist in the database anymore
+ // happens when trying to delete children of already deleted object
+ // so increase the counter and move on
+ $count++;
+ continue;
+ }
+ }
+
$object->delete();
if ($object->isDeleted())
{
Please sign in to comment.
Something went wrong with that request. Please try again.