function removeNodeFromTree($moveToTrash = true) { $nodeID = $this->attribute('node_id'); $object = $this->object(); $assignedNodes = $object->attribute('assigned_nodes'); if ($nodeID == $this->attribute('main_node_id')) { if (count($assignedNodes) > 1) { $newMainNode = false; foreach ($assignedNodes as $assignedNode) { $assignedNodeID = $assignedNode->attribute('node_id'); if ($assignedNodeID == $nodeID) { continue; } $newMainNode = $assignedNode; break; } // We need to change the main node ID before we remove the current node $db = eZDB::instance(); $db->begin(); eZContentObjectTreeNode::updateMainNodeID($newMainNode->attribute('node_id'), $object->attribute('id'), $object->attribute('current_version'), $newMainNode->attribute('parent_node_id')); $this->removeThis(); eZSearch::addObject($object); $db->commit(); } else { // This is the last assignment so we remove the object too $db = eZDB::instance(); $db->begin(); $this->removeThis(); if ($moveToTrash) { // saving information about this node in ..trash_node table $trashNode = eZContentObjectTrashNode::createFromNode($this); $db = eZDB::instance(); $db->begin(); $trashNode->storeToTrash(); $db->commit(); $object->removeThis(); } else { $object->purge(); } $db->commit(); } } else { $this->removeThis(); if (count($assignedNodes) > 1) { eZSearch::addObject($object); } } }