本文整理汇总了PHP中CRM_Mailing_BAO_MailingJob类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Mailing_BAO_MailingJob类的具体用法?PHP CRM_Mailing_BAO_MailingJob怎么用?PHP CRM_Mailing_BAO_MailingJob使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Mailing_BAO_MailingJob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
/**
*/
public function tearDown()
{
$this->_mut->stop();
// $this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact'));
CRM_Utils_Hook::singleton()->reset();
CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0;
// DGW
parent::tearDown();
}
示例2: postProcess
/**
*
* @return void
*/
public function postProcess()
{
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Mailing_BAO_Mailing::del($this->_mailingId);
} elseif ($this->_action & CRM_Core_Action::DISABLE) {
CRM_Mailing_BAO_MailingJob::cancel($this->_mailingId);
} elseif ($this->_action & CRM_Core_Action::RENEW) {
//set is_archived to 1
CRM_Core_DAO::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId, 'is_archived', TRUE);
}
}
示例3: processQueue
/**
* @param null $mode
*
* @return bool
* @throws Exception
*/
public static function processQueue($mode = NULL)
{
$config = CRM_Core_Config::singleton();
if ($mode == NULL && CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") {
throw new CRM_Core_Exception(ts('The <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in the online user and administrator guide</a>', array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', 'reset=1'), 2 => "http://book.civicrm.org/user/advanced-configuration/email-system-configuration/")));
}
// check if we are enforcing number of parallel cron jobs
// CRM-8460
$gotCronLock = FALSE;
if (property_exists($config, 'mailerJobsMax') && $config->mailerJobsMax && $config->mailerJobsMax > 0) {
$lockArray = range(1, $config->mailerJobsMax);
shuffle($lockArray);
// check if we are using global locks
foreach ($lockArray as $lockID) {
$cronLock = Civi\Core\Container::singleton()->get('lockManager')->acquire("worker.mailing.send.{$lockID}");
if ($cronLock->isAcquired()) {
$gotCronLock = TRUE;
break;
}
}
// exit here since we have enuf cronjobs running
if (!$gotCronLock) {
CRM_Core_Error::debug_log_message('Returning early, since max number of cronjobs running');
return TRUE;
}
if (getenv('CIVICRM_CRON_HOLD')) {
// In testing, we may need to simulate some slow activities.
sleep(getenv('CIVICRM_CRON_HOLD'));
}
}
// load bootstrap to call hooks
// Split up the parent jobs into multiple child jobs
$mailerJobSize = property_exists($config, 'mailerJobSize') ? $config->mailerJobSize : NULL;
CRM_Mailing_BAO_MailingJob::runJobs_pre($mailerJobSize, $mode);
CRM_Mailing_BAO_MailingJob::runJobs(NULL, $mode);
CRM_Mailing_BAO_MailingJob::runJobs_post($mode);
// lets release the global cron lock if we do have one
if ($gotCronLock) {
$cronLock->release();
}
return TRUE;
}
示例4: civicrm_api3_mailing_send_test
/**
* Send test mailing.
*
* @param array $params
*
* @return array
* @throws \API_Exception
* @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_mailing_send_test($params)
{
if (!array_key_exists('test_group', $params) && !array_key_exists('test_email', $params)) {
throw new API_Exception("Mandatory key(s) missing from params array: test_group and/or test_email field are required");
}
civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_MailingJob', array('mailing_id'), FALSE);
$testEmailParams = _civicrm_api3_generic_replace_base_params($params);
$testEmailParams['is_test'] = 1;
$job = civicrm_api3('MailingJob', 'create', $testEmailParams);
$testEmailParams['job_id'] = $job['id'];
$testEmailParams['emails'] = explode(',', $testEmailParams['test_email']);
if (!empty($params['test_email'])) {
$query = CRM_Utils_SQL_Select::from('civicrm_email e')->select(array('e.id', 'e.contact_id', 'e.email'))->join('c', 'INNER JOIN civicrm_contact c ON e.contact_id = c.id')->where('e.email IN (@emails)', array('@emails' => $testEmailParams['emails']))->where('e.on_hold = 0')->where('c.is_opt_out = 0')->where('c.do_not_email = 0')->where('c.is_deceased = 0')->where('c.is_deleted = 0')->groupBy('e.id')->orderBy(array('e.is_bulkmail DESC', 'e.is_primary DESC'))->toSQL();
$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 ($testEmailParams['emails'] as $key => $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.
$contact = civicrm_api3('Contact', 'create', array('contact_type' => 'Individual', 'email' => $email, 'api.Email.get' => array('return' => 'id')));
$contactId = $contact['id'];
$emailId = $contact['values'][$contactId]['api.Email.get']['id'];
}
civicrm_api3('MailingEventQueue', 'create', array('job_id' => $job['id'], 'email_id' => $emailId, 'contact_id' => $contactId));
}
}
$isComplete = FALSE;
$config = CRM_Core_Config::singleton();
$mailerJobSize = Civi::settings()->get('mailerJobSize');
while (!$isComplete) {
// Q: In CRM_Mailing_BAO_Mailing::processQueue(), the three runJobs*()
// functions are all called. Why does Mailing.send_test only call one?
// CRM_Mailing_BAO_MailingJob::runJobs_pre($mailerJobSize, NULL);
$isComplete = CRM_Mailing_BAO_MailingJob::runJobs($testEmailParams);
// CRM_Mailing_BAO_MailingJob::runJobs_post(NULL);
}
//return delivered mail info
$mailDelivered = CRM_Mailing_Event_BAO_Delivered::getRows($params['mailing_id'], $job['id'], TRUE, NULL, NULL, NULL, TRUE);
return civicrm_api3_create_success($mailDelivered);
}
示例5: run
/**
* Run this page (figure out the action needed and perform it).
*/
public function run()
{
$this->preProcess();
$newArgs = func_get_args();
// since we want only first function argument
$newArgs = $newArgs[0];
if (isset($_GET['runJobs']) || CRM_Utils_Array::value('2', $newArgs) == 'queue') {
$mailerJobSize = Civi::settings()->get('mailerJobSize');
CRM_Mailing_BAO_MailingJob::runJobs_pre($mailerJobSize);
CRM_Mailing_BAO_MailingJob::runJobs();
CRM_Mailing_BAO_MailingJob::runJobs_post();
}
$this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this);
// CRM-11920 all should set sortByCharacter to null, not empty string
if (strtolower($this->_sortByCharacter) == 'all' || !empty($_POST)) {
$this->_sortByCharacter = NULL;
$this->set('sortByCharacter', NULL);
}
if (CRM_Utils_Array::value(3, $newArgs) == 'unscheduled') {
$this->_unscheduled = TRUE;
}
$this->set('unscheduled', $this->_unscheduled);
if (CRM_Utils_Array::value(3, $newArgs) == 'archived') {
$this->_archived = TRUE;
}
$this->set('archived', $this->_archived);
if (CRM_Utils_Array::value(3, $newArgs) == 'scheduled') {
$this->_scheduled = TRUE;
}
$this->set('scheduled', $this->_scheduled);
$this->_createdId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0);
if ($this->_createdId) {
$this->set('createdId', $this->_createdId);
}
if ($this->_sms) {
$this->set('sms', $this->_sms);
}
$session = CRM_Core_Session::singleton();
$context = $session->readUserContext();
if ($this->_action & CRM_Core_Action::DISABLE) {
if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', $this)) {
CRM_Mailing_BAO_MailingJob::cancel($this->_mailingId);
CRM_Utils_System::redirect($context);
} else {
$controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse', ts('Cancel Mailing'), $this->_action);
$controller->setEmbedded(TRUE);
$controller->run();
}
} elseif ($this->_action & CRM_Core_Action::DELETE) {
if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', $this)) {
// check for action permissions.
if (!CRM_Core_Permission::checkActionPermission('CiviMail', $this->_action)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
CRM_Mailing_BAO_Mailing::del($this->_mailingId);
CRM_Utils_System::redirect($context);
} else {
$controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse', ts('Delete Mailing'), $this->_action);
$controller->setEmbedded(TRUE);
$controller->run();
}
} elseif ($this->_action & CRM_Core_Action::RENEW) {
// archive this mailing, CRM-3752.
if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', $this)) {
// set is_archived to 1
CRM_Core_DAO::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId, 'is_archived', TRUE);
CRM_Utils_System::redirect($context);
} else {
$controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse', ts('Archive Mailing'), $this->_action);
$controller->setEmbedded(TRUE);
$controller->run();
}
}
$selector = new CRM_Mailing_Selector_Browse();
$selector->setParent($this);
$controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $this->get(CRM_Utils_Sort::SORT_ID) . $this->get(CRM_Utils_Sort::SORT_DIRECTION), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TEMPLATE);
$controller->setEmbedded(TRUE);
$controller->run();
// hack to display results as per search
$rows = $controller->getRows($controller);
$this->assign('rows', $rows);
$urlParams = 'reset=1';
$urlString = 'civicrm/mailing/browse';
if ($this->get('sms')) {
$urlParams .= '&sms=1';
}
if (CRM_Utils_Array::value(3, $newArgs) == 'unscheduled') {
$urlString .= '/unscheduled';
$urlParams .= '&scheduled=false';
$this->assign('unscheduled', TRUE);
} elseif (CRM_Utils_Array::value(3, $newArgs) == 'archived') {
$urlString .= '/archived';
$this->assign('archived', TRUE);
} elseif (CRM_Utils_Array::value(3, $newArgs) == 'scheduled') {
$urlString .= '/scheduled';
$urlParams .= '&scheduled=true';
}
//.........这里部分代码省略.........
示例6: postProcess
/**
* Process the posted form values. Approve /reject a mailing.
*/
public function postProcess()
{
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
$ids = array();
if (isset($this->_mailingID)) {
$ids['mailing_id'] = $this->_mailingID;
} else {
$ids['mailing_id'] = $this->get('mailing_id');
}
if (!$ids['mailing_id']) {
CRM_Core_Error::fatal();
}
$params['approver_id'] = $this->_contactID;
$params['approval_date'] = date('YmdHis');
// if rejected, then we need to reset the scheduled date and scheduled id
$rejectOptionID = CRM_Core_OptionGroup::getValue('mail_approval_status', 'Rejected', 'name');
if ($rejectOptionID && $params['approval_status_id'] == $rejectOptionID) {
$params['scheduled_id'] = 'null';
$params['scheduled_date'] = 'null';
// also delete any jobs associated with this mailing
$job = new CRM_Mailing_BAO_MailingJob();
$job->mailing_id = $ids['mailing_id'];
$job->delete();
} else {
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->id = $ids['mailing_id'];
$mailing->find(TRUE);
$params['scheduled_date'] = CRM_Utils_Date::processDate($mailing->scheduled_date);
}
CRM_Mailing_BAO_Mailing::create($params, $ids);
//when user perform mailing from search context
//redirect it to search result CRM-3711
$ssID = $this->get('ssID');
if ($ssID && $this->_searchBasedMailing) {
if ($this->_action == CRM_Core_Action::BASIC) {
$fragment = 'search';
} elseif ($this->_action == CRM_Core_Action::PROFILE) {
$fragment = 'search/builder';
} elseif ($this->_action == CRM_Core_Action::ADVANCED) {
$fragment = 'search/advanced';
} else {
$fragment = 'search/custom';
}
$context = $this->get('context');
if (!CRM_Contact_Form_Search::isSearchContext($context)) {
$context = 'search';
}
$urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}";
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&qfKey={$qfKey}";
}
$url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
return $this->controller->setDestination($url);
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse/scheduled', 'reset=1&scheduled=true'));
}
示例7: CRM_Mailing_BAO_Mailing
/**
* Get the mailing object for this queue event instance.
*
* @param
*
* @return object
* Mailing BAO
*/
public function &getMailing()
{
$mailing = new CRM_Mailing_BAO_Mailing();
$jobs = CRM_Mailing_BAO_MailingJob::getTableName();
$mailings = CRM_Mailing_BAO_Mailing::getTableName();
$queue = self::getTableName();
$mailing->query("\n SELECT {$mailings}.*\n FROM {$mailings}\n INNER JOIN {$jobs}\n ON {$jobs}.mailing_id = {$mailings}.id\n INNER JOIN {$queue}\n ON {$queue}.job_id = {$jobs}.id\n WHERE {$queue}.id = {$this->id}");
$mailing->fetch();
return $mailing;
}
示例8: CRM_Core_Dao
/**
* Get rows for the event browser
*
* @param int $mailing_id ID of the mailing
* @param int $job_id optional ID of the job
* @param boolean $is_distinct Group by queue id?
* @param int $offset Offset
* @param int $rowCount Number of rows
* @param array $sort sort array
*
* @return array Result set
* @access public
* @static
*/
public static function &getRows($mailing_id, $job_id = NULL, $is_distinct = FALSE, $offset = NULL, $rowCount = NULL, $sort = NULL)
{
$dao = new CRM_Core_Dao();
$bounce = self::getTableName();
$bounceType = CRM_Mailing_DAO_BounceType::getTableName();
$queue = CRM_Mailing_Event_BAO_Queue::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$job = CRM_Mailing_BAO_MailingJob::getTableName();
$contact = CRM_Contact_BAO_Contact::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$query = "\n SELECT {$contact}.display_name as display_name,\n {$contact}.id as contact_id,\n {$email}.email as email,\n {$bounce}.time_stamp as date,\n {$bounce}.bounce_reason as reason,\n {$bounceType}.name as bounce_type\n FROM {$contact}\n INNER JOIN {$queue}\n ON {$queue}.contact_id = {$contact}.id\n INNER JOIN {$email}\n ON {$queue}.email_id = {$email}.id\n INNER JOIN {$bounce}\n ON {$bounce}.event_queue_id = {$queue}.id\n LEFT JOIN {$bounceType}\n ON {$bounce}.bounce_type_id = {$bounceType}.id\n INNER JOIN {$job}\n ON {$queue}.job_id = {$job}.id\n AND {$job}.is_test = 0\n INNER JOIN {$mailing}\n ON {$job}.mailing_id = {$mailing}.id\n WHERE {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
if (!empty($job_id)) {
$query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
if ($is_distinct) {
$query .= " GROUP BY {$queue}.id ";
}
$orderBy = "sort_name ASC, {$bounce}.time_stamp DESC";
if ($sort) {
if (is_string($sort)) {
$sort = CRM_Utils_Type::escape($sort, 'String');
$orderBy = $sort;
} else {
$orderBy = trim($sort->orderBy());
}
}
$query .= " ORDER BY {$orderBy} ";
if ($offset || $rowCount) {
//Added "||$rowCount" to avoid displaying all records on first page
$query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
}
$dao->query($query);
$results = array();
while ($dao->fetch()) {
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
$results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'type' => empty($dao->bounce_type) ? ts('Unknown') : $dao->bounce_type, 'reason' => $dao->reason, 'date' => CRM_Utils_Date::customFormat($dao->date));
}
return $results;
}
示例9: cancel
/**
* Cancel a mailing.
*
* @param int $mailingId
* The id of the mailing to be canceled.
*/
public static function cancel($mailingId)
{
$sql = "\nSELECT *\nFROM civicrm_mailing_job\nWHERE mailing_id = %1\nAND is_test = 0\nAND ( ( job_type IS NULL ) OR\n job_type <> 'child' )\n";
$params = array(1 => array($mailingId, 'Integer'));
$job = CRM_Core_DAO::executeQuery($sql, $params);
if ($job->fetch() && in_array($job->status, array('Scheduled', 'Running', 'Paused'))) {
$newJob = new CRM_Mailing_BAO_MailingJob();
$newJob->id = $job->id;
$newJob->end_date = date('YmdHis');
$newJob->status = 'Canceled';
$newJob->save();
// also cancel all child jobs
$sql = "\nUPDATE civicrm_mailing_job\nSET status = 'Canceled',\n end_date = %2\nWHERE parent_id = %1\nAND is_test = 0\nAND job_type = 'child'\nAND status IN ( 'Scheduled', 'Running', 'Paused' )\n";
$params = array(1 => array($job->id, 'Integer'), 2 => array(date('YmdHis'), 'Timestamp'));
CRM_Core_DAO::executeQuery($sql, $params);
CRM_Core_Session::setStatus(ts('The mailing has been canceled.'), ts('Canceled'), 'success');
}
}
示例10: processQueue
static function processQueue($mode = NULL)
{
$config =& CRM_Core_Config::singleton();
// CRM_Core_Error::debug_log_message("Beginning processQueue run: {$config->mailerJobsMax}, {$config->mailerJobSize}");
if ($mode == NULL && CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") {
CRM_Core_Error::fatal(ts('The <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in the online user and administrator guide</a>', array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', 'reset=1'), 2 => "http://book.civicrm.org/user/advanced-configuration/email-system-configuration/")));
}
// check if we are enforcing number of parallel cron jobs
// CRM-8460
$gotCronLock = FALSE;
if (property_exists($config, 'mailerJobsMax') && $config->mailerJobsMax && $config->mailerJobsMax > 1) {
$lockArray = range(1, $config->mailerJobsMax);
shuffle($lockArray);
// check if we are using global locks
$serverWideLock = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'civimail_server_wide_lock');
foreach ($lockArray as $lockID) {
$cronLock = new CRM_Core_Lock("civimail.cronjob.{$lockID}", NULL, $serverWideLock);
if ($cronLock->isAcquired()) {
$gotCronLock = TRUE;
break;
}
}
// exit here since we have enuf cronjobs running
if (!$gotCronLock) {
CRM_Core_Error::debug_log_message('Returning early, since max number of cronjobs running');
return TRUE;
}
}
// load bootstrap to call hooks
// Split up the parent jobs into multiple child jobs
$mailerJobSize = property_exists($config, 'mailerJobSize') ? $config->mailerJobSize : NULL;
CRM_Mailing_BAO_MailingJob::runJobs_pre($mailerJobSize, $mode);
CRM_Mailing_BAO_MailingJob::runJobs(NULL, $mode);
CRM_Mailing_BAO_MailingJob::runJobs_post($mode);
// lets release the global cron lock if we do have one
if ($gotCronLock) {
$cronLock->release();
}
// CRM_Core_Error::debug_log_message('Ending processQueue run');
return TRUE;
}
示例11: ts
//.........这里部分代码省略.........
$workFlow = $showApprovalLinks = $showScheduleLinks = $showCreateLinks = FALSE;
if (CRM_Mailing_Info::workflowEnabled()) {
$allAccess = FALSE;
$workFlow = TRUE;
//supercedes all permission
if (CRM_Core_Permission::check('access CiviMail')) {
$allAccess = TRUE;
}
if (CRM_Core_Permission::check('approve mailings')) {
$showApprovalLinks = TRUE;
}
if (CRM_Core_Permission::check('create mailings')) {
$showCreateLinks = TRUE;
}
if (CRM_Core_Permission::check('schedule mailings')) {
$showScheduleLinks = TRUE;
}
}
$mailing = new CRM_Mailing_BAO_Mailing();
$params = array();
$whereClause = ' AND ' . $this->whereClause($params);
if (empty($params)) {
$this->_parent->assign('isSearch', 0);
} else {
$this->_parent->assign('isSearch', 1);
}
$rows =& $mailing->getRows($offset, $rowCount, $sort, $whereClause, $params);
//get the search base mailing Ids, CRM-3711.
$searchMailings = $mailing->searchMailingIDs();
//check for delete CRM-4418
$allowToDelete = CRM_Core_Permission::check('delete in CiviMail');
if ($output != CRM_Core_Selector_Controller::EXPORT) {
//create the appropriate $op to use for hook_civicrm_links
$pageTypes = array('view', 'mailing', 'browse');
if ($this->_parent->_unscheduled) {
$pageTypes[] = 'unscheduled';
}
if ($this->_parent->_scheduled) {
$pageTypes[] = 'scheduled';
}
if ($this->_parent->_archived) {
$pageTypes[] = 'archived';
}
$opString = implode('.', $pageTypes);
foreach ($rows as $key => $row) {
$actionMask = NULL;
if ($row['sms_provider_id']) {
$actionLinks[CRM_Core_Action::PREVIEW]['url'] = 'civicrm/sms/send';
}
if (!($row['status'] == 'Not scheduled') && !$row['sms_provider_id']) {
if ($allAccess || $showCreateLinks) {
$actionMask = CRM_Core_Action::VIEW;
}
if (!in_array($row['id'], $searchMailings)) {
if ($allAccess || $showCreateLinks) {
$actionMask |= CRM_Core_Action::UPDATE;
}
}
} else {
if ($allAccess || ($showCreateLinks || $showScheduleLinks)) {
$actionMask = CRM_Core_Action::PREVIEW;
}
}
if (in_array($row['status'], array('Scheduled', 'Running', 'Paused'))) {
if ($allAccess || $showApprovalLinks && $showCreateLinks && $showScheduleLinks) {
$actionMask |= CRM_Core_Action::DISABLE;
}
if ($row['status'] == 'Scheduled' && empty($row['approval_status_id'])) {
if ($workFlow && ($allAccess || $showApprovalLinks)) {
$actionMask |= CRM_Core_Action::ENABLE;
}
}
}
if (in_array($row['status'], array('Complete', 'Canceled')) && !$row['archived']) {
if ($allAccess || $showCreateLinks) {
$actionMask |= CRM_Core_Action::RENEW;
}
}
//check for delete permission.
if ($allowToDelete) {
$actionMask |= CRM_Core_Action::DELETE;
}
if ($actionMask == NULL) {
$actionMask = CRM_Core_Action::ADD;
}
//get status strings as per locale settings CRM-4411.
$rows[$key]['status'] = CRM_Mailing_BAO_MailingJob::status($row['status']);
$rows[$key]['action'] = CRM_Core_Action::formLink($actionLinks, $actionMask, array('mid' => $row['id']), "more", FALSE, $opString, "Mailing", $row['id']);
//unset($rows[$key]['id']);
// if the scheduled date is 0, replace it with an empty string
if ($rows[$key]['scheduled_iso'] == '0000-00-00 00:00:00') {
$rows[$key]['scheduled'] = '';
}
unset($rows[$key]['scheduled_iso']);
}
}
// also initialize the AtoZ pager
$this->pagerAtoZ();
return $rows;
}
示例12: send
/**
* Store Mails into Spool table.
*
* @param string|array $recipient
* Either a comma-seperated list of recipients
* (RFC822 compliant), or an array of recipients,
* each RFC822 valid. This may contain recipients not
* specified in the headers, for Bcc:, resending
* messages, etc.
* @param array $headers
* The array of headers to send with the mail.
*
* @param string $body
* The full text of the message body, including any mime parts, etc.
*
* @param int $job_id
*
* @return bool|CRM_Core_Error
* true if successful
*/
public function send($recipient, $headers, $body, $job_id = NULL)
{
$headerStr = array();
foreach ($headers as $name => $value) {
$headerStr[] = "{$name}: {$value}";
}
$headerStr = implode("\n", $headerStr);
if (is_null($job_id)) {
// This is not a bulk mailing. Create a dummy job for it.
$session = CRM_Core_Session::singleton();
$params = array();
$params['created_id'] = $session->get('userID');
$params['created_date'] = date('YmdHis');
$params['scheduled_id'] = $params['created_id'];
$params['scheduled_date'] = $params['created_date'];
$params['is_completed'] = 1;
$params['is_archived'] = 1;
$params['body_html'] = htmlspecialchars($headerStr) . "\n\n" . $body;
$params['subject'] = $headers['Subject'];
$params['name'] = $headers['Subject'];
$ids = array();
$mailing = CRM_Mailing_BAO_Mailing::create($params, $ids);
if (empty($mailing) || is_a($mailing, 'CRM_Core_Error')) {
return PEAR::raiseError('Unable to create spooled mailing.');
}
$job = new CRM_Mailing_BAO_MailingJob();
$job->is_test = 0;
// if set to 1 it doesn't show in the UI
$job->status = 'Complete';
$job->scheduled_date = CRM_Utils_Date::processDate(date('Y-m-d'), date('H:i:s'));
$job->start_date = $job->scheduled_date;
$job->end_date = $job->scheduled_date;
$job->mailing_id = $mailing->id;
$job->save();
$job_id = $job->id;
// need this for parent_id below
$job = new CRM_Mailing_BAO_MailingJob();
$job->is_test = 0;
$job->status = 'Complete';
$job->scheduled_date = CRM_Utils_Date::processDate(date('Y-m-d'), date('H:i:s'));
$job->start_date = $job->scheduled_date;
$job->end_date = $job->scheduled_date;
$job->mailing_id = $mailing->id;
$job->parent_id = $job_id;
$job->job_type = 'child';
$job->save();
$job_id = $job->id;
// this is the one we want for the spool
if (is_array($recipient)) {
$recipient = implode(';', $recipient);
}
}
$session = CRM_Core_Session::singleton();
$params = array('job_id' => $job_id, 'recipient_email' => $recipient, 'headers' => $headerStr, 'body' => $body, 'added_at' => date("YmdHis"), 'removed_at' => NULL);
$spoolMail = new CRM_Mailing_DAO_Spool();
$spoolMail->copyValues($params);
$spoolMail->save();
return TRUE;
}
示例13: send_resub_response
/**
* Send a response email informing the contact of the groups to which he/she
* has been resubscribed.
*
* @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.
*/
public static function send_resub_response($queue_id, $groups, $is_domain = FALSE, $job)
{
// param is_domain is not supported as of now.
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
$jobTable = CRM_Mailing_BAO_MailingJob::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();
$component->id = $dao->resubscribe_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();
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();
if ($eq->format == 'HTML' || $eq->format == 'Both') {
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceResubscribeTokens($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($html, $domain, TRUE, $tokens['text']);
$text = CRM_Utils_Token::replaceResubscribeTokens($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);
}
$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}");
CRM_Mailing_BAO_Mailing::addMessageIdHeader($headers, 'e', $job, $queue_id, $eq->hash);
$b = CRM_Utils_Mail::setMimeParams($message);
$h = $message->headers($headers);
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$mailer->send($eq->email, $h, $b);
unset($errorScope);
}
}
示例14: tearDown
public function tearDown()
{
CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0;
// DGW
parent::tearDown();
}
示例15: array
/**
* returns the column headers as an array of tuples:
* (name, sortName (key to the sort array))
*
* @param string $action the action being performed
* @param enum $output what should the result set include (web/email/csv)
*
* @return array the column headers that need to be displayed
* @access public
*/
function &getColumnHeaders($action = NULL, $output = NULL)
{
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$contact = CRM_Contact_BAO_Contact::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$job = CRM_Mailing_BAO_MailingJob::getTableName();
if (!isset($this->_columnHeaders)) {
$this->_columnHeaders = array(array('name' => ts('Contact'), 'sort' => $contact . '.sort_name', 'direction' => CRM_Utils_Sort::ASCENDING), array('name' => ts('Email Address'), 'sort' => $email . '.email', 'direction' => CRM_Utils_Sort::DONTCARE));
switch ($this->_event_type) {
case 'queue':
$dateSort = $job . '.start_date';
break;
case 'delivered':
$dateSort = CRM_Mailing_Event_BAO_Delivered::getTableName() . '.time_stamp';
break;
case 'opened':
$dateSort = CRM_Mailing_Event_BAO_Opened::getTableName() . '.time_stamp';
break;
case 'bounce':
$dateSort = CRM_Mailing_Event_BAO_Bounce::getTableName() . '.time_stamp';
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Bounce Type')), array('name' => ts('Bounce Reason'))));
break;
case 'forward':
$dateSort = CRM_Mailing_Event_BAO_Forward::getTableName() . '.time_stamp';
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Forwarded Email'))));
break;
case 'reply':
$dateSort = CRM_Mailing_Event_BAO_Reply::getTableName() . '.time_stamp';
break;
case 'unsubscribe':
$dateSort = CRM_Mailing_Event_BAO_Unsubscribe::getTableName() . '.time_stamp';
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Unsubscribe'))));
break;
case 'optout':
$dateSort = CRM_Mailing_Event_BAO_Unsubscribe::getTableName() . '.time_stamp';
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Opt-Out'))));
break;
case 'click':
$dateSort = CRM_Mailing_Event_BAO_TrackableURLOpen::getTableName() . '.time_stamp';
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('URL'))));
break;
default:
return 0;
}
$this->_columnHeaders = array_merge($this->_columnHeaders, array(array('name' => ts('Date'), 'sort' => $dateSort, 'direction' => CRM_Utils_Sort::DESCENDING)));
}
return $this->_columnHeaders;
}