Ejemplo n.º 1
0
 /**
  * Implementation for 'DELETE' method for Rest API
  *
  * @param  mixed $sesUid Primary key
  *
  * @return array $result Returns array within multiple records or a single record depending if
  *                       a single selection was requested passing id(s) as param
  */
 protected function delete($sesUid)
 {
     $conn = Propel::getConnection(SessionPeer::DATABASE_NAME);
     try {
         $conn->begin();
         $obj = SessionPeer::retrieveByPK($sesUid);
         if (!is_object($obj)) {
             throw new RestException(412, G::LoadTranslation('ID_RECORD_DOES_NOT_EXIST'));
         }
         $obj->delete();
         $conn->commit();
     } catch (Exception $e) {
         $conn->rollback();
         throw new RestException(412, $e->getMessage());
     }
 }
Ejemplo n.º 2
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = SessionPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setSessionId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setDateCreated($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setLastUpdated($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setSessionData($arr[$keys[3]]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(SessionPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(SessionPeer::DATABASE_NAME);
         $criteria->add(SessionPeer::SESSION_ID, $pks, Criteria::IN);
         $objs = SessionPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Ejemplo n.º 4
0
 /**
  * Authenticates this user and signs them in, if the API key or session is valid.
  * 
  * @param sfActions $action
  * @throws Exception if validation fails.
  */
 public function authenticate()
 {
     //require SSL, if applicable
     $this->assertSslApiRequest();
     //authenticate via the API key, if provided
     $api_key = $this->getHttpRequestHeader('Authorization', null);
     if (!is_null($api_key)) {
         if (preg_match('/\\s*Basic\\s+(.*?)\\s*$/im', $api_key, $regs)) {
             $api_key = $regs[1];
             $api_user = \ApiUserQuery::create()->filterByApiKey($api_key)->filterByActive(true)->findOne();
             if (!$api_user) {
                 throw new \Exception('Unknown or inactive API user.');
             }
             if (0) {
                 $api_user = new \ApiUser();
             }
             $sf_guard_user = $api_user->getUser()->getsfGuardUser();
             if ($sf_guard_user->getIsActive()) {
                 \sfContext::getInstance()->getUser()->signIn($sf_guard_user, false);
             } else {
                 throw new \Exception('Unknown or inactive API user.');
             }
         } else {
             throw new \Exception('API key format not recognized');
         }
     }
     //try to authenticate via the session, if the api key was not provided
     if (is_null($api_key)) {
         $session_id = $this->getCookie(\sfConfig::get('altumo_api_session_cookie_name', 'my_session_name'), null);
         if (!is_null($session_id)) {
             $session = \SessionPeer::retrieveBySessionKey($session_id);
             if (!$session) {
                 throw new \Exception('Invalid session.');
             }
             $user = $session->getUser();
             if (!$user) {
                 throw new \Exception('Invalid session.');
             }
             if (!$user->hasApiUser()) {
                 throw new \Exception('Invalid session.');
             }
             $api_user = $user->getApiUser();
             if (!$api_user->isActive()) {
                 throw new \Exception('Inactive API user.');
             } else {
                 \sfContext::getInstance()->getUser()->signIn($user->getsfGuardUser(), false);
             }
         } else {
             throw new \Exception('Please provide either a valid session or valid API key.');
         }
     }
     //successful authentication
 }
Ejemplo n.º 5
0
 /**
  * This function checks the user session
  *
  *
  * @name verifySession
  *
  * @param string sSessionId
  * @return array
  */
 public function verifySession($sSessionId = NULL)
 {
     try {
         if ($sSessionId != NULL) {
             $this->sessionId = $sSessionId;
         } else {
             if ($this->sessionId == NULL) {
                 throw new Exception('session id was not set.');
             }
         }
         $date = date('Y-m-d H:i:s');
         $oCriteria = new Criteria('workflow');
         $oCriteria->addSelectColumn(SessionPeer::USR_UID);
         $oCriteria->addSelectColumn(SessionPeer::SES_STATUS);
         $oCriteria->addSelectColumn(SessionPeer::SES_DUE_DATE);
         $oCriteria->add(SessionPeer::SES_UID, $this->sessionId);
         $oCriteria->add(SessionPeer::SES_STATUS, 'ACTIVE');
         $oCriteria->add(SessionPeer::SES_DUE_DATE, $date, Criteria::GREATER_EQUAL);
         $oDataset = SessionPeer::doSelectRS($oCriteria, Propel::getDbConnection('workflow_ro'));
         $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
         $oDataset->next();
         $aRow = $oDataset->getRow();
         if (!is_array($aRow)) {
             $this->deleteTmpfile();
         }
         return $aRow;
     } catch (Exception $oError) {
         throw $oError;
     }
 }
Ejemplo n.º 6
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return   Session A model object, or null if the key is not found
  * @throws   PropelException
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `ID`, `SESSION_KEY`, `DATA`, `CLIENT_IP_ADDRESS`, `SESSION_TYPE`, `TIME`, `USER_ID` FROM `session` WHERE `ID` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new Session();
         $obj->hydrate($row);
         SessionPeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
Ejemplo n.º 7
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = SessionPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setIdCoach($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setName($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setNbrCourses($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setNbrUsers($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setNbrClasses($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setDateStart($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setDateEnd($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setNbDaysAccessBeforeBeginning($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setNbDaysAccessAfterEnd($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setSessionAdminId($arr[$keys[10]]);
     }
 }
 /**
  * Gets the Session object associated to the session.
  * 
  * @param mixed $session_key
  * @return Session
  */
 public function getSession()
 {
     $session = SessionPeer::retrieveBySessionKey($this->getSessionKey());
     return $session;
 }
Ejemplo n.º 9
0
 /**
  * Implementation for 'DELETE' method for Rest API
  *
  * @param  mixed $sesUid Primary key
  *
  * @return array $result Returns array within multiple records or a single record depending if
  *                       a single selection was requested passing id(s) as param
  */
 protected function delete($sesUid)
 {
     $conn = Propel::getConnection(SessionPeer::DATABASE_NAME);
     try {
         $conn->begin();
         $obj = SessionPeer::retrieveByPK($sesUid);
         if (!is_object($obj)) {
             throw new RestException(412, 'Record does not exist.');
         }
         $obj->delete();
         $conn->commit();
     } catch (Exception $e) {
         $conn->rollback();
         throw new RestException(412, $e->getMessage());
     }
 }
Ejemplo n.º 10
0
 /**
  * Selects a collection of SingleSignOnKey objects pre-filled with all related objects except User.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return array           Array of SingleSignOnKey objects.
  * @throws PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptUser(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     // $criteria->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     SingleSignOnKeyPeer::addSelectColumns($criteria);
     $startcol2 = SingleSignOnKeyPeer::NUM_HYDRATE_COLUMNS;
     SessionPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + SessionPeer::NUM_HYDRATE_COLUMNS;
     $criteria->addJoin(SingleSignOnKeyPeer::SESSION_ID, SessionPeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BaseSingleSignOnKeyPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = SingleSignOnKeyPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = SingleSignOnKeyPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://www.propelorm.org/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = SingleSignOnKeyPeer::getOMClass();
             $obj1 = new $cls();
             $obj1->hydrate($row);
             SingleSignOnKeyPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Session rows
         $key2 = SessionPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = SessionPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = SessionPeer::getOMClass();
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 SessionPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (SingleSignOnKey) to the collection in $obj2 (Session)
             $obj2->addSingleSignOnKey($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Ejemplo n.º 11
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's BasePeer::TYPE_PHPNAME
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = SessionPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setSessionKey($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setData($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setClientIpAddress($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setSessionType($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setTime($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setUserId($arr[$keys[6]]);
     }
 }
Ejemplo n.º 12
0
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = UserPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related Session objects
         $criteria = new Criteria(SessionPeer::DATABASE_NAME);
         $criteria->add(SessionPeer::USER_ID, $obj->getId());
         $affectedRows += SessionPeer::doDelete($criteria, $con);
         // delete related SingleSignOnKey objects
         $criteria = new Criteria(SingleSignOnKeyPeer::DATABASE_NAME);
         $criteria->add(SingleSignOnKeyPeer::USER_ID, $obj->getId());
         $affectedRows += SingleSignOnKeyPeer::doDelete($criteria, $con);
         // delete related SystemEventSubscription objects
         $criteria = new Criteria(SystemEventSubscriptionPeer::DATABASE_NAME);
         $criteria->add(SystemEventSubscriptionPeer::USER_ID, $obj->getId());
         $affectedRows += SystemEventSubscriptionPeer::doDelete($criteria, $con);
         // delete related SystemEventInstance objects
         $criteria = new Criteria(SystemEventInstancePeer::DATABASE_NAME);
         $criteria->add(SystemEventInstancePeer::USER_ID, $obj->getId());
         $affectedRows += SystemEventInstancePeer::doDelete($criteria, $con);
     }
     return $affectedRows;
 }
Ejemplo n.º 13
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
  * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = SessionPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setSesUid($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setSesStatus($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setUsrUid($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setSesRemoteIp($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setSesInitDate($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setSesDueDate($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setSesEndDate($arr[$keys[6]]);
     }
 }
Ejemplo n.º 14
0
 /**
  * Find object by primary key
  * Use instance pooling to avoid a database query if the object exists
  * <code>
  * $obj  = $c->findPk(12, $con);
  * </code>
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con an optional connection object
  *
  * @return    Session|array|mixed the result, formatted by the current formatter
  */
 public function findPk($key, $con = null)
 {
     if (null !== ($obj = SessionPeer::getInstanceFromPool((string) $key)) && $this->getFormatter()->isObjectFormatter()) {
         // the object is alredy in the instance pool
         return $obj;
     } else {
         // the object has not been requested yet, or the formatter is not an object formatter
         $criteria = $this->isKeepQuery() ? clone $this : $this;
         $stmt = $criteria->filterByPrimaryKey($key)->getSelectStatement($con);
         return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
     }
 }
Ejemplo n.º 15
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return                 Session A model object, or null if the key is not found
  * @throws PropelException
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `session_id`, `date_created`, `last_updated`, `session_data` FROM `session` WHERE `session_id` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_STR);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new Session();
         $obj->hydrate($row);
         SessionPeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }