Example #1
0
 protected function execute()
 {
     Gpf_Log::info('Executing Currency updater task');
     $this->updateDailyCurrencies();
     $this->setDone();
     Gpf_Log::info('End of Currency updater task');
 }
 protected function log($time, $message, $logLevel, $logGroup, $ip, $file, $line, $type = null)
 {
     if ($message == "") {
         return;
     }
     $timeString = strftime("Y-m-d H:i:s", $time);
     $userId = null;
     try {
         $userId = Gpf_Session::getAuthUser()->getUserId();
     } catch (Gpf_Exception $e) {
     }
     try {
         $dbLog = new Gpf_Db_Log();
         $dbLog->set('groupid', $logGroup);
         $dbLog->set('level', $logLevel);
         $dbLog->set('created', $timeString);
         $dbLog->set('filename', $file);
         $dbLog->set('message', $message);
         $dbLog->set('line', $line);
         $dbLog->set('ip', $ip);
         $dbLog->set('accountuserid', $userId);
         $dbLog->set(Gpf_Db_Table_Logs::TYPE, $type);
         $dbLog->save();
     } catch (Exception $e) {
         Gpf_Log::disableType(Gpf_Log_LoggerDatabase::TYPE);
         Gpf_Log::error($this->_sys("Database Logger Error. Logging on display: %s", $message));
         Gpf_Log::enableAllTypes();
     }
 }
Example #3
0
 /**
  * @return Gpf_Log_Logger
  */
 private static function getLogger()
 {
     if (self::$logger == null) {
         self::$logger = Gpf_Log_Logger::getInstance();
     }
     return self::$logger;
 }
Example #4
0
 	public function addCommission(Pap_Contexts_Signup $signupContext) {
 	    if (($user = $signupContext->getUserObject()) == null) {
 	        return;
 	    } 
 	    
 	    $campaignId = Gpf_Settings::get(SignupActionCommissions_Config::AFTER_SIGNUP_ACTION_CAMPAIGNID);
 	    $actionCode = Gpf_Settings::get(SignupActionCommissions_Config::AFTER_SIGNUP_ACTION_CODE);
 	    
 	    if ($actionCode == '') {
 	        Gpf_Log::error('SignupActionCommissions plugin: No Action code set');
 	        return;
 	    }
        
 	    $saleTracker = new Pap_Tracking_ActionTracker();
 	    
        $action = $saleTracker->createAction($actionCode);
        $action->setAffiliateID($user->getId());    
        $action->setStatus($user->getStatus());
        $action->setOrderId(SignupActionCommissions_Config::DEFAULT_ORDER_ID);
        if ($campaignId != '') {
          $action->setCampaignID($campaignId);
        }
        try {
            $saleTracker->register();
        } catch (Gpf_Exception $e) {
            Gpf_Log::error('SignupActionCommissions plugin: '.$e->getMessage());
        }
        
 	}
 public function invoke(Gpf_Rpc_Params $params)
 {
     Gpf_Log::debug($this->_sys("Invoking method %s->%s()", $this->className, $this->methodName));
     $this->checkPermissions($params);
     $this->checkParams();
     return call_user_func(array(&$this->serviceObj, $this->methodName), $params);
 }
