/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->akuser !== null) { if ($this->akuser->isModified() || $this->akuser->isNew()) { $affectedRows += $this->akuser->save($con); } $this->setkuser($this->akuser); } if ($this->isNew()) { $this->modifiedColumns[] = PuserKuserPeer::ID; } // If this object has been modified, then save it to the database. $this->objectSaved = false; if ($this->isModified()) { if ($this->isNew()) { $pk = PuserKuserPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); $this->objectSaved = true; } else { $affectedObjects = PuserKuserPeer::doUpdate($this, $con); if ($affectedObjects) { $this->objectSaved = true; } $affectedRows += $affectedObjects; } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collPuserRolesRelatedByPartnerId !== null) { foreach ($this->collPuserRolesRelatedByPartnerId as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collPuserRolesRelatedByPuserId !== null) { foreach ($this->collPuserRolesRelatedByPuserId as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** Returns newly created puser - after creating it's corresponding kuser. If the puser_kuser already exists && $verify_not_exists==true , don't create a new one and return the existing one */ public static function createPuserKuser($partner_id, $subp_id, $puser_id, $kuser_name, $puser_name, $create_kuser = false, $kuser = null) { $puser_kuser = self::retrieveByPartnerAndUid($partner_id, $subp_id, $puser_id, true); if (!$kuser) { $kuser = kuserPeer::getKuserByPartnerAndUid($partner_id, $puser_id, true); // don't create an existing kuser! } if ($puser_kuser) { if (!$create_kuser) { // if the puser_kuser already exists - don't re-create it $puser_kuser->exists = true; return $puser_kuser; } else { // puser_kuser exists but it's OK // this might be the case where we don't mind creating a new one each time } } else { $puser_kuser = new PuserKuser(); } $c = new Criteria(); $c->add(self::PARTNER_ID, $partner_id); $c->add(self::PUSER_ID, $puser_id); $partner_puser_kuser = self::doSelectOne($c); if ($kuser !== null) { $kuser_id = $kuser->getId(); } else { if ($partner_puser_kuser) { $kuser_id = $partner_puser_kuser->getKuserId(); $kuser = kuserPeer::retrieveByPK($kuser_id); } else { // create kuser for this puser $kuser = new kuser(); $kuser->setScreenName($kuser_name); list($firstName, $lastName) = kString::nameSplit($kuser_name); $kuser->setFirstName($firstName); $kuser->setLastName($lastName); $kuser->setPartnerId($partner_id); // set puserId for forward compatibility with PS3 $kuser->setPuserId($puser_id); $kuser->setStatus(KuserStatus::ACTIVE); // so he won't appear in the search $kuser->save(); $kuser_id = $kuser->getId(); } } $puser_kuser->setPartnerId($partner_id); $puser_kuser->setSubpId($subp_id); $puser_kuser->setPuserId($puser_id); $puser_kuser->setKuserId($kuser_id); $puser_kuser->setPuserName($puser_name); $puser_kuser->save(); $puser_kuser->setkuser($kuser); return $puser_kuser; }
public static function createKvote($entryId, $partnerId, $puserId, $rank, $type = KVoteType::RANK) { $kvote = new kvote(); $kvote->setEntryId($entryId); $kvote->setStatus(KVoteStatus::VOTED); $kvote->setPartnerId($partnerId); $kvote->setKvoteType($type); $kuser = self::getKuserFromPuserAndPartner($puserId, $partnerId); if (!$kuser) { $kuser = new kuser(); $kuser->setPuserId($puserId); $kuser->setStatus(KuserStatus::ACTIVE); $kuser->save(); } $kvote->setKuserId($kuser->getId()); $kvote->setRank($rank); $kvote->save(); }
/** * Adds a new kuser and user_login_data records as needed * @param kuser $user * @param string $password * @param bool $checkPasswordStructure * @throws kUserException::USER_NOT_FOUND * @throws kUserException::USER_ALREADY_EXISTS * @throws kUserException::INVALID_EMAIL * @throws kUserException::INVALID_PARTNER * @throws kUserException::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED * @throws kUserException::LOGIN_ID_ALREADY_USED * @throws kUserException::PASSWORD_STRUCTURE_INVALID * @throws kPermissionException::ROLE_ID_MISSING * @throws kPermissionException::ONLY_ONE_ROLE_PER_USER_ALLOWED */ public static function addUser(kuser $user, $password = null, $checkPasswordStructure = true, $sendEmail = null) { if (!$user->getPuserId()) { throw new kUserException('', kUserException::USER_ID_MISSING); } // check if user with the same partner and puserId already exists $existingUser = kuserPeer::getKuserByPartnerAndUid($user->getPartnerId(), $user->getPuserId()); if ($existingUser) { throw new kUserException('', kUserException::USER_ALREADY_EXISTS); } // check if roles are valid - may throw exceptions if (!$user->getRoleIds() && $user->getIsAdmin()) { // assign default role according to user type admin / normal $userRoleId = $user->getPartner()->getAdminSessionRoleId(); $user->setRoleIds($userRoleId); } UserRolePeer::testValidRolesForUser($user->getRoleIds(), $user->getPartnerId()); if ($user->getScreenName() === null) { $user->setScreenName($user->getPuserId()); } if ($user->getFullName() === null) { $user->setFirstName($user->getPuserId()); } if (is_null($user->getStatus())) { $user->setStatus(KuserStatus::ACTIVE); } // if password is set, user should be able to login to the system - add a user_login_data record if ($password || $user->getIsAdmin()) { // throws an action on error $user->enableLogin($user->getEmail(), $password, $checkPasswordStructure, $sendEmail); } $user->save(); return $user; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->akshow !== null) { if ($this->akshow->isModified() || $this->akshow->isNew()) { $affectedRows += $this->akshow->save($con); } $this->setkshow($this->akshow); } if ($this->akuser !== null) { if ($this->akuser->isModified() || $this->akuser->isNew()) { $affectedRows += $this->akuser->save($con); } $this->setkuser($this->akuser); } if ($this->aaccessControl !== null) { if ($this->aaccessControl->isModified() || $this->aaccessControl->isNew()) { $affectedRows += $this->aaccessControl->save($con); } $this->setaccessControl($this->aaccessControl); } if ($this->aconversionProfile2 !== null) { if ($this->aconversionProfile2->isModified() || $this->aconversionProfile2->isNew()) { $affectedRows += $this->aconversionProfile2->save($con); } $this->setconversionProfile2($this->aconversionProfile2); } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = entryPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setNew(false); } else { $affectedRows += entryPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collkvotes !== null) { foreach ($this->collkvotes as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collconversions !== null) { foreach ($this->collconversions as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collWidgetLogs !== null) { foreach ($this->collWidgetLogs as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collmoderationFlags !== null) { foreach ($this->collmoderationFlags as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collroughcutEntrysRelatedByRoughcutId !== null) { foreach ($this->collroughcutEntrysRelatedByRoughcutId as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collroughcutEntrysRelatedByEntryId !== null) { foreach ($this->collroughcutEntrysRelatedByEntryId as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collwidgets !== null) { foreach ($this->collwidgets as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collassetParamsOutputs !== null) { foreach ($this->collassetParamsOutputs as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collassets !== null) { foreach ($this->collassets as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @param boolean $skipReload Whether to skip the reload for this object from database. * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con, $skipReload = false) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; $reloadObject = false; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->akuser !== null) { if ($this->akuser->isModified() || $this->akuser->isNew()) { $affectedRows += $this->akuser->save($con); } $this->setkuser($this->akuser); } // If this object has been modified, then save it to the database. $this->objectSaved = false; if ($this->isModified()) { if ($this->isNew()) { $pk = UploadTokenPeer::doInsert($this, $con); if (!$skipReload) { $reloadObject = true; } $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setNew(false); $this->objectSaved = true; } else { $affectedObjects = UploadTokenPeer::doUpdate($this, $con); if ($affectedObjects) { $this->objectSaved = true; } $affectedRows += $affectedObjects; } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; if ($reloadObject) { $this->reload($con); } } return $affectedRows; }
/** * * Creates a new kuser and insert it into the kuser table * @param string $puserId * @param int $partnerId */ private function createKuser($puserId, $partnerId) { $kuser = new kuser(); $kuser->partnerId = $partnerId; $kuser->puserId = $puserId; if ($this->isDryRun) { $this->createdKusers["{$puserId}_{$partnerId}"] = $kuser; } else { $rowsAffected = $kuser->save(); if ($rowsAffected != 1) { $this->printToLog("Error in save: rows affected [{$rowsAffected}]"); } } }
public function isValid($partner_id, $puser_id, $type = false) { if (!$this->valid_string) { return self::INVALID_STR; } if (!$this->matchPartner($partner_id)) { return self::INVALID_PARTNER; } if (!$this->matchUser($puser_id)) { return self::INVALID_USER; } if ($type !== false) { // do not check ks type if (!$this->type == $type) { return self::INVALID_TYPE; } } if ($this->expired()) { return self::EXPIRED; } if (!$this->isUserIPAllowed()) { return self::EXCEEDED_RESTRICTED_IP; } if ($this->original_str && $partner_id != Partner::BATCH_PARTNER_ID && !$this->isWidgetSession() && $this->isKSInvalidated() !== false) { $criteria = new Criteria(); $ksCriterion = $criteria->getNewCriterion(invalidSessionPeer::TYPE, invalidSession::INVALID_SESSION_TYPE_KS); $ksCriterion->addAnd($criteria->getNewCriterion(invalidSessionPeer::KS, $this->getHash())); $sessionId = $this->getSessionIdHash(); if ($sessionId) { $invalidSession = $criteria->getNewCriterion(invalidSessionPeer::KS, $sessionId); $invalidSession->addAnd($criteria->getNewCriterion(invalidSessionPeer::TYPE, invalidSession::INVALID_SESSION_TYPE_SESSION_ID)); $ksCriterion->addOr($invalidSession); } $criteria->add($ksCriterion); $dbKs = invalidSessionPeer::doSelectOne($criteria); if ($dbKs) { $currentActionLimit = $dbKs->getActionsLimit(); if (is_null($currentActionLimit)) { return self::LOGOUT; } elseif ($currentActionLimit <= 0) { return self::EXCEEDED_ACTIONS_LIMIT; } $dbKs->setActionsLimit($currentActionLimit - 1); $dbKs->save(); } else { $limit = $this->isSetLimitAction(); if ($limit) { invalidSessionPeer::actionsLimitKs($this, $limit - 1); } } } // creates the kuser if ($partner_id != Partner::BATCH_PARTNER_ID && PermissionPeer::isValidForPartner(PermissionName::FEATURE_END_USER_REPORTS, $partner_id)) { $this->kuser = kuserPeer::createKuserForPartner($partner_id, $puser_id); if (!$puser_id && $this->kuser->getScreenName() != 'Unknown') { $this->kuser->setScreenName('Unknown'); $this->kuser->save(); } } return self::OK; }