Phalcon\Mvc\Model\Behavior\NestedSet::deleteNode PHP Method

deleteNode() public method

Deletes node and it's descendants.
public deleteNode ( ) : boolean
return boolean
    public function deleteNode()
    {
        $owner = $this->getOwner();
        if ($this->getIsNewRecord()) {
            throw new Exception('The node cannot be deleted because it is new.');
        }
        if ($this->getIsDeletedRecord()) {
            throw new Exception('The node cannot be deleted because it is already deleted.');
        }
        $this->db->begin();
        if ($owner->isLeaf()) {
            $this->ignoreEvent = true;
            if ($owner->delete() == false) {
                $this->db->rollback();
                $this->ignoreEvent = false;
                return false;
            }
            $this->ignoreEvent = false;
        } else {
            $condition = $this->leftAttribute . '>=' . $owner->{$this->leftAttribute} . ' AND ';
            $condition .= $this->rightAttribute . '<=' . $owner->{$this->rightAttribute};
            if ($this->hasManyRoots) {
                $condition .= ' AND ' . $this->rootAttribute . '=' . $owner->{$this->rootAttribute};
            }
            $this->ignoreEvent = true;
            foreach ($owner::find($condition) as $i) {
                if ($i->delete() == false) {
                    $this->db->rollback();
                    $this->ignoreEvent = false;
                    return false;
                }
            }
            $this->ignoreEvent = false;
        }
        $key = $owner->{$this->rightAttribute} + 1;
        $delta = $owner->{$this->leftAttribute} - $owner->{$this->rightAttribute} - 1;
        $this->shiftLeftRight($key, $delta);
        $this->db->commit();
        return true;
    }