Example #6
0
 protected function signUserToCampaign($userId, $campaignId, Gpf_Rpc_Form $form) {
     $campaign = new Pap_Common_Campaign();
     $campaign->setId($campaignId);
     try {
         $campaign->load();
     } catch (Gpf_Exception $e) {
         Gpf_Log::debug('SignupToCampaignPlugin: Invalid campaign '.$campaignId);
         return false;
     }
     if ($campaign->getCampaignType() == Pap_Common_Campaign::CAMPAIGN_TYPE_PUBLIC) {
         return false;
     }
     $userInCommGroup = new Pap_Db_UserInCommissionGroup();
     
     $user = new pap_common_user();
     $user->setId($userId);
     $user->load();
     if($user->getStatus() == Pap_Common_Constants::STATUS_PENDING){
         $userInCommGroup->addUserToGroup($campaign->getId(), $userId,
         $campaign->getDefaultCommissionGroup(), Pap_Common_Constants::STATUS_APPROVED);
         return true;
     }
     $userInCommGroup->addUserToGroupAndSendNotification($campaign->getId(), $userId,
     $campaign->getDefaultCommissionGroup(), Pap_Common_Constants::STATUS_APPROVED);
     return true;
 }
 public function execute() {
     Gpf_Log::debug('Executing rule: Add bonus commission to original parent affiliate for every sale...');
     if ($this->transaction->getType()!=Pap_Common_Transaction::TYPE_EXTRA_BONUS && $this->transaction->getTier()==1) {
         Gpf_Log::debug('Okay, this is 1st tier, not bonus commission, so we can create new bonus.');
         $this->addBonus();
     }
 }
Example #8
0
 public function executeAction() {
     if ($this->isConditionValid()) {
         $this->getActionObject()->execute();
     } else {
         Gpf_Log::debug('Condition of rule is not valid - skipping');
     }
 }
 function LogRequest($log){
   if($this->logLevel & self::L_RQST){
     Gpf_Log::error(sprintf("\n%s:- %s\n",date("D M j G:i:s T Y"),$log)); 
      return true;
   }
   return false;
 }
 public function saveConfiguration(Gpf_Plugins_EngineSettings $configuration)
 {
     if (defined('ENABLE_ENGINECONFIG_LOG')) {
         Gpf_Log::info('Writing configuration: ' . print_r($configuration, true));
     }
     $this->setSetting(self::CONFIGURATION, serialize($configuration));
 }
Example #11
0
 public function logMetadata()
 {
     $sendBuffer = socket_get_option($this->socket, SOL_SOCKET, SO_SNDBUF);
     $rcvBuffer = socket_get_option($this->socket, SOL_SOCKET, SO_RCVBUF);
     $linger = socket_get_option($this->socket, SOL_SOCKET, SO_LINGER);
     $keep = socket_get_option($this->socket, SOL_SOCKET, SO_KEEPALIVE);
     Gpf_Log::debug(var_export(array('send' => $sendBuffer, 'rcv' => $rcvBuffer, 'linger' => $linger, 'keepalive' => $keep), true));
 }
 private function interruptIfMemoryFull()
 {
     if ($this->checkIfMemoryIsFull(memory_get_usage())) {
         Gpf_Log::warning('Be carefull, memory was filled up so im interrupting Gpf_Newsletter_GenerateBroadcastMailsTask task.');
         $this->setDone();
         $this->interrupt();
     }
 }
 protected function logException()
 {
     if ($this->isLoggerException) {
         parent::logException();
         return;
     }
     Gpf_Log::error($this->getMessage());
 }
 /**
  * @throws Gpf_Exception
  */
 public function execute() {
     Gpf_Log::debug('Executing rule: Add bonus commission to affiliate...');
     if($this->isExtraBonusExists()) {
         Gpf_Log::debug('Bonus already exist. Skipping.');
         return;
     }
     $this->addBonus();
 }
 public function __construct(Pap_Common_Transaction $transaction) {
     try {
         $user = $this->loadUser($transaction->getUserId());
         $this->setAttributes($user->getName(), $user->getEmail(), $transaction);
     } catch (Gpf_DbEngine_NoRowException $e) {
         Gpf_Log::warning('User with userid=' . $transaction->getUserId() . ' was not found!');
         $this->setAttributes($this->_('Unknown user'), $this->_('Unknown email'), $transaction);
     }
 }
 public function sendNewUserSignupDeclinedMail(Pap_Common_User $user, $recipient) {
     if (Gpf_Settings::get(Pap_Settings::AFF_NOTOFICATION_SIGNUP_APPROVED_DECLINED) == Gpf::NO) {
         Gpf_Log::info('Sending approval/declined mails to affiliate was disabled');
         return;
     }
     $signupMail = new Pap_Mail_NewUserSignupDeclined();
     $signupMail->setUser($user);
     $signupMail->addRecipient($recipient);
     $signupMail->sendNow();
 }
 private function sendNotificationToMerchant(Pap_Db_DirectLinkUrl $directLink) {
     $mail = new Pap_Mail_MerchantNewDirectLinkNotification($directLink);
     $mail->loadUser(Gpf_Session::getAuthUser()->getPapUserId());
     $mail->addRecipient(Pap_Common_User::getMerchantEmail());
     try {
         $mail->send();
     } catch (Exception $e) {
     	Gpf_Log::error($this->_('Error sending new direct link notification email to merchant: %s', $e->getMessage()));
     }
 }
