/** * Removes a subscriber from a specific list for this provider * * @param mixed $listId * @param Interspire_EmailIntegration_Subscription $subscription * @param bool $asynchronous * @return Interspire_EmailIntegration_RemoveSubscriberResult */ public function removeSubscriberFromList ($listId, Interspire_EmailIntegration_Subscription $subscription, $asynchronous = true) { /** @var ISC_LOG */ $log = $GLOBALS['ISC_CLASS_LOG']; if ($asynchronous) { // queue job for later and return immediately Interspire_TaskManager::createTask('emailintegration', 'Job_EmailIntegration_RemoveSubscriberFromList', array( 'module' => str_replace('emailintegration_', '', $this->GetId()), 'listId' => $listId, 'email' => $subscription->getSubscriptionEmail(), )); return new Interspire_EmailIntegration_RemoveSubscriberResult($this->GetId(), $listId, true); } // run immediately $list = $this->getList($listId); if (!$list) { $log->LogSystemError(array('emailintegration', $this->GetName()), GetLang('EmailIntegrationRemoveSubscriberListDoesntExist', array( 'email' => $subscription->getSubscriptionEmail(), 'provider' => $this->GetName(), 'list' => $listId, ))); return new Interspire_EmailIntegration_RemoveSubscriberResult($this->GetId(), $listId, false, false); } $exists = $this->findListSubscriber($list['provider_list_id'], $subscription); if (is_array($exists)) { $exists = true; } else { $exists = false; } if ($exists) { $api = $this->getApiInstance(); $success = $api->listUnsubscribe($listId, $subscription->getSubscriptionEmail(), true, false, false); } else { $success = true; } if ($success) { if ($exists) { $log->LogSystemSuccess(array('emailintegration', $this->GetName()), GetLang('EmailIntegrationSubscriberRemoved', array( 'email' => $subscription->getSubscriptionEmail(), 'provider' => $this->GetName(), 'list' => $list['name'], ))); } else { $log->LogSystemDebug(array('emailintegration', $this->GetName()), GetLang('EmailIntegrationRemoveSubscriberDoesntExist', array( 'email' => $subscription->getSubscriptionEmail(), 'provider' => $this->GetName(), 'list' => $list['name'], ))); } } else { $log->LogSystemError(array('emailintegration', $this->GetName()), GetLang('EmailIntegrationSubscriberRemoveFailed', array( 'email' => $subscription->getSubscriptionEmail(), 'provider' => $this->GetName(), 'list' => $list['name'], )), $api->errorMessage); } return new Interspire_EmailIntegration_RemoveSubscriberResult($this->GetId(), $listId, false, $success, $exists); }
/** * Removes a subscriber from a specific list for this provider * * @param mixed $listId * @param Interspire_EmailIntegration_Subscription $subscription * @param bool $asynchronous * @return Interspire_EmailIntegration_RemoveSubscriberResult */ public function removeSubscriberFromList ($listId, Interspire_EmailIntegration_Subscription $subscription, $asynchronous = true) { /** @var ISC_LOG */ $log = $GLOBALS['ISC_CLASS_LOG']; if ($asynchronous) { // queue job for later and return immediately Interspire_TaskManager::createTask('emailintegration', 'Job_EmailIntegration_RemoveSubscriberFromList', array( 'module' => str_replace('emailintegration_', '', $this->GetId()), 'listId' => $listId, 'email' => $subscription->getSubscriptionEmail(), )); return new Interspire_EmailIntegration_RemoveSubscriberResult($this->GetId(), $listId, true); } // run immediately $list = $this->getList($listId); if (!$list) { $log->LogSystemError(array('emailintegration', $this->GetName()), GetLang('EmailIntegrationRemoveSubscriberListDoesntExist', array( 'email' => $subscription->getSubscriptionEmail(), 'provider' => $this->GetName(), 'list' => $listId, ))); return new Interspire_EmailIntegration_RemoveSubscriberResult($this->GetId(), $listId, false, false); } $api = $this->getApiInstance(); $exists = $api->isSubscriberOnList($subscription->getSubscriptionEmail(), $listId); if ($exists && $exists->isSuccess() && (string)$exists->getData()) { $exists = true; } else { $exists = false; } if ($exists) { try { $result = $api->deleteSubscriber($listId, $subscription->getSubscriptionEmail()); $success = $result->isSuccess(); } catch (Interspire_EmailIntegration_EmailMarketer_Exception $exception) { $error = GetLang(get_class($exception) . '_Message'); $log->LogSystemError(array('emailintegration', $this->GetName()), $error); $success = false; } } else { $success = true; } if ($success) { if ($exists) { $log->LogSystemSuccess(array('emailintegration', $this->GetName()), GetLang('EmailIntegrationSubscriberRemoved', array( 'email' => $subscription->getSubscriptionEmail(), 'provider' => $this->GetName(), 'list' => $list['name'], ))); } else { $log->LogSystemDebug(array('emailintegration', $this->GetName()), GetLang('EmailIntegrationRemoveSubscriberDoesntExist', array( 'email' => $subscription->getSubscriptionEmail(), 'provider' => $this->GetName(), 'list' => $list['name'], ))); } } else { $log->LogSystemError(array('emailintegration', $this->GetName()), GetLang('EmailIntegrationSubscriberRemoveFailed', array( 'email' => $subscription->getSubscriptionEmail(), 'provider' => $this->GetName(), 'list' => $list['name'], )), $error); } return new Interspire_EmailIntegration_RemoveSubscriberResult($this->GetId(), $listId, false, $success, $exists); }
public function addSubscriberToList ($listId, Interspire_EmailIntegration_Subscription $subscription, $fieldMap, $asynchronous = true) { /** @var ISC_LOG */ $log = $GLOBALS['ISC_CLASS_LOG']; /** @var mysqldb */ $db = $GLOBALS['ISC_CLASS_DB']; // the field mapping is most likely subscribers.subfirstname -> $subscription->firstName but, just incase, use the provided field map in the rule anyway $data = $subscription->getSubscriptionData(); $insert = array( 'subemail' => $subscription->getSubscriptionEmail(), 'subfirstname' => $data[$fieldMap['subfirstname']], ); $existed = (bool)$db->FetchOne("SELECT COUNT(*) FROM [|PREFIX|]subscribers WHERE subemail = '" . $db->Quote($insert['subemail']) . "'"); if (!$existed) { $success = (bool)$db->InsertQuery('subscribers', $insert); } else { $success = true; } if ($success) { $log->LogSystemSuccess(array('emailintegration', $this->GetName()), GetLang('EmailIntegration_ExportOnly_Stored', array( 'email' => $insert['subemail'], ))); } else { $log->LogSystemError(array('emailintegration', $this->GetName()), GetLang('EmailIntegration_ExportOnly_FailedToStore')); } return new Interspire_EmailIntegration_AddSubscriberResult($this->GetId(), $listId, false, $success, $existed); }
/** * Notify admin by email of a failed subscription * * @param Interspire_EmailIntegration_Subscription $subscription Failed subscription * @param array $merge Failed merge data * @param string $errorMessage */ public function notifyAdmin(Interspire_EmailIntegration_Subscription $subscription, $merge, $errorMessage) { // can't rely on ISC_ADMIN_ENGINE or admin lang stuff from here because this code may be run by the task manager $languagePath = ISC_BASE_PATH . '/language/' . GetConfig('Language') . '/admin'; ParseLangFile($languagePath . '/common.ini'); ParseLangFile($languagePath . '/settings.emailintegration.ini'); $replacements = array( 'provider' => $this->GetName(), 'time' => isc_date(GetConfig('ExtendedDisplayDateFormat'), time()), ); $GLOBALS['EmailHeader'] = GetLang("NoCheckoutProvidersSubject"); $GLOBALS['EmailMessage'] = sprintf(GetLang("NoCheckoutProvidersErrorLong"), $GLOBALS['ShopPath']); $GLOBALS['SubscriptionDetails'] = ''; $GLOBALS['EmailIntegrationNotice_Header'] = GetLang('EmailIntegrationNotice_Header', $replacements); $GLOBALS['EmailIntegrationNotice_Intro'] = GetLang('EmailIntegrationNotice_Intro', $replacements); $GLOBALS['EmailIntegrationNotice_Error'] = GetLang('EmailIntegrationNotice_Error', $replacements); $GLOBALS['EmailIntegrationNotice_Message'] = $errorMessage; $GLOBALS['EmailIntegrationNotice_Time'] = GetLang('EmailIntegrationNotice_Time', $replacements); $GLOBALS['EmailIntegrationNotice_Details'] = GetLang('EmailIntegrationNotice_Details', $replacements); $GLOBALS['EmailIntegrationNotice_Type'] = $subscription->getSubscriptionTypeLang(); $details = new Xhtml_Table(); $row = new Xhtml_Tr(); $row->appendChild(new Xhtml_Th(GetLang('EmailIntegrationNotice_Columns_Provider', $replacements))); $row->appendChild(new Xhtml_Th(GetLang('EmailIntegrationNotice_Columns_Subscription', $replacements))); $details->appendChild($row); $row = new Xhtml_Tr(); $row->appendChild(new Xhtml_Td($this->getEmailProviderFieldId())); $row->appendChild(new Xhtml_Td($subscription->getSubscriptionEmail())); $details->appendChild($row); foreach ($merge as $field => $value) { $row = new Xhtml_Tr(); $row->appendChild(new Xhtml_Td($field)); $row->appendChild(new Xhtml_Td($value)); $details->appendChild($row); } $GLOBALS['EmailIntegrationNotice_Subscription'] = $details->render(); $GLOBALS['EmailIntegrationNotice_CommonCauses'] = GetLang('EmailIntegrationNotice_CommonCauses', $replacements); $GLOBALS['EmailIntegrationNotice_Cause1_Intro'] = GetLang('EmailIntegrationNotice_Cause1_Intro', $replacements); $GLOBALS['EmailIntegrationNotice_Cause1_Detail'] = GetLang('EmailIntegrationNotice_Cause1_Detail', $replacements); $GLOBALS['EmailIntegrationNotice_Cause2_Intro'] = GetLang('EmailIntegrationNotice_Cause2_Intro', $replacements); $GLOBALS['EmailIntegrationNotice_Cause2_Detail'] = GetLang('EmailIntegrationNotice_Cause2_Detail', $replacements); $GLOBALS['EmailIntegrationNotice_Cause3_Intro'] = GetLang('EmailIntegrationNotice_Cause3_Intro', $replacements); $GLOBALS['EmailIntegrationNotice_Cause3_Detail'] = GetLang('EmailIntegrationNotice_Cause3_Detail', $replacements); $GLOBALS['EmailIntegrationNotice_Cause4_Intro'] = GetLang('EmailIntegrationNotice_Cause4_Intro', $replacements); $GLOBALS['EmailIntegrationNotice_Cause4_Detail'] = GetLang('EmailIntegrationNotice_Cause4_Detail', $replacements); $GLOBALS['EmailIntegrationNotice_Cause5_Intro'] = GetLang('EmailIntegrationNotice_Cause5_Intro', $replacements); $GLOBALS['EmailIntegrationNotice_Cause5_Detail'] = GetLang('EmailIntegrationNotice_Cause5_Detail', $replacements); $GLOBALS['EmailIntegrationNotice_Closing'] = GetLang('EmailIntegrationNotice_Closing', $replacements); $emailTemplate = FetchEmailTemplateParser(); $emailTemplate->SetTemplate("email_integration_notice_email"); $message = $emailTemplate->ParseTemplate(true); $obj_email = GetEmailClass(); $obj_email->Set('CharSet', GetConfig('CharacterSet')); $obj_email->From(GetConfig('OrderEmail'), GetConfig('StoreName')); $obj_email->Set("Subject", GetLang("EmailIntegrationEmailSubject")); $obj_email->AddBody("html", $message); $obj_email->AddRecipient(GetConfig('AdminEmail'), "", "h"); $email_result = $obj_email->Send(); }