/** * Begins an actual export job sequence based on requested data -- the job class itself will validate most of this info before attempting an export * * @param array $data */ protected function _moduleExportCommenceCommon($data) { $keystore = Interspire_KeyStore::instance(); // find a unique export id to use do { $id = md5(uniqid('',true)); } while ($keystore->exists('email:module_export:id:' . $id)); $keystore->set('email:module_export:id:' . $id, $id); $prefix = 'email:module_export:' . $id; if (!isset($data['exportSearch'])) { $data['exportSearch'] = array(); } if (!isset($data['exportMap'])) { $data['exportMap'] = array(); } $keystore->set($prefix . ':started', time()); $keystore->set($prefix . ':abort', 0); $keystore->set($prefix . ':skip', 0); $keystore->set($prefix . ':type', $data['exportType']); $keystore->set($prefix . ':module', $data['exportModule']); $keystore->set($prefix . ':list', $data['exportList']); $keystore->set($prefix . ':search', ISC_JSON::encode($data['exportSearch'])); $keystore->set($prefix . ':map', ISC_JSON::encode($data['exportMap'])); $keystore->set($prefix . ':success_count', 0); $keystore->set($prefix . ':error_count', 0); $keystore->set($prefix . ':doubleoptin', $data['exportDoubleOptin']); $keystore->set($prefix . ':updateexisting', $data['exportUpdateExisting']); // so we can send an email later, or diagnose troublesome users $user = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetUser(); $keystore->set($prefix . ':owner:id', $user['pk_userid']); $keystore->set($prefix . ':owner:username', $user['username']); $keystore->set($prefix . ':owner:email', $user['useremail']); $jobData = array( 'id' => $id, ); $json = array( 'success' => (bool)Interspire_TaskManager::createTask('emailintegration', 'Job_EmailIntegration_ModuleExport', $jobData), 'id' => $id, ); if (isset($data['return']) && $data['return']) { return $json; } ISC_JSON::output($json); }
/** * 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); }
/** * requeue this export job so it can process the next batch * * @return mixed result of Interspire_TaskManager::createTask */ protected function _repeatExport() { $this->_logDebug('repeating'); return Interspire_TaskManager::createTask('emailintegration', get_class($this), $this->args); }
/** * Aborts an in-progress listing job * */ private function abortProductListingAction() { $jobId = $_POST['jobId']; $jobKey = 'ebay:list_products:id:' . $jobId; $abortFlag = 'ebay:list_products:' . $jobId . ':abort'; $keystore = Interspire_KeyStore::instance(); if ($keystore->exists($jobKey)) { $keystore->set($abortFlag, 1); // if the export job has crashed, the abort will never be detected and data will never be cleaned up Interspire_TaskManager::createTask('ebay', 'Job_Ebay_ListProducts', array( 'id' => $jobId, )); } }
public function updateSubscriptionIP ($email, $ip, $asynchronous = true) { if ($asynchronous) { // queue job for later and return immediately Interspire_TaskManager::createTask('emailintegration', 'Job_EmailIntegration_UpdateSubscriptionIP', array( 'module' => $this->GetId(), 'email' => $email, 'ip' => $ip, )); return true; } $api = $this->getApiInstance(); /** @var ISC_LOG */ $log = $GLOBALS['ISC_CLASS_LOG']; try { // get lists to update for this subscriber $lists = $api->getAllListsForEmailAddress($email); if (!$lists || !$lists->isSuccess()) { return false; } // update this subscriber's ip address on all lists foreach ($lists->getData()->children() as $list) { $result = $api->updateSubscriberIP($email, (string)$list->listid, $ip); if (!$result || !$result->isSuccess()) { return false; } } } catch (Interspire_EmailIntegration_EmailMarketer_Exception $exception) { $log->LogSystemError(array('emailintegration', $this->GetName()), GetLang(get_class($exception) . '_Message')); return false; } return true; }
/** * Summarise logs for a given session id, copying raw data from product_views into product_views_summary * * @param string $sessionHash * @return void */ public static function summariseLogs($sessionHash) { if (!self::isEnabled()) { // the setting is disabled; this also stops data tracking return; } // gather a dataset of products viewed in the given session and place it in a background task for summarising, remove it from product_views so it isn't re-processed $db = $GLOBALS['ISC_CLASS_DB']; $sql = "SELECT product FROM `[|PREFIX|]product_views` WHERE `session` = '" . $db->Quote($sessionHash) . "' ORDER BY product"; $result = $db->Query($sql); $products = array(); while ($row = $db->Fetch($result)) { $products[] = (int)$row['product']; } // trim the processed data self::discardSession($sessionHash); // only concerned with sessions that viewed more than 1 product if (count($products) > 1) { $job = array( 'sessionId' => $sessionHash, 'viewedProducts' => $products, ); Interspire_TaskManager::createTask('productviews', 'Job_ProductViews_ProcessSession', $job); } }
/** * requeue this listing job so it can process the next batch * * @return mixed result of Interspire_TaskManager::createTask */ protected function _repeatListing() { return Interspire_TaskManager::createTask('ebay', get_class($this), $this->args); }
/** * Queues a new export background job, and stores a handle to the * job's controller accessible via $this->exportTask(). * * @return object A controller handle to the queued export job. */ public function pushExportTask() { $controller = Job_Controller::create($this->getId()); $this->setCurrentExportId($controller->getId()); Interspire_TaskManager::createTask('shoppingcomparison', 'Job_ShoppingComparison_RunExport', array("module" => $this->getId(), "controller" => $controller->getId())); $this->logSuccess(GetLang('ShoppingComparisonLogNewExportJob')); return $controller; }