Example #18
0
 protected function sendNewUserSignupApprovedMail() {
     $disableApprovalEmailNewUserSignup = new Gpf_Plugins_ValueContext(false);
     $disableApprovalEmailNewUserSignup->setArray(array($this));
     Gpf_Plugins_Engine::extensionPoint('PostAffiliate.affiliate.sendNewUserSignupApprovedMail', $disableApprovalEmailNewUserSignup);
     if ($disableApprovalEmailNewUserSignup->get()) {
         Gpf_Log::debug('Sending NewUserSignupApproved notification to affiliate ended by any feature or plugin. Affiliate '.$this->getId().': '.$this->getName().'.');
         return;
     }
     $signupEmail = new Pap_Signup_SendEmailToUser();
     $signupEmail->sendNewUserSignupApprovedMail($this, $this->getEmail());
 }
Example #19
0
 private function handleError($sth)
 {
     if ($sth->getErrorCode() == self::CR_SERVER_GONE_ERROR) {
         Gpf_Log::disableType(Gpf_Log_LoggerDatabase::TYPE);
         Gpf_Log::info($this->_sys('MySql server has gone away: Reconnecting...'));
         Gpf_Log::enableAllTypes();
         throw new Gpf_DbEngine_ConnectionGoneException($this->_sys('MySql server has gone away.'));
     }
     Gpf_Log_Benchmark::end(self::BENCHMARK_EXECUTE, "SQL ERROR: " . $sth->getStatement());
     $this->resetFailedConnectionsCount();
     throw new Gpf_DbEngine_Driver_Mysql_SqlException($sth->getStatement(), $sth->getErrorMessage(), $sth->getErrorCode());
 }
Example #20
0
	public function processFillBonus(Pap_Common_User $child) {
		try {
			$originalParent = Pap_Affiliates_User::loadFromId($child->getOriginalParentUserId());
		} catch (Gpf_Exception $e) {
		    Gpf_Log::debug('Forced Matrix: Cannot load parent: ' . $e->getMessage());
			return;
		}
		$matrix = $this->createMatrix();
		if ($matrix->isFilled($originalParent)) {
			$matrixFillBonus = new Pap_Features_ForcedMatrix_MatrixFillBonus();
			$matrixFillBonus->process($originalParent);
		}
	}
Example #21
0
 private function approveRecurringCommission($transactionId) {
     $recurringCommission = new Pap_Db_RecurringCommission();
     $recurringCommission->setTransactionId($transactionId);
     try {
         $recurringCommission->loadFromData(array(Pap_Db_Table_RecurringCommissions::TRANSACTION_ID));
         if ($recurringCommission->getStatus() == Pap_Common_Constants::STATUS_PENDING) {
             $recurringCommission->setStatus(Pap_Common_Constants::STATUS_APPROVED);
             $recurringCommission->update(array(Pap_Db_Table_RecurringCommissions::STATUS));
             Gpf_Log::debug('Recurring commission for transacton id: ' . $transactionId . ' is approved.' );
         }
     } catch (Gpf_DbEngine_NoRowException $e) {
         Gpf_Log::debug('Transacton id: ' . $transactionId . ' does not have recurring commission.' );
     }
 }
