/**
  *   @see parent::sessionRead
  */
 public function sessionRead($id)
 {
     $result = parent::sessionRead($id);
     $this->setSessionKey($id);
     // Find session persistent object
     $session = SessionQuery::create()->filterBySessionKey($id)->findOne();
     // Associate an IP address with the session & user
     if (!is_null($session) && $session instanceof Session) {
         $context = sfContext::getInstance();
         if ($session->getClientIpAddress() == null) {
             $session->setClientIpAddress($context->getRequest()->getRemoteAddress());
         }
         // Associate User with session
         $user = $context->getUser();
         if ($session->getUserId() == null && !is_null($user) && $user->isAuthenticated()) {
             $session->setUser($user->getProfile());
         }
         $session->save();
     }
     return $result;
 }
Пример #2
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return     void
  * @throws     PropelException
  * @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(SessionPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = SessionQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Пример #3
0
 /**
  * Retrieves a single Session by the provided session key
  *
  * @param string $session_key
  * @return Session
  */
 public static function retrieveBySessionKey($session_key)
 {
     return SessionQuery::create()->filterBySessionKey($session_key)->findOne();
 }
Пример #4
0
 /**
  * Get the associated Session object
  *
  * @param      PropelPDO $con Optional Connection object.
  * @return                 Session The associated Session object.
  * @throws PropelException
  */
 public function getSession(PropelPDO $con = null)
 {
     if ($this->aSession === null && $this->session_id !== null) {
         $this->aSession = SessionQuery::create()->findPk($this->session_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aSession->addSingleSignOnKeys($this);
            */
     }
     return $this->aSession;
 }
Пример #5
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(SessionPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = SessionQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // symfony_behaviors behavior
         foreach (sfMixer::getCallables('BaseSession:delete:pre') as $callable) {
             if (call_user_func($callable, $this, $con)) {
                 $con->commit();
                 return;
             }
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             // symfony_behaviors behavior
             foreach (sfMixer::getCallables('BaseSession:delete:post') as $callable) {
                 call_user_func($callable, $this, $con);
             }
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Пример #6
0
 /**
  * Returns the number of related Session objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return int             Count of related Session objects.
  * @throws PropelException
  */
 public function countSessions(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collSessions || null !== $criteria) {
         if ($this->isNew() && null === $this->collSessions) {
             return 0;
         } else {
             $query = SessionQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByUser($this)->count($con);
         }
     } else {
         return count($this->collSessions);
     }
 }