本文整理汇总了PHP中CRM_Core_Error::setCallback方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Error::setCallback方法的具体用法?PHP CRM_Core_Error::setCallback怎么用?PHP CRM_Core_Error::setCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Error
的用法示例。
在下文中一共展示了CRM_Core_Error::setCallback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_crmAPI
/**
*/
function smarty_function_crmAPI($params, &$smarty)
{
if (!array_key_exists('action', $params)) {
$params['action'] = "get";
}
if (!array_key_exists('sequential', $params)) {
$params['sequential'] = 1;
}
if (!array_key_exists('entity', $params)) {
$smarty->trigger_error("assign: missing 'entity' parameter");
return "crmAPI: missing 'entity' parameter";
}
CRM_Core_Error::setCallback(array('CRM_Utils_REST', 'fatal'));
$action = $params['action'];
$entity = $params['entity'];
unset($params['entity']);
unset($params['method']);
unset($params['assign']);
$params['version'] = 3;
require_once 'api/api.php';
$result = civicrm_api($entity, $action, $params);
CRM_Core_Error::setCallback();
if ($result === FALSE) {
$smarty->trigger_error("Unkown error");
return;
}
if (!array_key_exists('var', $params)) {
return json_encode($result);
}
if (!empty($params['json'])) {
$smarty->assign($params["var"], json_encode($result));
} else {
$smarty->assign($params["var"], $result);
}
}
示例2: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
//Test database user privilege to create table(Temporary) CRM-4725
CRM_Core_Error::ignoreException();
$daoTestPrivilege = new CRM_Core_DAO();
$daoTestPrivilege->query("CREATE TEMPORARY TABLE import_job_permission_one(test int) ENGINE=InnoDB");
$daoTestPrivilege->query("CREATE TEMPORARY TABLE import_job_permission_two(test int) ENGINE=InnoDB");
$daoTestPrivilege->query("DROP TABLE IF EXISTS import_job_permission_one, import_job_permission_two");
CRM_Core_Error::setCallback();
if ($daoTestPrivilege->_lastError) {
CRM_Core_Error::fatal(ts('Database Configuration Error: Insufficient permissions. Import requires that the CiviCRM database user has permission to create temporary tables. Contact your site administrator for assistance.'));
}
$this->_dataSourceIsValid = false;
$this->_dataSource = CRM_Utils_Request::retrieve('dataSource', 'String', CRM_Core_DAO::$_nullObject);
$this->_params = $this->controller->exportValues($this->_name);
if (!$this->_dataSource) {
//considering dataSource as base criteria instead of hidden_dataSource.
$this->_dataSource = CRM_Utils_Array::value('dataSource', $_POST, CRM_Utils_Array::value('dataSource', $this->_params));
$this->assign('showOnlyDataSourceFormPane', false);
} else {
$this->assign('showOnlyDataSourceFormPane', true);
}
if (strpos($this->_dataSource, 'CRM_Import_DataSource_') === 0) {
$this->_dataSourceIsValid = true;
$this->assign('showDataSourceFormPane', true);
$dataSourcePath = split('_', $this->_dataSource);
$templateFile = "CRM/Import/Form/" . $dataSourcePath[3] . ".tpl";
$this->assign('dataSourceFormTemplateFile', $templateFile);
}
}
示例3: send
static function send($from, $toDisplayName, $toEmail, $subject, $text_message = null, $cc = null, $bcc = null, $replyTo = null, $html_message = null, $attachments = null)
{
require_once 'CRM/Core/BAO/MailSettings.php';
$returnPath = CRM_Core_BAO_MailSettings::defaultReturnPath();
if (!$returnPath) {
$returnPath = self::pluckEmailFromHeader($from);
}
$headers = array();
$headers['From'] = $from;
$headers['To'] = "{$toDisplayName} <{$toEmail}>";
$headers['Cc'] = $cc;
$headers['Subject'] = $subject;
$headers['Content-Type'] = $html_message ? 'multipart/mixed; charset=utf-8' : 'text/plain; charset=utf-8';
$headers['Content-Disposition'] = 'inline';
$headers['Content-Transfer-Encoding'] = '8bit';
$headers['Return-Path'] = $returnPath;
$headers['Reply-To'] = isset($replyTo) ? $replyTo : $from;
$headers['Date'] = date('r');
$to = array($toEmail);
if ($cc) {
$to[] = $cc;
}
if ($bcc) {
$to[] = $bcc;
}
// we need to wrap Mail_mime because PEAR is apparently unable to fix
// a six-year-old bug (PEAR bug #30) in Mail_mime::_encodeHeaders()
// this fixes CRM-4631
require_once 'CRM/Utils/Mail/FixedMailMIME.php';
$msg = new CRM_Utils_Mail_FixedMailMIME("\n");
if ($text_message) {
$msg->setTxtBody($text_message);
}
if ($html_message) {
$msg->setHTMLBody($html_message);
}
if (!empty($attachments)) {
foreach ($attachments as $fileID => $attach) {
$msg->addAttachment($attach['fullPath'], $attach['mime_type'], $attach['cleanName']);
}
}
$message = self::setMimeParams($msg);
$headers =& $msg->headers($headers);
$result = null;
$mailer =& CRM_Core_Config::getMailer();
CRM_Core_Error::ignoreException();
if (is_object($mailer)) {
$result = $mailer->send($to, $headers, $message);
CRM_Core_Error::setCallback();
if (is_a($result, 'PEAR_Error')) {
$message = self::errorMessage($mailer, $result);
CRM_Core_Session::setStatus($message, false);
return false;
}
return true;
}
return false;
}
示例4: smarty_function_crmAPI
/**
*/
function smarty_function_crmAPI($params, &$smarty)
{
// $mandatorypVars = array( 'entity', 'method','assign');
$fnGroup = ucfirst($params['entity']);
if (strpos($fnGroup, '_')) {
$fnGroup = explode('_', $fnGroup);
$fnGroup[1] = ucfirst($fnGroup[1]);
$fnGroup = implode('', $fnGroup);
}
if ($fnGroup == 'Contribution') {
$fnGroup = 'Contribute';
}
$apiFile = "api/v2/{$fnGroup}.php";
require_once $apiFile;
$fnName = "civicrm_{$params['entity']}_{$params['action']}";
if (!function_exists($fnName)) {
$smarty->trigger_error("Unknown function called: {$fnName}");
return;
}
// trap all fatal errors
require_once 'CRM/Utils/REST.php';
CRM_Core_Error::setCallback(array('CRM_Utils_REST', 'fatal'));
unset($params['entity']);
unset($params['method']);
unset($params['assign']);
if (!empty($params['return'])) {
$return = explode(",", $params['return']);
foreach ($return as $r) {
$params["return." . trim($r)] = 1;
}
unset($params['return']);
}
$result = $fnName($params);
CRM_Core_Error::setCallback();
if ($result === false) {
$smarty->trigger_error("Unkown error");
return;
}
if (empty($params['var'])) {
$smarty->trigger_error("assign: missing 'var' parameter");
return;
}
if (!empty($params['json'])) {
$smarty->assign($params["var"], json_encode($result));
} else {
$smarty->assign($params["var"], $result);
}
}
示例5: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
//Test database user privilege to create table(Temporary) CRM-4725
CRM_Core_Error::ignoreException();
$daoTestPrivilege = new CRM_Core_DAO();
$daoTestPrivilege->query("CREATE TEMPORARY TABLE import_job_permission_one(test int) ENGINE=InnoDB");
$daoTestPrivilege->query("CREATE TEMPORARY TABLE import_job_permission_two(test int) ENGINE=InnoDB");
$daoTestPrivilege->query("DROP TABLE IF EXISTS import_job_permission_one, import_job_permission_two");
CRM_Core_Error::setCallback();
if ($daoTestPrivilege->_lastError) {
CRM_Core_Error::fatal(ts('Database Configuration Error: Insufficient permissions. Import requires that the CiviCRM database user has permission to create temporary tables. Contact your site administrator for assistance.'));
}
$results = array();
$config = CRM_Core_Config::singleton();
$handler = opendir($config->uploadDir);
$errorFiles = array('sqlImport.errors', 'sqlImport.conflicts', 'sqlImport.duplicates', 'sqlImport.mismatch');
while ($file = readdir($handler)) {
if ($file != '.' && $file != '..' && in_array($file, $errorFiles) && !is_writable($config->uploadDir . $file)) {
$results[] = $file;
}
}
closedir($handler);
if (!empty($results)) {
CRM_Core_Error::fatal(ts('<b>%1</b> file(s) in %2 directory are not writable. Listed file(s) might be used during the import to log the errors occurred during Import process. Contact your site administrator for assistance.', array(1 => implode(', ', $results), 2 => $config->uploadDir)));
}
$this->_dataSourceIsValid = false;
$this->_dataSource = CRM_Utils_Request::retrieve('dataSource', 'String', CRM_Core_DAO::$_nullObject);
$this->_params = $this->controller->exportValues($this->_name);
if (!$this->_dataSource) {
//considering dataSource as base criteria instead of hidden_dataSource.
$this->_dataSource = CRM_Utils_Array::value('dataSource', $_POST, CRM_Utils_Array::value('dataSource', $this->_params));
$this->assign('showOnlyDataSourceFormPane', false);
} else {
$this->assign('showOnlyDataSourceFormPane', true);
}
if (strpos($this->_dataSource, 'CRM_Import_DataSource_') === 0) {
$this->_dataSourceIsValid = true;
$this->assign('showDataSourceFormPane', true);
$dataSourcePath = explode('_', $this->_dataSource);
$templateFile = "CRM/Import/Form/" . $dataSourcePath[3] . ".tpl";
$this->assign('dataSourceFormTemplateFile', $templateFile);
}
}
示例6: smarty_function_crmSetting
/**
* Retrieve CiviCRM settings from the api for use in templates
*/
function smarty_function_crmSetting($params, &$smarty)
{
CRM_Core_Error::setCallback(array('CRM_Utils_REST', 'fatal'));
unset($params['method']);
unset($params['assign']);
$params['version'] = 3;
require_once 'api/api.php';
$result = civicrm_api('setting', 'getvalue', $params);
CRM_Core_Error::setCallback();
if ($result === FALSE) {
$smarty->trigger_error("Unknown error");
return;
}
if (empty($params['var'])) {
return is_numeric($result) ? $result : json_encode($result);
}
if (!empty($params['json'])) {
$smarty->assign($params["var"], json_encode($result));
} else {
$smarty->assign($params["var"], $result);
}
}
示例7: deliver
/**
* Send the mailing
*
* @param object $mailer A Mail object to send the messages
* @return void
* @access public
*/
function deliver(&$mailer)
{
require_once 'CRM/Mailing/BAO/Mailing.php';
$mailing =& new CRM_Mailing_BAO_Mailing();
$mailing->id = $this->mailing_id;
$mailing->find(true);
$eq =& new CRM_Mailing_Event_BAO_Queue();
$eqTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$emailTable = CRM_Core_BAO_Email::getTableName();
$contactTable = CRM_Contact_BAO_Contact::getTableName();
$edTable = CRM_Mailing_Event_BAO_Delivered::getTableName();
$ebTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
$query = " SELECT {$eqTable}.id,\n {$emailTable}.email as email,\n {$eqTable}.contact_id,\n {$eqTable}.hash\n FROM {$eqTable}\n INNER JOIN {$emailTable}\n ON {$eqTable}.email_id = {$emailTable}.id\n LEFT JOIN {$edTable}\n ON {$eqTable}.id = {$edTable}.event_queue_id\n LEFT JOIN {$ebTable}\n ON {$eqTable}.id = {$ebTable}.event_queue_id\n WHERE {$eqTable}.job_id = " . $this->id . "\n AND {$edTable}.id IS null\n AND {$ebTable}.id IS null";
$eq->query($query);
while ($eq->fetch()) {
/* Compose the mailing */
$recipient = null;
$message = $mailing->compose($this->id, $eq->id, $eq->hash, $eq->contact_id, $eq->email, $recipient);
/* Send the mailing */
$body = $message->get();
$headers = $message->headers();
/* TODO: when we separate the content generator from the delivery
* engine, maybe we should dump the messages into a table */
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP'));
$result = $mailer->send($recipient, $headers, $body);
CRM_Core_Error::setCallback();
$params = array('event_queue_id' => $eq->id, 'job_id' => $this->id, 'hash' => $eq->hash);
if (is_a($result, PEAR_Error)) {
/* Register the bounce event */
require_once 'CRM/Mailing/BAO/BouncePattern.php';
require_once 'CRM/Mailing/Event/BAO/Bounce.php';
$params = array_merge($params, CRM_Mailing_BAO_BouncePattern::match($result->getMessage()));
CRM_Mailing_Event_BAO_Bounce::create($params);
} else {
/* Register the delivery event */
CRM_Mailing_Event_BAO_Delivered::create($params);
}
}
}
示例8: executeUnbufferedQuery
/**
* execute an unbuffered query. This is a wrapper around new functionality
* exposed with CRM-17748.
*
* @param string $query query to be executed
*
* @return Object CRM_Core_DAO object that points to an unbuffered result set
* @static
* @access public
*/
public static function executeUnbufferedQuery($query, $params = array(), $abort = TRUE, $daoName = NULL, $freeDAO = FALSE, $i18nRewrite = TRUE, $trapException = FALSE)
{
$queryStr = self::composeQuery($query, $params, $abort);
//CRM_Core_Error::debug( 'q', $queryStr );
if (!$daoName) {
$dao = new CRM_Core_DAO();
} else {
$dao = new $daoName();
}
if ($trapException) {
CRM_Core_Error::ignoreException();
}
// set the DAO object to use an unbuffered query
$dao->setOptions(array('result_buffering' => 0));
$result = $dao->query($queryStr, $i18nRewrite);
if ($trapException) {
CRM_Core_Error::setCallback();
}
if (is_a($result, 'DB_Error')) {
return $result;
}
// since it is unbuffered, ($dao->N==0) is true. This blocks the standard fetch() mechanism.
$dao->N = TRUE;
if ($freeDAO || preg_match('/^(insert|update|delete|create|drop|replace)/i', $queryStr)) {
// we typically do this for insert/update/delete stataments OR if explicitly asked to
// free the dao
$dao->free();
}
return $dao;
}
示例9: array
static function &dbHandle(&$config)
{
CRM_Core_Error::ignoreException();
$db_uf = DB::connect($config->userFrameworkDSN);
CRM_Core_Error::setCallback();
if (!$db_uf || DB::isError($db_uf)) {
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
CRM_Core_Error::statusBounce(ts("Cannot connect to UF db via %1. Please check the CIVICRM_UF_DSN value in your civicrm.settings.php file", array(1 => $db_uf->getMessage())));
}
$db_uf->query('/*!40101 SET NAMES utf8 */');
return $db_uf;
}
示例10: deliverGroup
public function deliverGroup(&$fields, &$mailing, &$mailer, &$job_date, &$attachments)
{
static $smtpConnectionErrors = 0;
if (!is_object($mailer) || empty($fields)) {
CRM_Core_Error::fatal();
}
// get the return properties
$returnProperties = $mailing->getReturnProperties();
$params = $targetParams = $deliveredParams = array();
$count = 0;
/**
* CRM-15702: Sending bulk sms to contacts without e-mail addres fails.
* Solution is to skip checking for on hold
*/
$skipOnHold = true;
//do include a statement to check wether e-mail address is on hold
if ($mailing->sms_provider_id) {
$skipOnHold = false;
//do not include a statement to check wether e-mail address is on hold
}
foreach ($fields as $key => $field) {
$params[] = $field['contact_id'];
}
$details = CRM_Utils_Token::getTokenDetails($params, $returnProperties, $skipOnHold, TRUE, NULL, $mailing->getFlattenedTokens(), get_class($this), $this->id);
$config = CRM_Core_Config::singleton();
foreach ($fields as $key => $field) {
$contactID = $field['contact_id'];
if (!array_key_exists($contactID, $details[0])) {
$details[0][$contactID] = array();
}
/* Compose the mailing */
$recipient = $replyToEmail = NULL;
$replyValue = strcmp($mailing->replyto_email, $mailing->from_email);
if ($replyValue) {
$replyToEmail = $mailing->replyto_email;
}
$message =& $mailing->compose($this->id, $field['id'], $field['hash'], $field['contact_id'], $field['email'], $recipient, FALSE, $details[0][$contactID], $attachments, FALSE, NULL, $replyToEmail);
if (empty($message)) {
// lets keep the message in the queue
// most likely a permissions related issue with smarty templates
// or a bad contact id? CRM-9833
continue;
}
/* Send the mailing */
$body =& $message->get();
$headers =& $message->headers();
if ($mailing->sms_provider_id) {
$provider = CRM_SMS_Provider::singleton(array('mailing_id' => $mailing->id));
$body = $provider->getMessage($message, $field['contact_id'], $details[0][$contactID]);
$headers = $provider->getRecipientDetails($field, $details[0][$contactID]);
}
// make $recipient actually be the *encoded* header, so as not to baffle Mail_RFC822, CRM-5743
$recipient = $headers['To'];
$result = NULL;
// disable error reporting on real mailings (but leave error reporting for tests), CRM-5744
if ($job_date) {
CRM_Core_Error::ignoreException();
}
$result = $mailer->send($recipient, $headers, $body, $this->id);
if ($job_date) {
CRM_Core_Error::setCallback();
}
if (is_a($result, 'PEAR_Error') && !$mailing->sms_provider_id) {
// CRM-9191
$message = $result->getMessage();
if (strpos($message, 'Failed to write to socket') !== FALSE || strpos($message, 'Failed to set sender') !== FALSE) {
// lets log this message and code
$code = $result->getCode();
CRM_Core_Error::debug_log_message("SMTP Socket Error or failed to set sender error. Message: {$message}, Code: {$code}");
// these are socket write errors which most likely means smtp connection errors
// lets skip them
$smtpConnectionErrors++;
if ($smtpConnectionErrors <= 5) {
continue;
}
// seems like we have too many of them in a row, we should
// write stuff to disk and abort the cron job
$this->writeToDB($deliveredParams, $targetParams, $mailing, $job_date);
CRM_Core_Error::debug_log_message("Too many SMTP Socket Errors. Exiting");
CRM_Utils_System::civiExit();
}
/* Register the bounce event */
$params = array('event_queue_id' => $field['id'], 'job_id' => $this->id, 'hash' => $field['hash']);
$params = array_merge($params, CRM_Mailing_BAO_BouncePattern::match($result->getMessage()));
CRM_Mailing_Event_BAO_Bounce::create($params);
} elseif (is_a($result, 'PEAR_Error') && $mailing->sms_provider_id) {
// Handle SMS errors: CRM-15426
$job_id = intval($this->id);
$mailing_id = intval($mailing->id);
CRM_Core_Error::debug_log_message("Failed to send SMS message. Vars: mailing_id: {$mailing_id}, job_id: {$job_id}. Error message follows.");
CRM_Core_Error::debug_log_message($result->getMessage());
} else {
/* Register the delivery event */
$deliveredParams[] = $field['id'];
$targetParams[] = $field['contact_id'];
$count++;
if ($count % CRM_Core_DAO::BULK_MAIL_INSERT_COUNT == 0) {
$this->writeToDB($deliveredParams, $targetParams, $mailing, $job_date);
$count = 0;
// hack to stop mailing job at run time, CRM-4246.
//.........这里部分代码省略.........
示例11: send_unsub_response
/**
* Send a reponse email informing the contact of the groups from which he
* has been unsubscribed.
*
* @param string $queue_id The queue event ID
* @param array $groups List of group IDs
* @param bool $is_domain Is this domain-level?
* @param int $job The job ID
* @return void
* @access public
* @static
*/
public static function send_unsub_response($queue_id, $groups, $is_domain = false, $job)
{
$config =& CRM_Core_Config::singleton();
$domain =& CRM_Core_BAO_Domain::getDomain();
$jobTable = CRM_Mailing_BAO_Job::getTableName();
$mailingTable = CRM_Mailing_DAO_Mailing::getTableName();
$contacts = CRM_Contact_DAO_Contact::getTableName();
$email = CRM_Core_DAO_Email::getTableName();
$queue = CRM_Mailing_Event_BAO_Queue::getTableName();
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$dao =& new CRM_Mailing_BAO_Mailing();
$dao->query(" SELECT * FROM {$mailingTable} \n INNER JOIN {$jobTable} ON\n {$jobTable}.mailing_id = {$mailingTable}.id \n WHERE {$jobTable}.id = {$job}");
$dao->fetch();
$component =& new CRM_Mailing_BAO_Component();
if ($is_domain) {
$component->id = $dao->optout_id;
} else {
$component->id = $dao->unsubscribe_id;
}
$component->find(true);
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$eq =& new CRM_Core_DAO();
$eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$contacts}.id as contact_id,\n {$email}.email as email,\n {$queue}.hash as hash\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
$eq->fetch();
if ($groups) {
foreach ($groups as $key => $value) {
if (!$value) {
unset($groups[$key]);
}
}
}
$message =& new Mail_Mime("\n");
list($addresses, $urls) = CRM_Mailing_BAO_Mailing::getVerpAndUrls($job, $queue_id, $eq->hash, $eq->email);
$bao =& new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
require_once 'CRM/Utils/Token.php';
if ($eq->format == 'HTML' || $eq->format == 'Both') {
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']);
$html = CRM_Utils_Token::replaceUnsubscribeTokens($html, $domain, $groups, true, $eq->contact_id, $eq->hash);
$html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, true, $tokens['html']);
$html = CRM_Utils_Token::replaceMailingTokens($html, $dao, null, $tokens['html']);
$message->setHTMLBody($html);
}
if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']);
$text = CRM_Utils_Token::replaceUnsubscribeTokens($text, $domain, $groups, false, $eq->contact_id, $eq->hash);
$text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, false, $tokens['text']);
$text = CRM_Utils_Token::replaceMailingTokens($text, $dao, null, $tokens['text']);
$message->setTxtBody($text);
}
require_once 'CRM/Core/BAO/MailSettings.php';
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'To' => $eq->email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
$b =& CRM_Utils_Mail::setMimeParams($message);
$h =& $message->headers($headers);
$mailer =& $config->getMailer();
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
if (is_object($mailer)) {
$mailer->send($eq->email, $h, $b);
CRM_Core_Error::setCallback();
}
}
示例12: columnSpecsOf
/**
* Get an array of columns and their details like DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT for the given table.
*/
private function columnSpecsOf($table)
{
static $columnSpecs = array(), $civiDB = NULL;
if (empty($columnSpecs)) {
if (!$civiDB) {
$dao = new CRM_Contact_DAO_Contact();
$civiDB = $dao->_database;
}
CRM_Core_Error::ignoreException();
// NOTE: W.r.t Performance using one query to find all details and storing in static array is much faster
// than firing query for every given table.
$query = "\nSELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT\nFROM INFORMATION_SCHEMA.COLUMNS\nWHERE table_schema IN ('{$this->db}', '{$civiDB}')";
$dao = CRM_Core_DAO::executeQuery($query);
CRM_Core_Error::setCallback();
if (is_a($dao, 'DB_Error')) {
return array();
}
while ($dao->fetch()) {
if (!array_key_exists($dao->TABLE_NAME, $columnSpecs)) {
$columnSpecs[$dao->TABLE_NAME] = array();
}
$columnSpecs[$dao->TABLE_NAME][$dao->COLUMN_NAME] = array('COLUMN_NAME' => $dao->COLUMN_NAME, 'DATA_TYPE' => $dao->DATA_TYPE, 'IS_NULLABLE' => $dao->IS_NULLABLE, 'COLUMN_DEFAULT' => $dao->COLUMN_DEFAULT);
}
}
return $columnSpecs[$table];
}
示例13: send
//.........这里部分代码省略.........
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$from = CRM_Utils_Array::value('from', $params);
if (!$returnPath) {
$returnPath = self::pluckEmailFromHeader($from);
}
$params['returnPath'] = $returnPath;
// first call the mail alter hook
CRM_Utils_Hook::alterMailParams($params);
// check if any module has aborted mail sending
if (CRM_Utils_Array::value('abortMailSend', $params) || !CRM_Utils_Array::value('toEmail', $params)) {
return FALSE;
}
$textMessage = CRM_Utils_Array::value('text', $params);
$htmlMessage = CRM_Utils_Array::value('html', $params);
$attachments = CRM_Utils_Array::value('attachments', $params);
// CRM-6224
if (trim(CRM_Utils_String::htmlToText($htmlMessage)) == '') {
$htmlMessage = FALSE;
}
$headers = array();
// CRM-10699 support custom email headers
if (CRM_Utils_Array::value('headers', $params)) {
$headers = array_merge($headers, $params['headers']);
}
$headers['From'] = $params['from'];
$headers['To'] = self::formatRFC822Email(CRM_Utils_Array::value('toName', $params), CRM_Utils_Array::value('toEmail', $params), FALSE);
$headers['Cc'] = CRM_Utils_Array::value('cc', $params);
$headers['Bcc'] = CRM_Utils_Array::value('bcc', $params);
$headers['Subject'] = CRM_Utils_Array::value('subject', $params);
$headers['Content-Type'] = $htmlMessage ? 'multipart/mixed; charset=utf-8' : 'text/plain; charset=utf-8';
$headers['Content-Disposition'] = 'inline';
$headers['Content-Transfer-Encoding'] = '8bit';
$headers['Return-Path'] = CRM_Utils_Array::value('returnPath', $params);
// CRM-11295: Omit reply-to headers if empty; this avoids issues with overzealous mailservers
$replyTo = CRM_Utils_Array::value('replyTo', $params, $from);
if (!empty($replyTo)) {
$headers['Reply-To'] = $replyTo;
}
$headers['Date'] = date('r');
if ($includeMessageId) {
$headers['Message-ID'] = '<' . uniqid('civicrm_', TRUE) . "@{$emailDomain}>";
}
if (CRM_Utils_Array::value('autoSubmitted', $params)) {
$headers['Auto-Submitted'] = "Auto-Generated";
}
//make sure we has to have space, CRM-6977
foreach (array('From', 'To', 'Cc', 'Bcc', 'Reply-To', 'Return-Path') as $fld) {
if (isset($headers[$fld])) {
$headers[$fld] = str_replace('"<', '" <', $headers[$fld]);
}
}
// quote FROM, if comma is detected AND is not already quoted. CRM-7053
if (strpos($headers['From'], ',') !== FALSE) {
$from = explode(' <', $headers['From']);
$headers['From'] = self::formatRFC822Email($from[0], substr(trim($from[1]), 0, -1), TRUE);
}
require_once 'Mail/mime.php';
$msg = new Mail_mime("\n");
if ($textMessage) {
$msg->setTxtBody($textMessage);
}
if ($htmlMessage) {
$msg->setHTMLBody($htmlMessage);
}
if (!empty($attachments)) {
foreach ($attachments as $fileID => $attach) {
$msg->addAttachment($attach['fullPath'], $attach['mime_type'], $attach['cleanName']);
}
}
$message = self::setMimeParams($msg);
$headers =& $msg->headers($headers);
$to = array($params['toEmail']);
//get emails from headers, since these are
//combination of name and email addresses.
if (CRM_Utils_Array::value('Cc', $headers)) {
$to[] = CRM_Utils_Array::value('Cc', $headers);
}
if (CRM_Utils_Array::value('Bcc', $headers)) {
$to[] = CRM_Utils_Array::value('Bcc', $headers);
unset($headers['Bcc']);
}
$result = NULL;
$mailer = CRM_Core_Config::getMailer();
CRM_Core_Error::ignoreException();
if (is_object($mailer)) {
$result = $mailer->send($to, $headers, $message);
CRM_Core_Error::setCallback();
if (is_a($result, 'PEAR_Error')) {
$message = self::errorMessage($mailer, $result);
// append error message in case multiple calls are being made to
// this method in the course of sending a batch of messages.
CRM_Core_Session::setStatus($message, TRUE);
return FALSE;
}
// CRM-10699
CRM_Utils_Hook::postEmailSend($params);
return TRUE;
}
return FALSE;
}
示例14: sendReminder
static function sendReminder($contactId, $email, $messageTemplateID, $from)
{
require_once "CRM/Core/BAO/Domain.php";
require_once "CRM/Utils/String.php";
require_once "CRM/Utils/Token.php";
$messageTemplates =& new CRM_Core_DAO_MessageTemplates();
$messageTemplates->id = $messageTemplateID;
$domain = CRM_Core_BAO_Domain::getDomain();
$result = null;
if ($messageTemplates->find(true)) {
$body_text = $messageTemplates->msg_text;
$body_html = $messageTemplates->msg_html;
$body_subject = $messageTemplates->msg_subject;
if (!$body_text) {
$body_text = CRM_Utils_String::htmlToText($body_html);
}
$params = array('contact_id' => $contactId);
require_once 'api/v2/Contact.php';
$contact =& civicrm_contact_get($params);
//CRM-4524
$contact = reset($contact);
if (!$contact || is_a($contact, 'CRM_Core_Error')) {
return null;
}
$type = array('html', 'text');
foreach ($type as $key => $value) {
require_once 'CRM/Mailing/BAO/Mailing.php';
$dummy_mail = new CRM_Mailing_BAO_Mailing();
$bodyType = "body_{$value}";
$dummy_mail->{$bodyType} = ${$bodyType};
$tokens = $dummy_mail->getTokens();
if (${$bodyType}) {
${$bodyType} = CRM_Utils_Token::replaceDomainTokens(${$bodyType}, $domain, true, $tokens[$value]);
${$bodyType} = CRM_Utils_Token::replaceContactTokens(${$bodyType}, $contact, false, $tokens[$value]);
}
}
$html = $body_html;
$text = $body_text;
$message =& new Mail_Mime("\n");
/* Do contact-specific token replacement in text mode, and add to the
* message if necessary */
if (!$html || $contact['preferred_mail_format'] == 'Text' || $contact['preferred_mail_format'] == 'Both') {
// render the & entities in text mode, so that the links work
$text = str_replace('&', '&', $text);
$message->setTxtBody($text);
unset($text);
}
if ($html && ($contact['preferred_mail_format'] == 'HTML' || $contact['preferred_mail_format'] == 'Both')) {
$message->setHTMLBody($html);
unset($html);
}
$recipient = "\"{$contact['display_name']}\" <{$email}>";
$matches = array();
preg_match_all('/(?<!\\{|\\\\)\\{(\\w+\\.\\w+)\\}(?!\\})/', $body_subject, $matches, PREG_PATTERN_ORDER);
$subjectToken = null;
if ($matches[1]) {
foreach ($matches[1] as $token) {
list($type, $name) = split('\\.', $token, 2);
if ($name) {
if (!isset($subjectToken['contact'])) {
$subjectToken['contact'] = array();
}
$subjectToken['contact'][] = $name;
}
}
}
$messageSubject = CRM_Utils_Token::replaceContactTokens($body_subject, $contact, false, $subjectToken);
$headers = array('From' => $from, 'Subject' => $messageSubject);
$headers['To'] = $recipient;
$mailMimeParams = array('text_encoding' => '8bit', 'html_encoding' => '8bit', 'head_charset' => 'utf-8', 'text_charset' => 'utf-8', 'html_charset' => 'utf-8');
$message->get($mailMimeParams);
$message->headers($headers);
$config =& CRM_Core_Config::singleton();
$mailer =& $config->getMailer();
$body = $message->get();
$headers = $message->headers();
CRM_Core_Error::ignoreException();
$result = $mailer->send($recipient, $headers, $body);
CRM_Core_Error::setCallback();
}
return $result;
}
示例15: array
/**
* Singleton function used to manage this object.
*
* @param $loadFromDB boolean whether to load from the database
* @param $force boolean whether to force a reconstruction
*
* @return object
* @static
*/
static function &singleton($loadFromDB = TRUE, $force = FALSE)
{
if (self::$_singleton === NULL || $force) {
// goto a simple error handler
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK;
$GLOBALS['_PEAR_default_error_options'] = array('CRM_Core_Error', 'simpleHandler');
// lets ensure we set E_DEPRECATED to minimize errors
// CRM-6327
if (defined('E_DEPRECATED')) {
error_reporting(error_reporting() & ~E_DEPRECATED);
}
// first, attempt to get configuration object from cache
$cache = CRM_Utils_Cache::singleton();
self::$_singleton = $cache->get('CRM_Core_Config' . CRM_Core_Config::domainID());
// if not in cache, fire off config construction
if (!self::$_singleton) {
self::$_singleton = new CRM_Core_Config();
self::$_singleton->_initialize($loadFromDB);
//initialize variables. for gencode we cannot load from the
//db since the db might not be initialized
if ($loadFromDB) {
// initialize stuff from the settings file
self::$_singleton->setCoreVariables();
self::$_singleton->_initVariables();
// I dont think we need to do this twice
// however just keeping this commented for now in 4.4
// in case we hit any issues - CRM-13064
// We can safely delete this once we release 4.4.4
// self::$_singleton->setCoreVariables();
}
$cache->set('CRM_Core_Config' . CRM_Core_Config::domainID(), self::$_singleton);
} else {
// we retrieve the object from memcache, so we now initialize the objects
self::$_singleton->_initialize($loadFromDB);
// CRM-9803, NYSS-4822
// this causes various settings to be reset and hence we should
// only use the config object that we retrived from memcache
}
self::$_singleton->initialized = 1;
if (isset(self::$_singleton->customPHPPathDir) && self::$_singleton->customPHPPathDir) {
$include_path = self::$_singleton->customPHPPathDir . PATH_SEPARATOR . get_include_path();
set_include_path($include_path);
}
// set the callback at the very very end, to avoid an infinite loop
// set the error callback
CRM_Core_Error::setCallback();
// call the hook so other modules can add to the config
// again doing this at the very very end
CRM_Utils_Hook::config(self::$_singleton);
// make sure session is always initialised
$session = CRM_Core_Session::singleton();
// for logging purposes, pass the userID to the db
$userID = $session->get('userID');
if ($userID) {
CRM_Core_DAO::executeQuery('SET @civicrm_user_id = %1', array(1 => array($userID, 'Integer')));
}
// initialize authentication source
self::$_singleton->initAuthSrc();
}
return self::$_singleton;
}