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(); } }
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 executeAction() { if ($this->isConditionValid()) { $this->getActionObject()->execute(); } else { Gpf_Log::debug('Condition of rule is not valid - skipping'); } }
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); }
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)); }
/** * @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(); }
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()); }
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); } }
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.' ); } }
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) { } }
public function getFirstTheme($panelName) { $iterator = new Gpf_Io_DirectoryIterator(Gpf_Paths::getInstance()->getTopTemplatePath() . $panelName, '', false, true); $themeIds = array(); foreach ($iterator as $fullName => $themeId) { try { $theme = new Gpf_Desktop_Theme($themeId, $panelName); if (strlen($themeId) > 0 && $themeId[0] != '_' && $theme->isEnabled()) { $themeIds[] = $themeId; } } catch (Gpf_Exception $e) { Gpf_Log::debug('This is only info message: ' . $e->getMessage()); } } if (count($themeIds) > 0) { sort($themeIds, SORT_STRING); return $themeIds[0]; } throw new Gpf_Exception($this->_("No available theme") . ': ' . Gpf_Paths::getInstance()->getTopTemplatePath() . $panelName); }
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); } }
private function setFromEmailAndName(Pap_Mail_MassMailTemplate $template, $affiliateId) { $user = new Pap_Common_User(); $user->setAccountUserId($affiliateId); try { $user->loadFromData(array(Pap_Db_Table_Users::ACCOUNTUSERID)); } catch (Gpf_Exception $e) { Gpf_Log::debug('Unable to load sender information when sending broadcast mail from affiliateid: ' . $affiliateId . ', error: '. $e->getMessage()); return; } $email = $user->getUserName(); $name = $user->getFirstName() . ' ' . $user->getLastName(); $emailValidator = new Gpf_Rpc_Form_Validator_EmailValidator(); if ($emailValidator->validate($email)) { $template->setFromEmail($email); $template->setFromName($name); } }
public function saveChanges() { Gpf_Log::debug('Saving visitor affiliate cache.'); foreach ($this->visitorAffiliateCollections as $accountVisitorAffiliates) { foreach ($accountVisitorAffiliates as $visitorAffiliates) { foreach ($visitorAffiliates as $visitorAffiliate) { $visitorAffiliate->save(); Gpf_Log::debug('Saved visitor affiliate, visitorId: '. $visitorAffiliate->getVisitorId().', userId: ' . $visitorAffiliate->getUserId()); } } } $this->deleteVisitorAffiliatesFromDb(); }
protected function execute() { Gpf_Log::debug('Starting ccBill rebill process task'); if ($this->isPending('start')) { $this->setProgress(time()); } $this->processAllRefunds(); Gpf_Log::debug('Finished ccBill rebill process task'); $this->setDone(); }
private function _send() { $this->_reset_response(); $ch = curl_init(); // set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, URL);//constant("Relbit_API::URL")); curl_setopt($ch,CURLOPT_POST, 1); //temporary fix to empty responses from relbit curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); curl_setopt($ch,CURLOPT_POSTFIELDS, "request=" . urlencode(json_encode($this->request))); // TODO: weird CURL SSL handling // execute post $res = curl_exec($ch); if ($res === false) { Gpf_Log::error('Curl error: ' . curl_error($ch)); } if ($this->debug) { Gpf_Log::debug('RELBIT REQUEST: ' . print_r($this->request, true) . "\nRELBIT RESPONSE: " . print_r($res. true)); } $this->response = json_decode($res, true); // close connection curl_close($ch); $this->_reset_request(); }
public function sendOnChangeStatusNotification() { try { $user = $this->getUser($this->transaction); } catch (Gpf_DbEngine_NoRowException $e) { Gpf_Log::error('User with userid=' . $this->transaction->getUserId() . 'can not be loaded and mail can not be send.'); Gpf_Log::debug('Sending notification to affiliate ended'); return; } $isNotify = $this->isNotify($user, Pap_Settings::AFF_NOTIFICATION_ON_CHANGE_COMMISSION_STATUS_DEFAULT_SETTING_NAME, Pap_Settings::AFF_NOTIFICATION_ON_CHANGE_COMMISSION_STATUS_ENABLED_SETTING_NAME, 'aff_notification_on_change_comm_status', $this->transaction->getStatus(), Pap_Settings::AFF_NOTIFICATION_ON_CHANGE_COMMISSION_STATUS_OPTION_STATUS); if ($isNotify <> Gpf::YES) { Gpf_Log::debug('Sending change status notification to affiliate ended. Affiliate '.$user->getId().': '.$user->getName().' does not have change status notification turned on'); return; } if(Gpf_Settings::get(Pap_Settings::NOTIFICATION_ON_COMMISSION_APPROVED) == Gpf::YES && $this->transaction->getStatus() == Pap_Common_Constants::STATUS_APPROVED){ $this->sendEmail(new Pap_Mail_MerchantOnCommissionApproved(), $user, $this->transaction, $this->getMerchantEmail()); } $disableChangeStatusNotificationEmail = new Gpf_Plugins_ValueContext(false); $disableChangeStatusNotificationEmail->setArray(array($user)); Gpf_Plugins_Engine::extensionPoint('Pap_Tracking_Action_SendTransactionNotificationEmails.sendOnChangeStatusNotificationToAffiliate', $disableChangeStatusNotificationEmail); if($disableChangeStatusNotificationEmail->get()) { Gpf_Log::debug('Sending change status notification to affiliate ended by any feature or plugin. Affiliate '.$user->getId().': '.$user->getName().'.'); return; } $this->sendEmail(new Pap_Mail_AffiliateChangeCommissionStatus(), $user, $this->transaction, $user->getEmail()); Gpf_Log::debug('Sending notification to affiliate ended'); }
public function loadHistoricalRates() { $rawXmlData = file_get_contents('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml'); $xml = new SimpleXMLElement($rawXmlData); $lastDate = null; $lastRates = null; Gpf_Log::debug('Loading to db...'); foreach ($xml->{"Cube"}->{"Cube"} as $dailyRates) { $attr = $dailyRates->attributes(); $date = new Gpf_DateTime($attr['time']); Gpf_Log::debug('Loading rates for ' . $date->toDate()); $dayBefore = new Gpf_DateTime($attr['time']); $dayBefore->addDay(1); if ($lastDate !== null && $dayBefore->toDate() != $lastDate->toDate()) { Gpf_Log::debug('Last date was ' . $lastDate->toDate() . '! Extending last saved rates validFrom parameters...'); foreach ($lastRates as $rate) { Gpf_Log::debug('Extending validFrom for currency ' . $rate->getValidFrom() . ' - ' . $rate->getValidTo() . ' - ' . $rate->getTargetCurrency() . ' to value ' . $dayBefore->toDate() . ' 00:00:00'); $rate->setValidFrom($dayBefore->toDate() . ' 00:00:00'); $rate->update(array(Gpf_Db_Table_CurrencyRates::VALID_FROM)); } } Gpf_Log::debug('Saving rates for ' . $date->toDate()); $lastRates = array(); foreach ($dailyRates->{"Cube"} as $currencyRate) { $info = $currencyRate->attributes(); Gpf_Log::debug('Saving EUR to ' . $info['currency'] . ', rate=' . $info['rate']); $rate = $this->saveDailyRate($date, (string) $info['currency'], (double) $info['rate']); $lastRates[] = $rate; } $lastDate = new Gpf_DateTime($attr['time']); } Gpf_Log::debug('Load complete'); }
protected function runExistingTasks($timeFrame, $inclusion_type, $inclusion_tasks) { $startTime = time(); $lastRunTaskId = null; try { while ($timeFrame > time() - $startTime && ($task = $this->getPendingTask($lastRunTaskId, $inclusion_type, $inclusion_tasks))) { if ($inclusion_type == self::INCLUDE_TASKS && !in_array($task->getClassName(), $inclusion_tasks) || $inclusion_type == self::EXCLUDE_TASKS && in_array($task->getClassName(), $inclusion_tasks)) { Gpf_Log::debug('Skipping task ' . $task->getClassName() . ', inclusion settings: ' . $inclusion_type . ', ' . print_r($inclusion_tasks, true)); $lastRunTaskId = $task->get(Gpf_Db_Table_Tasks::ID); continue; } //Init long task try { $longTask = $this->createLongTaskObject($task->getClassName()); } catch (Exception $e) { Gpf_Log::error($this->_("Can not instantiate tasks %s with error %s", $task->getClassName(), $e->getMessage())); $lastRunTaskId = $task->get(Gpf_Db_Table_Tasks::ID); continue; } //Run long task try { Gpf_Log::debug($this->_("Running task %s", $task->getClassName())); $longTask->run($timeFrame - (time() - $startTime), $task); } catch (Gpf_Tasks_LongTaskInterrupt $e) { } catch (Exception $e) { Gpf_Log::error($this->_("Error while running task %s. Message: %s. Trace: %s.", $task->getClassName(), $e->getMessage(), $e->getTraceAsString())); } $lastRunTaskId = $task->get(Gpf_Db_Table_Tasks::ID); } } catch (Gpf_DbEngine_NoRowException $e) { Gpf_Log::debug('No task pending'); } }
protected function debug($message) { Gpf_Log::debug($message, 'HTTP'); }
/** * * @param Gpf_Net_Server_Http_Request $request * @return Gpf_Net_Server_Http_Response */ public function handle(Gpf_Net_Server_Http_Request $request) { $file = new Gpf_Io_File($this->getFileName($request->getPath())); $fileETag = $this->computeEtag($file); Gpf_Log::debug($request->toString()); if ($this->isCacheableFile($file) && $request->ifNoneMatch($fileETag)) { $response = new Gpf_Net_Server_Http_Response(304, $file); $response->setConnection('Keep-Alive'); $response->setBody("Not Modified"); $response->setETag($fileETag); Gpf_Log::debug($this->_sys("Resource not modified, returned 304 for %s", $request->getPath())); return $response; } //TODO load file from memory cache if available and not from file // - but I'm not sure if file cache will help - it can just use quite huge amount of server memory try { $file->open(); } catch (Gpf_Exception $e) { $response = new Gpf_Net_Server_Http_Response(404); $response->setBody('File not found'); Gpf_Log::info($e->getMessage()); return $response; } $response = new Gpf_Net_Server_Http_StreamResponse(200, $file); $response->setConnection('Keep-Alive'); $response->setContentType(self::getContentType(self::getFileExtension($request->getPath()))); $response->setContentLength($file->getSize()); if ($this->isCacheableFile($file)) { $response->setETag($fileETag); } Gpf_Log::debug($this->_sys("Return static file %s" . $request->getPath())); return $response; }
/** * @param string $url * @return Gpf_Gadget */ public function downloadGadget($url) { if (strpos($url, self::CONTENT_PREFFIX) === 0) { Gpf_Log::debug($this->_sys("Adding content gadget: %s", $url)); $gadget = new Gpf_Gadget_Content(); $gadget->setUrl($url); $gadget->loadConfiguration(""); return $gadget; } else { Gpf_Log::debug($this->_sys("Downloading gadget: %s", $url)); $request = new Gpf_Net_Http_Request(); $request->setUrl($url); $client = new Gpf_Net_Http_Client(); $response = $client->execute($request); $gadgetContent = $response->getBody(); foreach ($this->gadgetTypes as $className) { $gadget = Gpf::newObj($className); $gadget->setUrl($url); try { $gadget->loadConfiguration($gadgetContent); return $gadget; } catch (Gpf_Exception $e) { } } throw new Gpf_Exception($this->_("Unsupported gadget")); } }
public function writeSetting($name, $value) { $this->defines->checkSetting($name); if ($this->defines->isFileSetting($name)) { $file = $this->lock(LOCK_EX); try { $this->file->forceReload(); $this->saveFileSetting($name, $value, $file); } catch (Exception $e) { $this->unlock($file); throw $e; } $this->unlock($file); return; } if (array_key_exists($name, $this->cache) && $this->cache[$name] == $value) { Gpf_Log::debug($this->_('Setting %s have the same value %s, no change needed - skipping', $name, $value)); return; } //store setting also to settings cache $this->cache[$name] = $value; $this->saveDbSetting($name, $value); }
protected function logMessage($message) { Gpf_Log::debug($message); }
public function createFile($filename, $content) { Gpf_Log::debug('Writing content to tmp file'); $tempFile = tmpfile(); if ($tempFile === false) { Gpf_Log::error('Unable to create TMP file!'); } fwrite($tempFile, $content); fseek($tempFile, 0); $result = ftp_fput($this->ftpStream, $filename, $tempFile, FTP_BINARY); if ($result === false) { Gpf_Log::error('Unable to uplaod file to ftp'); } fclose($tempFile); }
public function processVisit(Pap_Db_Visit $visit) { $compoundContext = new Gpf_Data_Record(array(self::IP, self::COUNTRYCODE), array($visit->getIp(), '')); $this->getCountryCode($compoundContext); $countryCode = $compoundContext->get(self::COUNTRYCODE); if (!strlen($countryCode)) { Gpf_Log::debug("Preprocessing visit error: country code not recognized from IP " . $visit->getIp()); return; } Gpf_Log::debug('Preprocessing visit: found country code ' . $countryCode . ', resolved from IP ' . $visit->getIp() . ', and setting it to visit'); $visit->setCountryCode($countryCode); }
public function process(Pap_Db_Visit $visit) { Gpf_Log::debug('Action processor processing...'); $accountContext = $this->processAccount($visit); if (!$accountContext->getDoTrackerSave()) { Gpf_Log::debug('Saving disabled because of account problems.'); return; } $this->visitorAffiliateCache->setAccountId($accountContext->getAccountId()); try { $actions = $this->loadActions($visit->getSaleParams()); } catch (Gpf_Exception $e) { Gpf_Log::debug('Action processor: ' . $e->getMessage()); return; } foreach ($actions as $action) { $context = new Pap_Contexts_Action($action, $visit); $context->debug('Saving sale/action for visit: '.$visit->toText()); $context->setDoCommissionsSave(true); $context->setAccountId($accountContext->getAccountId(), $accountContext->getAccountRecognizeMethod()); try { $this->processAction($context); } catch (Gpf_Exception $e) { $context->debug("Saving commission interrupted: ".$e->getMessage()); } } }
private function computeInstalledVersions() { $this->installedVersion = false; $this->gpfInstalledVersion = false; try { $this->installedVersion = $this->computeLatestInstalledApplicationVersion(); $this->gpfInstalledVersion = Gpf_Db_Table_Versions::getInstance()->getLatestVersion(Gpf::CODE); } catch (Gpf_DbEngine_Exception $e) { throw new Gpf_DbEngine_Exception($e->getMessage()); } catch (Gpf_Exception $e) { Gpf_Log::debug('Error during computing latest versions: ' . $e->getMessage()); } }
protected function saveRawClick(Pap_Db_RawClick $rawClick) { Gpf_Log::debug('Calling save on raw click'); $rawClick->save(); Gpf_Log::debug('Saving done'); }