protected function executeBatchDelete(sfWebRequest $request) { $ids = $request->getParameter('ids'); $count = 0; foreach (ProductoPeer::retrieveByPks($ids) as $object) { $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()) { $count++; } } if ($count >= count($ids)) { $this->getUser()->setFlash('notice', 'The selected items have been deleted successfully.'); } else { $this->getUser()->setFlash('error', 'A problem occurs when deleting the selected items.'); } $this->redirect('@producto'); }