示例#1
0
    public function save() {
        if ($this->isFirstChangeStatus()) {
            $this->setDateApproved(Gpf_Common_DateUtils::now());
        }
        try {
            $authUser = new Gpf_Db_AuthUser();
            $authUser->setPrimaryKeyValue($this->authUser->getPrimaryKeyValue());
            $authUser->load();
            $this->accountUser->setAuthId($authUser->getId());
        } catch (Gpf_Exception $e) {
            try {
                $this->authUser->loadFromUsername();
                $this->accountUser->setAuthId($this->authUser->getId());
            } catch (Exception $e) {
            }
        }

        $this->inserting = !$this->user->rowExists();

        $this->checkConstraints();

        Gpf_Plugins_Engine::extensionPoint('PostAffiliate.User.beforeSave', $this);

        $this->authUser->save();
        $this->accountUser->setAuthId($this->authUser->getId());

        try {
            $this->accountUser->save();
        } catch (Gpf_Exception $e) {
            $this->authUser->delete();
            throw new Gpf_Exception($e->getMessage());
        }

        $this->user->set('accountuserid', $this->accountUser->get('accountuserid'));
        $this->initRefid($this->accountUser->getId());
        $this->initMinimupPayout();

        try {
            $this->user->save();
        } catch (Gpf_Exception $e) {
            $this->authUser->delete();
            $this->accountUser->delete();
            throw new Gpf_Exception($e->getMessage());
        }

        if($this->inserting) {
            $this->afterInsert();
        } else {
            Pap_Db_Table_CachedBanners::deleteCachedBannersForUser($this->user->getId(), $this->user->getRefId());
            Gpf_Plugins_Engine::extensionPoint('PostAffiliate.User.afterSave', $this);
        }
    }
示例#2
0
 private function validateUser(Pap_Db_User $user) {
     if ($user->getType() != Pap_Application::ROLETYPE_AFFILIATE) {
         return;
     }
     if ($user->getRefId() == "") {
         throw new Gpf_DbEngine_Row_ConstraintException(Pap_Db_Table_Users::REFID, $this->_("Referral ID can not be blank"));
     }
     if (Gpf_Session::getAuthUser()->isLogged() && Gpf_Session::getAuthUser()->isAffiliate()) {
         $userTmp = new Pap_Db_User();
         $userTmp->setId($user->getId());
         try {
             $userTmp->load();
         } catch (Gpf_Exception $e) {
             return;
         }
         if ($userTmp->getRefId() != $user->getRefId()) {
             throw new Gpf_DbEngine_Row_ConstraintException(Pap_Db_Table_Users::REFID, $this->_("Referral ID can not be changed"));
         }
     }
 }