Example #22
0
 public function getList() {
     try {
         return $this->transactionList->getHtml(10);
     } catch (Exception $e) {
         if (Gpf_Log::isLogToDisplay()) {
             Gpf_Log::critical('Report list, getHtml exception: ' . $e->getMessage());
         } else { 
             Gpf_Log::addLogger(Gpf_Log_LoggerDisplay::TYPE, Gpf_Log::CRITICAL);
             Gpf_Log::critical('Report list, getHtml exception: ' . $e->getMessage());
             Gpf_Log::disableType(Gpf_Log_LoggerDisplay::TYPE);
         }
         throw $e;
     }
 }
Example #23
0
 public function checkRules(Pap_Common_Transaction $transaction) {
     Gpf_Log::debug('Performance reward started');
     foreach($this->getRules($transaction->getCampaignId()) as $ruleRecord) {
         $rule = new Pap_Features_PerformanceRewards_Rule_Transaction($transaction);
         $rule->fillFromRecord($ruleRecord);
         try {
             Gpf_Log::debug('Processing rule ' . $rule->getId() . ': ' . $rule->getAction());
             $rule->executeAction();
             Gpf_Log::debug('Rule completed');
         } catch (Exception $e) {
             Gpf_Log::error(sprintf('Rule %s failed. Reason: %s', $rule->getId(), $e->getMessage()));
         }
     }
     Gpf_Log::debug('Performance reward ended');
 }
 public static function forwardPostCurlAsync($toUrl)
 {
     try {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $toUrl);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
         curl_setopt($ch, CURLOPT_TIMEOUT_MS, 2000);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $_REQUEST);
         if (curl_exec($ch) === false) {
             Gpf_Log::debug('Curl error: ' . curl_error($ch) . ', code: ' . curl_errno($ch));
         }
         curl_close($ch);
     } catch (Exception $e) {
     }
 }
 /**
  *
  * @return Pap_Db_UserInCommissionGroup
  */
 protected function getUserCommissionGroup() {
     if($this->userInGroup !== null) {
         return $this->userInGroup;
     }
     try {
         $userInGroup = Pap_Db_Table_UserInCommissionGroup::getInstance()->getUserCommissionGroup(
             $this->getCurrentUserId(), $this->transaction->getCampaignId());
     } catch (Gpf_DbEngine_TooManyRowsException $e) {
         Gpf_Log::error(sprintf('Database not in consistent state. User %s has many commission groups', $userId));
         Pap_Db_Table_UserInCommissionGroup::removeUserFromCampaignGroups($userId, $campaignId);
         $userInGroup = new Pap_Db_UserInCommissionGroup();
         $userInGroup->setStatus(Pap_Features_PerformanceRewards_Condition::STATUS_APPROVED);
         $userInGroup->setUserId($userId);
     }
     return $this->userInGroup = $userInGroup;
 }
Example #26
0
    /**
     * returns commission group for user.
     * If it doesn't exists, it will create default commission group and assign user to it.
     *
     * @param string $userId
     * @return string or false
     */
    public function getCommissionGroupForUser($userId) {
        $commGroupId = $this->checkUserIsInCampaign($userId);

        if($commGroupId != false) {
            return $commGroupId;
        }

        if($this->getCampaignType() == Pap_Db_Campaign::CAMPAIGN_TYPE_PUBLIC) {

            $defaultCommGroupId = $this->getDefaultCommissionGroup();

            return $defaultCommGroupId;
        }
        Gpf_Log::info($this->_('No commissiongroup recognized - this is just hint: This campaign has type: %s. If, problem occured during commissiongrup recognition, you shoud check if this type is correct.', $this->getCampaignType()));

        return false;
    }
