Exemplo n.º 1
0
 /**
 	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;
 }
Exemplo n.º 2
0
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     $target_puser_id = $this->getPM("user_id");
     $target_puser_kuser = PuserKuserPeer::retrieveByPartnerAndUid($partner_id, null, $target_puser_id);
     if ($target_puser_kuser) {
         $this->addDebug("puser_exists", $target_puser_kuser->getId());
         // might be that the puser_kuser exists but the kuser does not
         $kuser = kuserPeer::retrieveByPK($target_puser_kuser->getKuserId());
         if ($kuser) {
             $this->addError(APIErrors::DUPLICATE_USER_BY_ID, $target_puser_id);
             return;
         } else {
             // puser_kuser exists but need to create the ksuer...
         }
     } else {
         $target_puser_kuser = new PuserKuser();
         $target_puser_kuser->setPuserId($target_puser_id);
         $target_puser_kuser->setPartnerId($partner_id);
         $target_puser_kuser->save();
         $this->addDebug("Created_new_puser_kuser", $target_puser_kuser->getId());
     }
     // get the new properties for the kuser from the request
     $kuser = new kuser();
     $obj_wrapper = objectWrapperBase::getWrapperClass($kuser, 0);
     $fields_modified = baseObjectUtils::fillObjectFromMap($this->getInputParams(), $kuser, "user_", $obj_wrapper->getUpdateableFields());
     // check that mandatory fields were set
     // TODO
     if (count($fields_modified) > 0) {
         if (!$partner_id) {
             $kuser_from_db = kuserPeer::getKuserByScreenName($kuser->getScreenName());
             if ($kuser_from_db) {
                 $this->addError(APIErrors::DUPLICATE_USER_BY_SCREEN_NAME, $kuser->getScreenName());
                 return;
             }
         }
         $kuser->setPartnerId($partner_id);
         $kuser->setPuserId($target_puser_id);
         try {
             $kuser = kuserPeer::addUser($kuser);
         } catch (kUserException $e) {
             $code = $e->getCode();
             if ($code == kUserException::USER_ALREADY_EXISTS) {
                 $this->addException(APIErrors::DUPLICATE_USER_BY_ID, $kuser->getId());
                 return null;
             }
             if ($code == kUserException::LOGIN_ID_ALREADY_USED) {
                 $this->addException(APIErrors::DUPLICATE_USER_BY_LOGIN_ID, $kuser->getEmail());
                 return null;
             } else {
                 if ($code == kUserException::USER_ID_MISSING) {
                     $this->addException(APIErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL, 'id');
                     return null;
                 } else {
                     if ($code == kUserException::INVALID_EMAIL) {
                         $this->addException(APIErrors::INVALID_FIELD_VALUE);
                         return null;
                     } else {
                         if ($code == kUserException::INVALID_PARTNER) {
                             $this->addException(APIErrors::UNKNOWN_PARTNER_ID);
                             return null;
                         } else {
                             if ($code == kUserException::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED) {
                                 $this->addException(APIErrors::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED);
                                 return null;
                             } else {
                                 if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) {
                                     $this->addException(APIErrors::PASSWORD_STRUCTURE_INVALID);
                                     return null;
                                 }
                             }
                         }
                     }
                 }
             }
             throw $e;
         } catch (kPermissionException $e) {
             $code = $e->getCode();
             if ($code == kPermissionException::ROLE_ID_MISSING) {
                 $this->addException(APIErrors::ROLE_ID_MISSING);
                 return null;
             }
             if ($code == kPermissionException::ONLY_ONE_ROLE_PER_USER_ALLOWED) {
                 $this->addException(APIErrors::ONLY_ONE_ROLE_PER_USER_ALLOWED);
                 return null;
             }
             throw $e;
         }
         // now update the puser_kuser
         $target_puser_kuser->setPuserName($kuser->getScreenName());
         $target_puser_kuser->setKuserId($kuser->getId());
         $target_puser_kuser->save();
         $this->addMsg("user", objectWrapperBase::getWrapperClass($target_puser_kuser, objectWrapperBase::DETAIL_LEVEL_DETAILED));
         $this->addDebug("added_fields", $fields_modified);
     } else {
         $this->addError(APIErrors::NO_FIELDS_SET_FOR_USER);
     }
 }