Exemplo n.º 1
0
	/**
	* call this when the job reaches the end of its data to export
	*
	* @return void
	*/
	protected function _endExport()
	{
		$this->_logDebug('end');

		$started = (int)$this->_getExportData('started');
		$finished = time();

		$replacements = array(
			'type' => $this->_type,
			'success_count' => (int)$this->_getExportData('success_count'),
			'error_count' => (int)$this->_getExportData('error_count'),
			'start' => isc_date(GetConfig('ExtendedDisplayDateFormat'), $started),
			'end' => isc_date(GetConfig('ExtendedDisplayDateFormat'), $finished),
		);

		$replacements['total'] = $replacements['success_count'] + $replacements['error_count'];

		// 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("EmailIntegration_Export_End_Email_Subject", $replacements));
		$obj_email->AddRecipient($this->_getExportData('owner:email'), "", "h");

		$GLOBALS['EmailHeader'] = GetLang("EmailIntegration_Export_End_Email_Subject", $replacements);

		$GLOBALS['EmailIntegration_Export_End_Email_Message_1'] = GetLang('EmailIntegration_Export_End_Email_Message_1', $replacements);
		$GLOBALS['EmailIntegration_Export_End_Email_Message_2'] = GetLang('EmailIntegration_Export_End_Email_Message_2', $replacements);
		$GLOBALS['EmailIntegration_Export_End_Email_Message_3'] = GetLang('EmailIntegration_Export_End_Email_Message_3', $replacements);
		$GLOBALS['EmailIntegration_Export_End_Email_Message_4'] = GetLang('EmailIntegration_Export_End_Email_Message_4', $replacements);

		if ($replacements['error_count']) {
			$GLOBALS['EmailIntegration_Export_End_Email_Errors_Heading'] = GetLang('EmailIntegration_Export_End_Email_Errors_Heading', $replacements);

			$dl = new Xhtml_Dl();

			$errors = $this->_keystore->multiGet($this->_prefix . 'error:*');
			while ($error = array_shift($errors)) {
				$error = ISC_JSON::decode($error, true);
				$dl->appendChild(new Xhtml_Dt($error['row']['EMAIL']));

				$dd = new Xhtml_Dd($error['message']);
				$dd->attribute('style', 'margin-bottom:0.8em;');

				$dl->appendChild($dd);
			}

			$GLOBALS['EmailIntegration_Export_End_Email_Errors'] = $dl->render();
			unset($dl);
		}

		$emailTemplate = FetchEmailTemplateParser();
		$emailTemplate->SetTemplate("email_integration_export_finished");
		$message = $emailTemplate->ParseTemplate(true);

		$obj_email->AddBody("html", $message);
		$email_result = $obj_email->Send();

		$this->_removeExport();
	}
Exemplo n.º 2
0
	/**
	* call this when the job reaches the end of its data to export
	*
	* @return void
	*/
	protected function _endExport()
	{
		$this->_logDebug('end');

		$started = (int)$this->_getExportData('started');
		$finished = time();

		$replacements = array(
			'type' => $this->_type,
			'module' => $this->_module->GetName(),
			'success_count' => (int)$this->_getExportData('success_count'),
			'error_count' => (int)$this->_getExportData('error_count'),
			'start' => isc_date(GetConfig('ExtendedDisplayDateFormat'), $started),
			'end' => isc_date(GetConfig('ExtendedDisplayDateFormat'), $finished),
			'total' => (int)$this->_getExportData('skip'),
		);

		// 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("EmailIntegration_Export_End_Email_Subject", $replacements));
		$obj_email->AddRecipient($this->_getExportData('owner:email'), "", "h");

		$GLOBALS['EmailHeader'] = GetLang("EmailIntegration_Export_End_Email_Subject", $replacements);

		$GLOBALS['EmailIntegration_Export_End_Email_Message_1'] = GetLang('EmailIntegration_Export_End_Email_Message_1', $replacements);
		$GLOBALS['EmailIntegration_Export_End_Email_Message_2'] = GetLang('EmailIntegration_Export_End_Email_Message_2', $replacements);
		$GLOBALS['EmailIntegration_Export_End_Email_Message_3'] = GetLang('EmailIntegration_Export_End_Email_Message_3', $replacements);
		$GLOBALS['EmailIntegration_Export_End_Email_Message_4'] = GetLang('EmailIntegration_Export_End_Email_Message_4', $replacements);

		if ($replacements['error_count']) {
			$dl = new Xhtml_Dl();

			$errors = $this->_keystore->multiGet($this->_prefix . 'error:*');

			$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;
				}

				$dl->appendChild(new Xhtml_Dt($error['email']));

				$dd = new Xhtml_Dd($error['message']);
				$dd->attribute('style', 'margin-bottom:0.8em;');

				$dl->appendChild($dd);
				$limit--;
			}

			$GLOBALS['EmailIntegration_Export_End_Email_Errors'] = $dl->render();

			if ($GLOBALS['EmailIntegration_Export_End_Email_Errors']) {
				// only show the heading if error info was successfully generated
				$GLOBALS['EmailIntegration_Export_End_Email_Errors_Heading'] = GetLang('EmailIntegration_Export_End_Email_Errors_Heading', $replacements);
			}

			unset($dl);
		}

		$emailTemplate = FetchEmailTemplateParser();
		$emailTemplate->SetTemplate("email_integration_export_finished");
		$message = $emailTemplate->ParseTemplate(true);

		$obj_email->AddBody("html", $message);
		$email_result = $obj_email->Send();

		$this->_removeExport();
	}