Example #27
0
 /**
  * Execute request to CPanel
  *
  * @param $path CPanel command path
  * @param $params Array of parameters, which input to CPanel command
  * @return SimpleXMLElement
  */
 protected function execute($path, $params = array())
 {
     $client = new Gpf_Net_Http_Client();
     $request = new Gpf_Net_Http_Request();
     $url = ($this->useSsl ? 'https://' : 'http://') . $this->host . ':' . $this->port . $path;
     Gpf_Log::info('Request URL: ' . $url);
     $query = '';
     foreach ($params as $name => $value) {
         $query .= '&' . $name . '=' . urlencode($value);
     }
     Gpf_Log::info('Request params: ' . $query);
     $request->setUrl($url . (strlen($query) ? '?' : '') . ltrim($query, '&'));
     $request->setHttpUser($this->user);
     $request->setHttpPassword($this->passwd);
     Gpf_Log::info("Executing HTTP request: " . $request->toString());
     return $this->parseResult($client->execute($request));
 }
 private function generateDefaultValue($userId) {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->add('MAX(CAST(SUBSTR('.Pap_Db_Table_Channels::VALUE.', 5) AS UNSIGNED))', 'max');
     $select->from->add(Pap_Db_Table_Channels::getName());
     $select->where->add(Pap_Db_Table_Channels::VALUE, 'like', 'code%');
     $select->where->add(Pap_Db_Table_Channels::USER_ID, '=', $userId);
     try {
         $result = $select->getOneRow();
         $max = $result->get('max')+1;
     } catch (Gpf_DbEngine_NoRowException $e) {
         $max = 1;
     } catch (Gpf_DbEngine_TooManyRowsException $e) {
         Gpf_Log::error('Database not in consistent state. Error in qu_pap_channels.');
     }
     if (isset($max)) {
         return 'code'.$max;
     }
     return 'code';
 }
 protected function copy(Gpf_Io_File $source, Gpf_Io_File $target)
 {
     $this->resourceOverwritten = false;
     if ($target->isExists() && $this->isFileChanged($source, $target)) {
         try {
             Gpf_Io_File::copy($target, new Gpf_Io_File($target->getFileName() . '.v' . str_replace('.', '_', Gpf_Application::getInstance()->getVersion())), $this->mode);
             $this->resourceOverwritten = true;
         } catch (Gpf_Exception $e) {
             $message = $this->_('Could not backup changed theme resource file %s (%s)', $target->getFileName(), $e->getMessage());
             Gpf_Log::error($message);
             throw new Gpf_Exception($message);
         }
     }
     try {
         Gpf_Io_File::copy($source, $target, $this->mode);
     } catch (Gpf_Exception $e) {
         $message = $this->_('Could not install new theme resource (%s) file.  Make sure that file is writable by webserver.', $target->getFileName());
         Gpf_Log::error($message);
         throw new Gpf_Exception($message);
     }
 }
 private function saveCommissionGroup($campaignId, $userId, $newCommissionGroupId) {
 	$cgTable = Pap_Db_Table_CommissionGroups::getInstance();
 	$oldCommissionGroupId = $cgTable->getUserCommissionGroup($campaignId, $userId);
 	$status = Pap_Common_Constants::STATUS_APPROVED;
 	
     if ($oldCommissionGroupId != null) {
         try {
             $status = Pap_Db_Table_UserInCommissionGroup::getStatus($campaignId, $userId);
         } catch (Gpf_DbEngine_NoRowException $e) {
             Gpf_Log::debug('Row in userincommissiongroup should exist for userId: '.$userId.' and campaignId: '.$campaignId);
         }
     	$this->deleteUserInCommissionGroups($oldCommissionGroupId, $userId);
     }
     
     $commissionGroup = new Pap_Db_CommissionGroup();
     $commissionGroup->setPrimaryKeyValue($newCommissionGroupId);
     $commissionGroup->load();
     
     if ($commissionGroup->getIsDefault() != Gpf::YES) {
     	$this->addUserInCommissionGroup($newCommissionGroupId, $userId, $status);
     }
 }