/** * validates all data for this job, setting up ... * @return bool true if the job can proceed */ protected function _validateExport() { $this->_skip = (int)$this->_getExportData('skip'); $this->_doubleOptin = (int)$this->_getExportData('doubleoptin'); $this->_updateExisting = (int)$this->_getExportData('updateexisting'); // check if export data exists if (!$this->_exportExists()) { $this->_logDebug(GetLang('EmailIntegration_Log_DoesNotExist')); return false; } // check for valid export type $this->_type = $this->_getExportData('type'); switch ($this->_type) { case 'Customer': case 'Order': break; default: $error = GetLang('EmailIntegration_Log_InvalidExportType', array( 'type' => $this->_type, )); $this->_logError($error); $this->_errorExport($error); return false; } // check if the export is pointing to a valid rule $this->_rule = $this->_getExportData('rule'); if (!class_exists('Interspire_EmailIntegration_Rule_' . $this->_rule)) { $error = GetLang('EmailIntegration_Log_InvalidExportRule', array( 'rule' => $this->_rule, )); $this->_logError($error); $this->_errorExport($error); return false; } // check if export is aborted if ((bool)$this->_getExportData('abort')) { $this->_abortExport(); return false; } // parse search parameters $search = $this->_getExportData('search'); if (!$search) { $search = array(); } else { $search = ISC_JSON::decode($search, true); if (!is_array($search)) { $error = GetLang('EmailIntegration_Log_JobInvalidSearchParameters'); $this->_logError($error); $this->_errorExport($error); return false; } if (isset($search['searchId']) && isId($search['searchId'])) { // simulate ISC_ADMIN_CUSTOMERS->CustomSearch if a searchId is specified $GLOBALS['ISC_CLASS_ADMIN_CUSTOMSEARCH'] = new ISC_ADMIN_CUSTOMSEARCH('customers'); $search = $GLOBALS['ISC_CLASS_ADMIN_CUSTOMSEARCH']->LoadSearch($search['searchId']); if (!is_array($search)) { $error = GetLang('EmailIntegration_Log_SearchNotFound'); $this->_logError($error); $this->_errorExport($error); return false; } $search = $search['searchvars']; } } $this->_search = $search; return true; }
/** * validates all data for this job, setting up $this->_module, $this->_list, etc. * @return bool true if the job can proceed */ protected function _validateExport() { $this->_skip = (int)$this->_getExportData('skip'); $this->_doubleOptin = (int)$this->_getExportData('doubleoptin'); $this->_updateExisting = (int)$this->_getExportData('updateexisting'); // check if export data exists if (!$this->_exportExists()) { $this->_logDebug(GetLang('EmailIntegration_Log_DoesNotExist')); return false; } // check for valid export type $this->_type = $this->_getExportData('type'); switch ($this->_type) { case 'Customer': $searchtype = 'customers'; break; case 'Order': $searchtype = 'orders'; break; default: $error = GetLang('EmailIntegration_Log_InvalidExportType', array( 'type' => $this->_type, )); $this->_logError($error); $this->_errorExport($error); return false; } // check if specified module exists $module = $this->_getExportData('module'); GetModuleById('emailintegration', /** @var ISC_EMAILINTEGRATION */$this->_module, $module); if (!$this->_module) { $error = GetLang('EmailIntegration_Log_ModuleNotFound', array( 'module' => $module, )); $this->_logError($error); $this->_errorExport($error); return false; } // check if export is aborted if ((bool)$this->_getExportData('abort')) { $this->_abortExport(); return false; } // check if module is enabled if (!$this->_module->IsEnabled()) { $error = GetLang('EmailIntegration_Log_ModuleNotEnabled', array( 'module' => $this->_module->GetName(), )); $this->_logError($error); $this->_errorExport($error); return false; } // check if module is configured if (!$this->_module->isConfigured()) { $error = GetLang('EmailIntegration_Log_ModuleNotConfigured', array( 'module' => $this->_module->GetName(), )); $this->_logError($error); $this->_errorExport($error); return false; } // check if the destination list exists, at least locally $list = $this->_getExportData('list'); $this->_list = $this->_module->getList($list); if (!$this->_list) { $error = GetLang('EmailIntegration_Log_ListNotFound', array( 'list' => $list, )); $this->_logError($error); $this->_errorExport($error); return false; } // parse field mapping $map = $this->_getExportData('map'); if (!$map) { $map = array(); } else { $map = ISC_JSON::decode($map, true); if (!is_array($map)) { $error = GetLang('EmailIntegration_Log_JobInvalidFieldMapData'); $this->_logError($error); $this->_errorExport($error); return false; } } $this->_map = $map; // parse search parameters $search = $this->_getExportData('search'); if (!$search) { $search = array(); } else { $search = ISC_JSON::decode($search, true); if (!is_array($search)) { $error = GetLang('EmailIntegration_Log_JobInvalidSearchParameters'); $this->_logError($error); $this->_errorExport($error); return false; } if (isset($search['searchId']) && isId($search['searchId'])) { // simulate ISC_ADMIN_CUSTOMERS->CustomSearch if a searchId is specified $GLOBALS['ISC_CLASS_ADMIN_CUSTOMSEARCH'] = new ISC_ADMIN_CUSTOMSEARCH($searchtype); $search = $GLOBALS['ISC_CLASS_ADMIN_CUSTOMSEARCH']->LoadSearch($search['searchId']); if (!is_array($search)) { $error = GetLang('EmailIntegration_Log_SearchNotFound'); $this->_logError($error); $this->_errorExport($error); return false; } $search = $search['searchvars']; } } $this->_search = $search; return true; }
/** * Handle request from settings UI for a field sync form * * @param mixed $auth * @param mixed $data * @return mixed */ public function remoteGetFieldSyncForm($auth, $data) { $template = Interspire_Template::getInstance('admin'); $listId = $data['listId']; if (isset($data['modalContentOnly'])) { $modalContentOnly = (bool)$data['modalContentOnly']; } else { $modalContentOnly = false; } $lists = $this->getLists(); // use this to force a refresh from provider if necessary foreach ($lists as $list) { if ($list['provider_list_id'] == $listId) { $listFields = $this->getListFields($listId); $template->assign('listFields', $listFields); /** @var ISC_FORM */ $form = $GLOBALS['ISC_CLASS_FORM']; if (isset($data['subscriptionType'])) { $subscription = 'Interspire_EmailIntegration_Subscription_' . $data['subscriptionType']; $subscription = new $subscription(); } else { $subscription = new Interspire_EmailIntegration_Subscription_Order(); } $mappings = array(); if (isset($data['map']) && $data['map']) { $map = ISC_JSON::decode($data['map'], true); if (is_array($map)) { foreach ($map as $provider => $local) { $mappings[$provider] = $local; } } } $formFields = $subscription->getSubscriptionFields(); $template->assign('formFields', $formFields); $template->assign('module', $this); $template->assign('mappings', $mappings); break; } } if ($modalContentOnly) { return array( 'success' => true, 'html' => $template->render('emailintegration.fieldsyncform.modalcontent.tpl'), ); } else { $template->display('settings.emailintegration.fieldsyncform.tpl'); die(); } }
/** * call this when the job reaches the end of its data to list * * @return void */ protected function _endListing() { $this->_logDebug('end'); $started = (int)$this->_getListingData('started'); $finished = time(); $replacements = array( 'template' => $this->_getListingData('template_name'), 'success_count' => (int)$this->_getListingData('success_count'), 'error_count' => (int)$this->_getListingData('error_count'), 'warning_count' => (int)$this->_getListingData('warning_count'), 'start' => isc_date(GetConfig('ExtendedDisplayDateFormat'), $started), 'end' => isc_date(GetConfig('ExtendedDisplayDateFormat'), $finished), 'total' => (int)$this->_getListingData('actual_processed'), ); // notify user that started export of completion $obj_email = GetEmailClass(); $obj_email->Set('CharSet', GetConfig('CharacterSet')); $obj_email->From(GetConfig('OrderEmail'), GetConfig('StoreName')); $obj_email->Set("Subject", GetLang("Ebay_Listing_End_Email_Subject", $replacements)); $obj_email->AddRecipient($this->_getListingData('owner:email'), "", "h"); $emailTemplate = FetchEmailTemplateParser(); $emailTemplate->SetTemplate("ebay_listing_finished"); $emailTemplate->Assign('EmailHeader', GetLang("Ebay_Listing_End_Email_Subject", $replacements)); $emailTemplate->Assign('Ebay_Listing_End_Email_Message_1', GetLang('Ebay_Listing_End_Email_Message_1', $replacements)); $emailTemplate->Assign('Ebay_Listing_End_Email_Message_2', GetLang('Ebay_Listing_End_Email_Message_2', $replacements)); $emailTemplate->Assign('Ebay_Listing_End_Email_Message_3', GetLang('Ebay_Listing_End_Email_Message_3', $replacements)); $emailTemplate->Assign('Ebay_Listing_End_Email_Message_4', GetLang('Ebay_Listing_End_Email_Message_4', $replacements)); // process errors if ($replacements['error_count']) { $errors = $this->_keystore->multiGet($this->_prefix . 'error:*'); $errorHTML = ''; $limit = 100; // limit number of errors reported via email to 100 while (!empty($errors) && $limit) { $error = array_pop($errors); $error = ISC_JSON::decode($error, true); if (!$error) { // json decode error? continue; } $errorHTML .= ' <dt>' . $error['prodname'] . '</dt> <dd>' . $error['message'] . '</dd> <br /> '; $limit--; } if ($errorHTML) { $errorHTML = '<dl>' . $errorHTML . '</dl>'; // only show the heading if error info was successfully generated $emailTemplate->Assign('Ebay_Listing_End_Email_Errors_Heading', GetLang('Ebay_Listing_End_Email_Errors_Heading', $replacements)); $emailTemplate->Assign('Ebay_Listing_End_Email_Errors', $errorHTML); } } // process warnings if ($replacements['warning_count']) { $errors = $this->_keystore->multiGet($this->_prefix . 'warning:*'); $errorHTML = ''; $limit = 100; // limit number of warnings reported via email to 100 while (!empty($errors) && $limit) { $error = array_pop($errors); $error = ISC_JSON::decode($error, true); if (!$error) { // json decode error? continue; } $errorHTML .= ' <dt>' . $error['prodname'] . '</dt> <dd>' . $error['message'] . '</dd> <br /> '; $limit--; } if ($errorHTML) { $errorHTML = '<dl>' . $errorHTML . '</dl>'; // only show the heading if error info was successfully generated $emailTemplate->Assign('Ebay_Listing_End_Email_Warnings_Heading', GetLang('Ebay_Listing_End_Email_Warnings_Heading', $replacements)); $emailTemplate->Assign('Ebay_Listing_End_Email_Warnings', $errorHTML); } } $body = $emailTemplate->ParseTemplate(true); $obj_email->AddBody("html", $body); $email_result = $obj_email->Send(); $this->_removeListing(); }
/** * Executes the task described by the provided data, which is typically the return value of getNextTask() * * @param array $task * @return bool True if the task was executed successfully, otherwise false */ public static function executeTask($task) { $class = $task['class']; /** @var mysqldb */ $db = $GLOBALS['ISC_CLASS_DB']; // before running the task, delete it from the queue $db->DeleteQuery('tasks', "WHERE `id` = " . (int)$task['id']); // remove existing status logs to prevent pkey conflict $db->DeleteQuery('task_status', "WHERE id = " . (int)$task['id']); // copy task to status table with only a begin time $status = $task; unset($status['time']); // does not apply to status $status['begin'] = time(); unset($status['reservation']); $db->InsertQuery('task_status', $status); $message = ''; $data = null; if (isset($task['data'])) { if ($task['data'] === JSON_NULL) { $data = null; } else { GetLib('class.json'); $data = ISC_JSON::decode($task['data'], true); if ($data === null) { self::updateTaskStatus($task['id'], false, GetLang('TaskManagerFailedToDecodeJson')); return false; } } } // double-check class exists just incase this task record was not added through createTask if (!class_exists($class)) { $success = false; $message = 'Interspire_TaskManager_InvalidCallbackException'; } else { /** @var Job_Store_Abstract */ $job = new $class($data); $job->setUp(); try { $success = $job->perform(); if ($success === null) { // if the callback produced no return value, assume success $success = true; } $message = ''; } catch (Exception $exception) { $success = false; $message = $exception->__toString(); } $job->tearDown(); } self::updateTaskStatus($task['id'], $success, $message); self::pruneTaskStatus(); return $success; }