Пример #1
0
 /**
  * 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(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $whereCriteria = ProductQuery::create();
     if (null !== $first) {
         $whereCriteria->add(ProductPeer::RANK_COL, $first, Criteria::GREATER_EQUAL);
     }
     if (null !== $last) {
         $whereCriteria->addAnd(ProductPeer::RANK_COL, $last, Criteria::LESS_EQUAL);
     }
     $valuesCriteria = new Criteria(ProductPeer::DATABASE_NAME);
     $valuesCriteria->add(ProductPeer::RANK_COL, array('raw' => ProductPeer::RANK_COL . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL);
     BasePeer::doUpdate($whereCriteria, $valuesCriteria, $con);
     ProductPeer::clearInstancePool();
 }
Пример #2
0
 /**
  * Method to invalidate the instance pool of all tables related to principal
  * by a foreign key with ON DELETE CASCADE
  */
 public static function clearRelatedInstancePool()
 {
     // Invalidate objects in UserProfilePeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     UserProfilePeer::clearInstancePool();
     // Invalidate objects in ProductPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     ProductPeer::clearInstancePool();
     // Invalidate objects in PrincipalI18nPeer instance pool,
     // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     PrincipalI18nPeer::clearInstancePool();
 }
Пример #3
0
 /**
  * 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(ProductPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         EventDispatcherProxy::trigger(array('delete.pre', 'model.delete.pre'), new ModelEvent($this));
         $deleteQuery = ProductQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // sortable behavior
         ProductPeer::shiftRank(-1, $this->getSortableRank() + 1, null, $con);
         ProductPeer::clearInstancePool();
         // archivable behavior
         if ($ret) {
             if ($this->archiveOnDelete) {
                 // do nothing yet. The object will be archived later when calling ProductQuery::delete().
             } else {
                 $deleteQuery->setArchiveOnDelete(false);
                 $this->archiveOnDelete = true;
             }
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             // event behavior
             EventDispatcherProxy::trigger(array('delete.post', 'model.delete.post'), new ModelEvent($this));
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }