本文整理汇总了PHP中CRM_Mailing_Event_BAO_Queue::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Mailing_Event_BAO_Queue::create方法的具体用法?PHP CRM_Mailing_Event_BAO_Queue::create怎么用?PHP CRM_Mailing_Event_BAO_Queue::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Mailing_Event_BAO_Queue
的用法示例。
在下文中一共展示了CRM_Mailing_Event_BAO_Queue::create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recordBounce
static function recordBounce($params)
{
$isSpam = CRM_Utils_Array::value('is_spam', $params);
$mailingId = CRM_Utils_Array::value('mailing_id', $params);
//CiviCRM mailling ID
$contactId = CRM_Utils_Array::value('contact_id', $params);
$emailId = CRM_Utils_Array::value('email_id', $params);
$email = CRM_Utils_Array::value('email', $params);
$jobId = CRM_Utils_Array::value('job_id', $params);
$eqParams = array('job_id' => $jobId, 'contact_id' => $contactId, 'email_id' => $emailId);
$eventQueue = CRM_Mailing_Event_BAO_Queue::create($eqParams);
$time = date('YmdHis', CRM_Utils_Array::value('date_ts', $params));
$bounceType = array();
CRM_Core_PseudoConstant::populate($bounceType, 'CRM_Mailing_DAO_BounceType', TRUE, 'id', NULL, NULL, NULL, 'name');
$bounce = new CRM_Mailing_Event_BAO_Bounce();
$bounce->time_stamp = $time;
$bounce->event_queue_id = $eventQueue->id;
if ($isSpam) {
$bounce->bounce_type_id = $bounceType[CRM_Mailjet_Upgrader::SPAM];
$bounce->bounce_reason = CRM_Utils_Array::value('source', $params);
//bounce reason when spam occured
} else {
$hardBounce = CRM_Utils_Array::value('hard_bounce', $params);
$blocked = CRM_Utils_Array::value('blocked', $params);
// blocked : true if this bounce leads to recipient being blocked
if ($hardBounce && $blocked) {
$bounce->bounce_type_id = $bounceType[CRM_Mailjet_Upgrader::BLOCKED];
} elseif ($hardBounce && !$blocked) {
$bounce->bounce_type_id = $bounceType[CRM_Mailjet_Upgrader::HARD_BOUNCE];
} else {
$bounce->bounce_type_id = $bounceType[CRM_Mailjet_Upgrader::SOFT_BOUNCE];
}
$bounce->bounce_reason = $params['error_related_to'] . " - " . $params['error'];
}
$bounce->save();
if ($bounce->bounce_type_id != $bounceType[CRM_Mailjet_Upgrader::SOFT_BOUNCE]) {
$params = array('id' => $contactId, 'do_not_email' => 1);
civicrm_api3('Contact', 'create', $params);
}
return TRUE;
}
示例2: testMail
/**
* Form rule to send out a test mailing.
*
* @param aray $testParams
* @param array $files
* Any files posted to the form.
* @param array $self
* An current this object.
*
* @return bool
* true on successful SMTP handoff
*/
public static function testMail($testParams, $files, $self)
{
$error = NULL;
$urlString = 'civicrm/mailing/send';
$urlParams = "_qf_Test_display=true&qfKey={$testParams['qfKey']}";
$ssID = $self->get('ssID');
if ($ssID && $self->_searchBasedMailing) {
if ($self->_action == CRM_Core_Action::BASIC) {
$fragment = 'search';
} elseif ($self->_action == CRM_Core_Action::PROFILE) {
$fragment = 'search/builder';
} elseif ($self->_action == CRM_Core_Action::ADVANCED) {
$fragment = 'search/advanced';
} else {
$fragment = 'search/custom';
}
$urlString = 'civicrm/contact/' . $fragment;
}
$emails = NULL;
if (!empty($testParams['sendtest'])) {
if (!($testParams['test_group'] || $testParams['test_email'])) {
CRM_Core_Session::setStatus(ts('You did not provide an email address or select a group.'), ts('Test not sent.'), 'error');
$error = TRUE;
}
if ($testParams['test_email']) {
$emailAdd = explode(',', $testParams['test_email']);
foreach ($emailAdd as $key => $value) {
$email = trim($value);
$testParams['emails'][] = $email;
$emails .= ($emails ? ',' : '') . "'" . CRM_Core_DAO::escapeString($email) . "'";
if (!CRM_Utils_Rule::email($email)) {
CRM_Core_Session::setStatus(ts('Please enter a valid email address.'), ts('Test not sent.'), 'error');
$error = TRUE;
}
}
}
if ($error) {
$url = CRM_Utils_System::url($urlString, $urlParams);
CRM_Utils_System::redirect($url);
return $error;
}
}
if (!empty($testParams['_qf_Test_submit'])) {
//when user perform mailing from search context
//redirect it to search result CRM-3711.
if ($ssID && $self->_searchBasedMailing) {
$draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
$status = ts("You can continue later by clicking the 'Continue' action to resume working on it.<br />From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
//replace user context to search.
$context = $self->get('context');
if (!CRM_Contact_Form_Search::isSearchContext($context)) {
$context = 'search';
}
$urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}&qfKey={$testParams['qfKey']}";
$url = CRM_Utils_System::url($urlString, $urlParams);
} else {
$status = ts("Click the 'Continue' action to resume working on it.");
$url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
}
CRM_Core_Session::setStatus($status, ts('Mailing Saved'), 'success');
CRM_Utils_System::redirect($url);
}
if (CRM_Mailing_Info::workflowEnabled()) {
if (!CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings')) {
$url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
CRM_Utils_System::redirect($url);
}
}
if (!empty($testParams['_qf_Test_next']) && $self->get('count') <= 0) {
return array('_qf_default' => ts("You can not schedule or send this mailing because there are currently no recipients selected. Click 'Previous' to return to the Select Recipients step, OR click 'Save & Continue Later'."));
}
if (!empty($_POST['_qf_Import_refresh']) || !empty($testParams['_qf_Test_next']) || empty($testParams['sendtest'])) {
$error = TRUE;
return $error;
}
$job = new CRM_Mailing_BAO_MailingJob();
$job->mailing_id = $self->get('mailing_id');
$job->is_test = TRUE;
$job->save();
$newEmails = NULL;
$session = CRM_Core_Session::singleton();
if (!empty($testParams['emails'])) {
$query = "\nSELECT e.id, e.contact_id, e.email\nFROM civicrm_email e\nINNER JOIN civicrm_contact c ON e.contact_id = c.id\nWHERE e.email IN ({$emails})\nAND e.on_hold = 0\nAND c.is_opt_out = 0\nAND c.do_not_email = 0\nAND c.is_deleted = 0\nAND c.is_deceased = 0\nGROUP BY e.id\nORDER BY e.is_bulkmail DESC, e.is_primary DESC\n";
$dao = CRM_Core_DAO::executeQuery($query);
$emailDetail = array();
// fetch contact_id and email id for all existing emails
while ($dao->fetch()) {
$emailDetail[$dao->email] = array('contact_id' => $dao->contact_id, 'email_id' => $dao->id);
//.........这里部分代码省略.........
示例3: CRM_Core_Dao
/**
* Create a new forward event, create a new contact if necessary
*/
static function &forward($job_id, $queue_id, $hash, $forward_email, $fromEmail = null, $comment = null)
{
$q =& CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
$successfulForward = false;
if (!$q) {
return $successfulForward;
}
/* Find the email address/contact, if it exists */
$contact = CRM_Contact_BAO_Contact::getTableName();
$location = CRM_Core_BAO_Location::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$queueTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$job = CRM_Mailing_BAO_Job::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$forward = self::getTableName();
$domain =& CRM_Core_BAO_Domain::getDomain();
$dao =& new CRM_Core_Dao();
$dao->query("\n SELECT {$contact}.id as contact_id,\n {$email}.id as email_id,\n {$contact}.do_not_email as do_not_email,\n {$queueTable}.id as queue_id\n FROM ({$email}, {$job} as temp_job)\n INNER JOIN {$contact}\n ON {$email}.contact_id = {$contact}.id\n LEFT JOIN {$queueTable}\n ON {$email}.id = {$queueTable}.email_id\n LEFT JOIN {$job}\n ON {$queueTable}.job_id = {$job}.id\n AND temp_job.mailing_id = {$job}.mailing_id\n WHERE {$queueTable}.job_id = {$job_id}\n AND {$email}.email = '" . CRM_Utils_Type::escape($forward_email, 'String') . "'");
$dao->fetch();
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
if (isset($dao->queue_id) || $dao->do_not_email == 1) {
/* We already sent this mailing to $forward_email, or we should
* never email this contact. Give up. */
return $successfulForward;
}
require_once 'api/v2/Contact.php';
$contact_params = array('email' => $forward_email);
$count = civicrm_contact_search_count($contact_params);
if ($count == 0) {
require_once 'CRM/Core/BAO/LocationType.php';
/* If the contact does not exist, create one. */
$formatted = array('contact_type' => 'Individual');
$locationType = CRM_Core_BAO_LocationType::getDefault();
$value = array('email' => $forward_email, 'location_type_id' => $locationType->id);
_civicrm_add_formatted_param($value, $formatted);
require_once 'CRM/Import/Parser.php';
$formatted['onDuplicate'] = CRM_Import_Parser::DUPLICATE_SKIP;
$formatted['fixAddress'] = true;
$contact =& civicrm_contact_format_create($formatted);
if (civicrm_error($contact, CRM_Core_Error)) {
return $successfulForward;
}
$contact_id = $contact['id'];
}
$email =& new CRM_Core_DAO_Email();
$email->email = $forward_email;
$email->find(true);
$email_id = $email->id;
if (!$contact_id) {
$contact_id = $email->contact_id;
}
/* Create a new queue event */
$queue_params = array('email_id' => $email_id, 'contact_id' => $contact_id, 'job_id' => $job_id);
$queue =& CRM_Mailing_Event_BAO_Queue::create($queue_params);
$forward =& new CRM_Mailing_Event_BAO_Forward();
$forward->time_stamp = date('YmdHis');
$forward->event_queue_id = $queue_id;
$forward->dest_queue_id = $queue->id;
$forward->save();
$dao->reset();
$dao->query(" SELECT {$job}.mailing_id as mailing_id \n FROM {$job}\n WHERE {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'));
$dao->fetch();
$mailing_obj =& new CRM_Mailing_BAO_Mailing();
$mailing_obj->id = $dao->mailing_id;
$mailing_obj->find(true);
$config =& CRM_Core_Config::singleton();
$mailer =& $config->getMailer();
$recipient = null;
$attachments = null;
$message =& $mailing_obj->compose($job_id, $queue->id, $queue->hash, $queue->contact_id, $forward_email, $recipient, false, null, $attachments, true, $fromEmail);
//append comment if added while forwarding.
if (count($comment)) {
$message->_txtbody = $comment['body_text'] . $message->_txtbody;
if (CRM_Utils_Array::value('body_html', $comment)) {
$message->_htmlbody = $comment['body_html'] . '<br />---------------Original message---------------------<br />' . $message->_htmlbody;
}
}
$body = $message->get();
$headers = $message->headers();
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
$result = null;
if (is_object($mailer)) {
$result = $mailer->send($recipient, $headers, $body);
CRM_Core_Error::setCallback();
}
$params = array('event_queue_id' => $queue->id, 'job_id' => $job_id, 'hash' => $queue->hash);
if (is_a($result, PEAR_Error)) {
/* Register the bounce event */
$params = array_merge($params, CRM_Mailing_BAO_BouncePattern::match($result->getMessage()));
CRM_Mailing_Event_BAO_Bounce::create($params);
} else {
$successfulForward = true;
/* Register the delivery event */
CRM_Mailing_Event_BAO_Delivered::create($params);
}
$transaction->commit();
//.........这里部分代码省略.........
示例4: getTestRecipients
/**
* Generate an event queue for a test job.
*
* @param array $testParams
* Contains form values.
*
* @return void
*/
public function getTestRecipients($testParams)
{
if (array_key_exists($testParams['test_group'], CRM_Core_PseudoConstant::group())) {
$contacts = civicrm_api('contact', 'get', array('version' => 3, 'group' => $testParams['test_group'], 'return' => 'id', 'options' => array('limit' => 100000000000.0)));
foreach (array_keys($contacts['values']) as $groupContact) {
$query = "\nSELECT civicrm_email.id AS email_id,\n civicrm_email.is_primary as is_primary,\n civicrm_email.is_bulkmail as is_bulkmail\nFROM civicrm_email\nINNER JOIN civicrm_contact ON civicrm_email.contact_id = civicrm_contact.id\nWHERE (civicrm_email.is_bulkmail = 1 OR civicrm_email.is_primary = 1)\nAND civicrm_contact.id = {$groupContact}\nAND civicrm_contact.do_not_email = 0\nAND civicrm_contact.is_deceased <> 1\nAND civicrm_email.on_hold = 0\nAND civicrm_contact.is_opt_out = 0\nGROUP BY civicrm_email.id\nORDER BY civicrm_email.is_bulkmail DESC\n";
$dao = CRM_Core_DAO::executeQuery($query);
if ($dao->fetch()) {
$params = array('job_id' => $testParams['job_id'], 'email_id' => $dao->email_id, 'contact_id' => $groupContact);
CRM_Mailing_Event_BAO_Queue::create($params);
}
}
}
}
示例5: sendTestEmailToIndividuals
/**
* @param $mailingId
* @param $emails
*
* @return CRM_Mailing_BAO_MailingJob
*/
protected static function sendTestEmailToIndividuals($mailingId, $emails)
{
$job = static::createTestMailingJob($mailingId);
$emailArr = explode(',', $emails);
array_walk($emailArr, function (&$email) {
$email = trim($email);
});
$emailStr = implode(', ', array_map(function ($email) {
return '\'' . $email . '\'';
}, $emailArr));
$query = "\n SELECT e.id, e.contact_id, e.email\n FROM civicrm_email e\n\n INNER JOIN civicrm_contact c ON e.contact_id = c.id\n\n WHERE e.email IN ({$emailStr})\n AND e.on_hold = 0\n AND c.is_opt_out = 0\n AND c.do_not_email = 0\n AND c.is_deceased = 0\n\n GROUP BY e.id\n ORDER BY e.is_bulkmail DESC, e.is_primary DESC\n ";
$dao = CRM_Core_DAO::executeQuery($query);
$emailDetail = array();
// fetch contact_id and email id for all existing emails
while ($dao->fetch()) {
$emailDetail[$dao->email] = array('contact_id' => $dao->contact_id, 'email_id' => $dao->id);
}
$dao->free();
foreach ($emailArr as $email) {
$email = trim($email);
$contactId = $emailId = NULL;
if (array_key_exists($email, $emailDetail)) {
$emailId = $emailDetail[$email]['email_id'];
$contactId = $emailDetail[$email]['contact_id'];
}
if (!$contactId) {
//create new contact.
$createParams = array('contact_type' => 'Individual', 'email' => array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => 1)));
$contact = CRM_Contact_BAO_Contact::create($createParams);
$emailId = $contact->email[0]->id;
$contactId = $contact->id;
$contact->free();
}
$queueParams = array('job_id' => $job->id, 'email_id' => $emailId, 'contact_id' => $contactId);
CRM_Mailing_Event_BAO_Queue::create($queueParams);
}
static::runTestEmailJobs($job);
return $job;
}
示例6: queue
/**
* Queue recipients of a job.
*
* @return void
* @access public
*/
function queue()
{
require_once 'CRM/Mailing/BAO/Mailing.php';
$mailing =& new CRM_Mailing_BAO_Mailing();
$mailing->id = $this->mailing_id;
if ($this->is_retry) {
$recipients =& $mailing->retryRecipients($this->id);
} else {
$recipients =& $mailing->getRecipients($this->id);
}
// foreach ($recipients as $recipient) {
while ($recipients->fetch()) {
$params = array('job_id' => $this->id, 'email_id' => $recipients->email_id, 'contact_id' => $recipients->contact_id);
CRM_Mailing_Event_BAO_Queue::create($params);
}
}
示例7: processMandrillCalls
public static function processMandrillCalls($reponse)
{
$events = array('open', 'click', 'hard_bounce', 'soft_bounce', 'spam', 'reject');
$bounceType = array();
//MTE-17
$config = CRM_Core_Config::singleton();
if (property_exists($config, 'civiVersion')) {
$civiVersion = $config->civiVersion;
} else {
$civiVersion = CRM_Core_BAO_Domain::version();
}
if (version_compare('4.4alpha1', $civiVersion) > 0) {
$jobCLassName = 'CRM_Mailing_DAO_Job';
} else {
$jobCLassName = 'CRM_Mailing_DAO_MailingJob';
}
foreach ($reponse as $value) {
//changes done to check if email exists in response array
if (in_array($value['event'], $events) && CRM_Utils_Array::value('email', $value['msg'])) {
$metaData = CRM_Utils_Array::value('metadata', $value['msg']) ? CRM_Utils_Array::value('CiviCRM_Mandrill_id', $value['msg']['metadata']) : NULL;
$header = self::extractHeader($metaData);
$mail = self::getMailing($header, $jobCLassName);
$contacts = array();
if ($mail->find(TRUE)) {
if ($value['event'] == 'click' && $mail->url_tracking === FALSE || $value['event'] == 'open' && $mail->open_tracking === FALSE) {
continue;
}
$emails = self::retrieveEmailContactId($value['msg']['email']);
if (!CRM_Utils_Array::value('contact_id', $emails['email'])) {
continue;
}
$value['mailing_id'] = $mail->id;
// IF no activity id in header then create new activity
if (empty($header[0])) {
self::createActivity($value, NULL, $header);
}
if (empty($header[2])) {
$params = array('job_id' => CRM_Core_DAO::getFieldValue($jobCLassName, $mail->id, 'id', 'mailing_id'), 'contact_id' => $emails['email']['contact_id'], 'email_id' => $emails['email']['id']);
$eventQueue = CRM_Mailing_Event_BAO_Queue::create($params);
$eventQueueID = $eventQueue->id;
$hash = $eventQueue->hash;
$jobId = $params['job_id'];
} else {
$eventQueueID = $header[3];
$hash = explode('@', $header[4]);
$hash = $hash[0];
$jobId = $header[2];
}
if ($eventQueueID) {
$mandrillActivtyParams = array('mailing_queue_id' => $eventQueueID, 'activity_id' => $header[0]);
CRM_Mte_BAO_MandrillActivity::create($mandrillActivtyParams);
}
$msgBody = '';
if (!empty($header[0])) {
$msgBody = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $header[0], 'details');
}
$value['mail_body'] = $msgBody;
$bType = ucfirst(preg_replace('/_\\w+/', '', $value['event']));
$assignedContacts = array();
switch ($value['event']) {
case 'open':
$oe = new CRM_Mailing_Event_BAO_Opened();
$oe->event_queue_id = $eventQueueID;
$oe->time_stamp = date('YmdHis', $value['ts']);
$oe->save();
break;
case 'click':
if (CRM_Utils_Array::value(1, $header) == 'b') {
break;
}
$tracker = new CRM_Mailing_BAO_TrackableURL();
$tracker->url = $value['url'];
$tracker->mailing_id = $mail->id;
if (!$tracker->find(TRUE)) {
$tracker->save();
}
$open = new CRM_Mailing_Event_BAO_TrackableURLOpen();
$open->event_queue_id = $eventQueueID;
$open->trackable_url_id = $tracker->id;
$open->time_stamp = date('YmdHis', $value['ts']);
$open->save();
break;
case 'hard_bounce':
case 'soft_bounce':
case 'spam':
case 'reject':
if (empty($bounceType)) {
CRM_Core_PseudoConstant::populate($bounceType, 'CRM_Mailing_DAO_BounceType', TRUE, 'id', NULL, NULL, NULL, 'name');
}
//Delete queue in delivered since this email is not successfull
$delivered = new CRM_Mailing_Event_BAO_Delivered();
$delivered->event_queue_id = $eventQueueID;
if ($delivered->find(TRUE)) {
$delivered->delete();
}
$bounceParams = array('time_stamp' => date('YmdHis', $value['ts']), 'event_queue_id' => $eventQueueID, 'bounce_type_id' => $bounceType["Mandrill {$bType}"], 'job_id' => $jobId, 'hash' => $hash);
$bounceParams['bounce_reason'] = CRM_Utils_Array::value('bounce_description', $value['msg']);
if (empty($bounceParams['bounce_reason'])) {
$bounceParams['bounce_reason'] = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_BounceType', $bounceType["Mandrill {$bType}"], 'description');
}
//.........这里部分代码省略.........
示例8: getTestRecipients
/**
* Generate an event queue for a test job
*
* @params array $params contains form values
*
* @return void
* @access public
*/
public function getTestRecipients($testParams)
{
if (array_key_exists($testParams['test_group'], CRM_Core_PseudoConstant::group())) {
$group = new CRM_Contact_DAO_Group();
$group->id = $testParams['test_group'];
$contacts = CRM_Contact_BAO_GroupContact::getGroupContacts($group);
foreach ($contacts as $contact) {
$query = "SELECT DISTINCT civicrm_email.id AS email_id, civicrm_email.is_primary as is_primary,\n civicrm_email.is_bulkmail as is_bulkmail\nFROM civicrm_email\nINNER JOIN civicrm_contact ON civicrm_email.contact_id = civicrm_contact.id\nWHERE civicrm_email.is_bulkmail = 1\nAND civicrm_contact.id = {$contact->contact_id}\nAND civicrm_contact.do_not_email = 0\nAND civicrm_contact.is_deceased = 0\nAND civicrm_email.on_hold = 0\nAND civicrm_contact.is_opt_out =0";
$dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
if ($dao->fetch()) {
$params = array('job_id' => $testParams['job_id'], 'email_id' => $dao->email_id, 'contact_id' => $contact->contact_id);
$queue = CRM_Mailing_Event_BAO_Queue::create($params);
} else {
$query = "SELECT DISTINCT civicrm_email.id AS email_id, civicrm_email.is_primary as is_primary,\n civicrm_email.is_bulkmail as is_bulkmail\nFROM civicrm_email\nINNER JOIN civicrm_contact ON civicrm_email.contact_id = civicrm_contact.id\nWHERE civicrm_email.is_primary = 1\nAND civicrm_contact.id = {$contact->contact_id}\nAND civicrm_contact.do_not_email =0\nAND civicrm_contact.is_deceased = 0\nAND civicrm_email.on_hold = 0\nAND civicrm_contact.is_opt_out =0";
$dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
if ($dao->fetch()) {
$params = array('job_id' => $testParams['job_id'], 'email_id' => $dao->email_id, 'contact_id' => $contact->contact_id);
$queue = CRM_Mailing_Event_BAO_Queue::create($params);
}
}
}
}
}
示例9: queue
/**
* Queue recipients of a job.
*
* @return void
* @access public
*/
public function queue($testParams = null)
{
require_once 'CRM/Mailing/BAO/Mailing.php';
$mailing =& new CRM_Mailing_BAO_Mailing();
$mailing->id = $this->mailing_id;
if (!empty($testParams)) {
$mailing->getTestRecipients($testParams);
} else {
$recipients =& $mailing->getRecipientsObject($this->id);
// since this is such a simple db operation, we could potentially optimize it a lot
// by doing a batch of inserts at one time
// INSERT INTO civicrm_..._queue ( job_id, email_id, contact_id, hash ) VALUES ( ... ),( ... ),...
// this will cut down the number of trips to the db quite nicely rather than doing one insert at a time
while ($recipients->fetch()) {
$params = array('job_id' => $this->id, 'email_id' => $recipients->email_id, 'contact_id' => $recipients->contact_id);
CRM_Mailing_Event_BAO_Queue::create($params);
}
}
}
示例10: CRM_Core_Dao
/**
* Create a new forward event, create a new contact if necessary
*
* @param $job_id
* @param $queue_id
* @param $hash
* @param $forward_email
* @param null $fromEmail
* @param null $comment
*
* @return bool
*/
public static function &forward($job_id, $queue_id, $hash, $forward_email, $fromEmail = NULL, $comment = NULL)
{
$q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
$successfulForward = FALSE;
$contact_id = NULL;
if (!$q) {
return $successfulForward;
}
/* Find the email address/contact, if it exists */
$contact = CRM_Contact_BAO_Contact::getTableName();
$location = CRM_Core_BAO_Location::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$queueTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$job = CRM_Mailing_BAO_MailingJob::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$forward = self::getTableName();
$domain = CRM_Core_BAO_Domain::getDomain();
$dao = new CRM_Core_Dao();
$dao->query("\n SELECT {$contact}.id as contact_id,\n {$email}.id as email_id,\n {$contact}.do_not_email as do_not_email,\n {$queueTable}.id as queue_id\n FROM ({$email}, {$job} as temp_job)\n INNER JOIN {$contact}\n ON {$email}.contact_id = {$contact}.id\n LEFT JOIN {$queueTable}\n ON {$email}.id = {$queueTable}.email_id\n LEFT JOIN {$job}\n ON {$queueTable}.job_id = {$job}.id\n AND temp_job.mailing_id = {$job}.mailing_id\n WHERE {$queueTable}.job_id = {$job_id}\n AND {$email}.email = '" . CRM_Utils_Type::escape($forward_email, 'String') . "'");
$dao->fetch();
$transaction = new CRM_Core_Transaction();
if (isset($dao->queue_id) || isset($dao->do_not_email) && $dao->do_not_email == 1) {
/* We already sent this mailing to $forward_email, or we should
* never email this contact. Give up. */
return $successfulForward;
}
require_once 'api/api.php';
$contactParams = array('email' => $forward_email, 'version' => 3);
$contactValues = civicrm_api('contact', 'get', $contactParams);
$count = $contactValues['count'];
if ($count == 0) {
/* If the contact does not exist, create one. */
$formatted = array('contact_type' => 'Individual', 'version' => 3);
$locationType = CRM_Core_BAO_LocationType::getDefault();
$value = array('email' => $forward_email, 'location_type_id' => $locationType->id);
require_once 'CRM/Utils/DeprecatedUtils.php';
_civicrm_api3_deprecated_add_formatted_param($value, $formatted);
$formatted['onDuplicate'] = CRM_Import_Parser::DUPLICATE_SKIP;
$formatted['fixAddress'] = TRUE;
$contact = civicrm_api('contact', 'create', $formatted);
if (civicrm_error($contact)) {
return $successfulForward;
}
$contact_id = $contact['id'];
}
$email = new CRM_Core_DAO_Email();
$email->email = $forward_email;
$email->find(TRUE);
$email_id = $email->id;
if (!$contact_id) {
$contact_id = $email->contact_id;
}
/* Create a new queue event */
$queue_params = array('email_id' => $email_id, 'contact_id' => $contact_id, 'job_id' => $job_id);
$queue = CRM_Mailing_Event_BAO_Queue::create($queue_params);
$forward = new CRM_Mailing_Event_BAO_Forward();
$forward->time_stamp = date('YmdHis');
$forward->event_queue_id = $queue_id;
$forward->dest_queue_id = $queue->id;
$forward->save();
$dao->reset();
$dao->query(" SELECT {$job}.mailing_id as mailing_id\n FROM {$job}\n WHERE {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'));
$dao->fetch();
$mailing_obj = new CRM_Mailing_BAO_Mailing();
$mailing_obj->id = $dao->mailing_id;
$mailing_obj->find(TRUE);
$config = CRM_Core_Config::singleton();
$mailer = $config->getMailer();
$recipient = NULL;
$attachments = NULL;
$message = $mailing_obj->compose($job_id, $queue->id, $queue->hash, $queue->contact_id, $forward_email, $recipient, FALSE, NULL, $attachments, TRUE, $fromEmail);
//append comment if added while forwarding.
if (count($comment)) {
$message->_txtbody = CRM_Utils_Array::value('body_text', $comment) . $message->_txtbody;
if (!empty($comment['body_html'])) {
$message->_htmlbody = $comment['body_html'] . '<br />---------------Original message---------------------<br />' . $message->_htmlbody;
}
}
$body = $message->get();
$headers = $message->headers();
$result = NULL;
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$result = $mailer->send($recipient, $headers, $body);
unset($errorScope);
}
$params = array('event_queue_id' => $queue->id, 'job_id' => $job_id, 'hash' => $queue->hash);
if (is_a($result, 'PEAR_Error')) {
//.........这里部分代码省略.........
示例11: elseif
/**
* Form rule to send out a test mailing.
*
* @param array $params Array of the form values
* @param array $files Any files posted to the form
* @param array $self an current this object
*
* @return boolean true on succesful SMTP handoff
* @access public
*/
static function &testMail($testParams, $files, $self)
{
$error = NULL;
$urlString = 'civicrm/mailing/send';
$urlParams = "_qf_Test_display=true&qfKey={$testParams['qfKey']}";
$ssID = $self->get('ssID');
if ($ssID && $self->_searchBasedMailing) {
if ($self->_action == CRM_Core_Action::BASIC) {
$fragment = 'search';
} elseif ($self->_action == CRM_Core_Action::PROFILE) {
$fragment = 'search/builder';
} elseif ($self->_action == CRM_Core_Action::ADVANCED) {
$fragment = 'search/advanced';
} else {
$fragment = 'search/custom';
}
$urlString = 'civicrm/contact/' . $fragment;
}
$emails = NULL;
if (CRM_Utils_Array::value('sendtest', $testParams)) {
if (!($testParams['test_group'] || $testParams['test_email'])) {
CRM_Core_Session::setStatus(ts('Your did not provided any email address or selected any group. No test mail is sent.'));
$error = TRUE;
}
if ($testParams['test_email']) {
$emailAdd = explode(',', $testParams['test_email']);
foreach ($emailAdd as $key => $value) {
$email = trim($value);
$testParams['emails'][] = $email;
$emails .= $emails ? ",'{$email}'" : "'{$email}'";
if (!CRM_Utils_Rule::email($email)) {
CRM_Core_Session::setStatus(ts('Please enter valid email addresses only.'));
$error = TRUE;
}
}
}
if ($error) {
$url = CRM_Utils_System::url($urlString, $urlParams);
CRM_Utils_System::redirect($url);
return $error;
}
}
if (CRM_Utils_Array::value('_qf_Test_submit', $testParams)) {
//when user perform mailing from search context
//redirect it to search result CRM-3711.
if ($ssID && $self->_searchBasedMailing) {
$draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
$status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.<br /> From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
CRM_Core_Session::setStatus($status);
//replace user context to search.
$context = $self->get('context');
if (!CRM_Contact_Form_Search::isSearchContext($context)) {
$context = 'search';
}
$urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}&qfKey={$testParams['qfKey']}";
$url = CRM_Utils_System::url($urlString, $urlParams);
CRM_Utils_System::redirect($url);
} else {
$status = ts("Your mailing has been saved. Click the 'Continue' action to resume working on it.");
CRM_Core_Session::setStatus($status);
$url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
CRM_Utils_System::redirect($url);
}
}
if (CRM_Mailing_Info::workflowEnabled()) {
if (!CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings')) {
$url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
CRM_Utils_System::redirect($url);
}
}
if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST) || CRM_Utils_Array::value('_qf_Test_next', $testParams) || !CRM_Utils_Array::value('sendtest', $testParams)) {
$error = TRUE;
return $error;
}
$job = new CRM_Mailing_BAO_Job();
$job->mailing_id = $self->get('mailing_id');
$job->is_test = TRUE;
$job->save();
$newEmails = NULL;
$session = CRM_Core_Session::singleton();
if (!empty($testParams['emails'])) {
$query = "\n SELECT id, contact_id, email \n FROM civicrm_email \n WHERE civicrm_email.email IN ({$emails})";
$dao = CRM_Core_DAO::executeQuery($query);
$emailDetail = array();
// fetch contact_id and email id for all existing emails
while ($dao->fetch()) {
$emailDetail[$dao->email] = array('contact_id' => $dao->contact_id, 'email_id' => $dao->id);
}
$dao->free();
foreach ($testParams['emails'] as $key => $email) {
//.........这里部分代码省略.........
示例12: queue
public function queue($testParams = null)
{
require_once 'CRM/Mailing/BAO/Mailing.php';
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $this->mailing_id;
if (!empty($testParams)) {
$mailing->getTestRecipients($testParams);
} else {
// We are still getting all the recipients from the parent job
// (The original so we don't mess with the include/exclude) logic
$recipients = $mailing->getRecipientsObject($this->parent_id, false, $this->job_offset, $this->job_limit);
// Here we will use the parent jobid to fetch the receipents, except
// We will introduce the limit and offset from the child job DAO object
// To only pick up segment of the receipents instead of the whole
while ($recipients->fetch()) {
$params = array('job_id' => $this->id, 'email_id' => $recipients->email_id, 'contact_id' => $recipients->contact_id);
CRM_Mailing_Event_BAO_Queue::create($params);
}
}
}
示例13: mte_createQueue
function mte_createQueue(&$mandrillHeader, $toEmail)
{
$mail = new CRM_Mailing_DAO_Mailing();
$mail->subject = "***All Transactional Emails***";
$mail->url_tracking = TRUE;
$mail->forward_replies = FALSE;
$mail->auto_responder = FALSE;
$mail->open_tracking = TRUE;
if ($mail->find(TRUE)) {
$emails = CRM_Mte_BAO_Mandrill::retrieveEmailContactId($toEmail);
$jobCLassName = 'CRM_Mailing_DAO_MailingJob';
if (version_compare('4.4alpha1', CRM_Core_Config::singleton()->civiVersion) > 0) {
$jobCLassName = 'CRM_Mailing_DAO_Job';
}
$params = array('job_id' => CRM_Core_DAO::getFieldValue($jobCLassName, $mail->id, 'id', 'mailing_id'), 'contact_id' => $emails['email']['contact_id'], 'email_id' => $emails['email']['id']);
$eventQueue = CRM_Mailing_Event_BAO_Queue::create($params);
$mandrillHeader = implode(CRM_Core_Config::singleton()->verpSeparator, array($mandrillHeader, 'm', $params['job_id'], $eventQueue->id, $eventQueue->hash));
}
}
示例14: CRM_Core_Dao
/**
* Create a new forward event, create a new contact if necessary
*/
function &forward($job_id, $queue_id, $hash, $forward_email)
{
$q =& CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
if (!$q) {
return null;
}
/* Find the email address/contact, if it exists */
$contact = CRM_Contact_BAO_Contact::getTableName();
$location = CRM_Core_BAO_Location::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$queueTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$job = CRM_Mailing_BAO_Job::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$forward = CRM_Mailing_Event_BAO_Forward::getTableName();
$domain =& CRM_Mailing_Event_BAO_Queue::getDomain($queue_id);
$dao =& new CRM_Core_Dao();
$dao->query("\n SELECT {$contact}.id as contact_id,\n {$email}.id as email_id,\n {$contact}.do_not_email as do_not_email,\n {$queueTable}.id as queue_id\n FROM {$email}, {$job} as temp_job\n INNER JOIN {$location}\n ON {$email}.location_id = {$location}.id\n INNER JOIN {$contact}\n ON {$location}.entity_table = '{$contact}'\n AND {$location}.entity_id = {$contact}.id\n LEFT JOIN {$queueTable}\n ON {$email}.id = {$queueTable}.email_id\n LEFT JOIN {$job}\n ON {$queueTable}.job_id = {$job}.id\n AND temp_job.mailing_id = {$job}.mailing_id\n WHERE temp_job.id = {$job_id}\n AND {$email}.email = '" . CRM_Utils_Type::escape($forward_email, 'String') . "'");
$dao->fetch();
CRM_Core_DAO::transaction('BEGIN');
if (isset($dao->queue_id) || $dao->do_not_email == 1) {
/* We already sent this mailing to $forward_email, or we should
* never email this contact. Give up. */
return false;
} elseif (empty($dao->contact_id)) {
/* No contact found, we'll have to create a new one */
$contact_params = array('email' => $forward_email);
$contact =& crm_create_contact($contact_params);
if (is_a($contact, 'CRM_Core_Error')) {
return false;
}
/* This is an ugly hack, but the API doesn't really support
* overriding the domain ID any other way */
$contact->domain_id = $domain->id;
$contact->save();
$contact_id = $contact->id;
$email_id = $contact->location[1]->email[1]->id;
} else {
$contact_id = $dao->contact_id;
$email_id = $dao->email_id;
}
/* Create a new queue event */
$queue_params = array('email_id' => $email_id, 'contact_id' => $contact_id, 'job_id' => $job_id);
$queue =& CRM_Mailing_Event_BAO_Queue::create($queue_params);
$forward =& new CRM_Mailing_Event_BAO_Forward();
$forward->time_stamp = date('YmdHis');
$forward->event_queue_id = $queue_id;
$forward->dest_queue_id = $queue->id;
$forward->save();
$dao->reset();
$dao->query(" SELECT {$job}.mailing_id as mailing_id \n FROM {$job}\n WHERE {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'));
$dao->fetch();
$mailing_obj =& new CRM_Mailing_BAO_Mailing();
$mailing_obj->id = $dao->mailing_id;
$mailing_obj->find(true);
$config =& CRM_Core_Config::singleton();
$mailer =& $config->getMailer();
$recipient = null;
$message =& $mailing_obj->compose($job_id, $queue->id, $queue->hash, $queue->contact_id, $forward_email, $recipient);
$body = $message->get();
$headers = $message->headers();
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' => $queue->id, 'job_id' => $job_id, 'hash' => $queue->hash);
if (is_a($result, PEAR_Error)) {
/* Register the bounce event */
$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);
}
CRM_Core_DAO::transaction('COMMIT');
return true;
}