/** * Deletes all descendants for the given node * Instance pooling is wiped out by this command, * so existing Page instances are probably invalid (except for the current one) * * @param PropelPDO $con Connection to use. * * @return int number of deleted nodes */ public function deleteDescendants(PropelPDO $con = null) { if ($this->isLeaf()) { // save one query return; } if ($con === null) { $con = Propel::getConnection(PagePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $left = $this->getLeftValue(); $right = $this->getRightValue(); $con->beginTransaction(); try { // delete descendant nodes (will empty the instance pool) $ret = PageQuery::create()->descendantsOf($this)->delete($con); // fill up the room that was used by descendants PagePeer::shiftRLValues($left - $right + 1, $right, null, $con); // fix the right value for the current node, which is now a leaf $this->setRightValue($left + 1); $con->commit(); } catch (Exception $e) { $con->rollback(); throw $e; } return $ret; }
/** * Update the tree to allow insertion of a leaf at the specified position * * @param int $left left column value * @param mixed $prune Object to prune from the shift * @param PropelPDO $con Connection to use. */ public static function makeRoomForLeaf($left, $prune = null, PropelPDO $con = null) { // Update database nodes PagePeer::shiftRLValues(2, $left, null, $con); // Update all loaded nodes PagePeer::updateLoadedNodes($prune, $con); }