/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(CmsCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = CmsCategoryQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // sortable behavior CmsCategoryPeer::shiftRank(-1, $this->getSortableRank() + 1, null, $con); CmsCategoryPeer::clearInstancePool(); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Adds $delta to all Rank values that are >= $first and <= $last. * '$delta' can also be negative. * * @param int $delta Value to be shifted by, can be negative * @param int $first First node to be shifted * @param int $last Last node to be shifted * @param PropelPDO $con Connection to use. */ public static function shiftRank($delta, $first = null, $last = null, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(CmsCategoryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $whereCriteria = CmsCategoryQuery::create(); if (null !== $first) { $whereCriteria->add(CmsCategoryPeer::RANK_COL, $first, Criteria::GREATER_EQUAL); } if (null !== $last) { $whereCriteria->addAnd(CmsCategoryPeer::RANK_COL, $last, Criteria::LESS_EQUAL); } $valuesCriteria = new Criteria(CmsCategoryPeer::DATABASE_NAME); $valuesCriteria->add(CmsCategoryPeer::RANK_COL, array('raw' => CmsCategoryPeer::RANK_COL . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL); BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con); CmsCategoryPeer::clearInstancePool(); }