/** * {@inheritDoc} */ public function delete($where) { $this->adapter = $this->masterAdapter; return parent::delete($where); }
/** * Remove a node * * @param mixed $objective target node ID or Node * @param bool $recursive Whether to delete all children nodes * @return int|false Affected rows */ public function remove($objective, $recursive = false) { $row = $this->normalizeNode($objective); if (!$row) { return false; } list($left, $right) = array($row->left, $row->right); //$result = parent::delete(array($this->primaryKeyColumn => $row->id)); $result = $row->delete(); /* if (!$result) { return false; } */ // Remove all children if ($recursive) { // Prepare for clause for children nodes with quoted identifier $where = array($this->quoteColumn('left') . ' > ?' => $left, $this->quoteColumn('right') . ' < ?' => $right); // Delete children and add up deleted row number $result += parent::delete($where); // shift right hand nodes with width if (!$this->shift($right + 1, -1 * ($right - $left + 1))) { return false; } // Keep children } else { $data = array($this->column('depth') => new Expression($this->quoteColumn('depth') . ' - 1')); $where = array($this->quoteColumn('left') . ' > ?' => $left, $this->quoteColumn('right') . ' < ?' => $right); $this->update($data, $where); if (!$this->shift($left + 1, -1, $right - 1)) { return false; } if (!$this->shift($right + 1, -2)) { return false; } } return $result; }