CRM_Utils_Hook::alterMailParams($mailParams, 'civimail');
// CRM-10699 support custom email headers
- if (CRM_Utils_Array::value('headers', $mailParams)) {
+ if (!empty($mailParams['headers'])) {
$headers = array_merge($headers, $mailParams['headers']);
}
//cycle through mailParams and set headers array
$result = $mailing->save();
- if (CRM_Utils_Array::value('mailing', $ids)) {
+ if (!empty($ids['mailing'])) {
CRM_Utils_Hook::post('edit', 'Mailing', $mailing->id, $mailing);
}
else {
'from_email' => $domain_email,
'from_name' => $domain_name,
'msg_template_id' => NULL,
- 'contact_id' => $params['created_id'],
'created_id' => $params['created_id'],
- 'approver_id' => $params['created_id'],
+ 'approver_id' => NULL,
'auto_responder' => 0,
'created_date' => date('YmdHis'),
- 'scheduled_date' => date('YmdHis'),
- 'approval_date' => date('YmdHis'),
+ 'scheduled_date' => NULL,
+ 'approval_date' => NULL,
);
// Get the default from email address, if not provided.
$mg = new CRM_Mailing_DAO_MailingGroup();
foreach (array('groups', 'mailings') as $entity) {
foreach (array('include', 'exclude', 'base') as $type) {
- if (isset($params[$entity]) &&
- CRM_Utils_Array::value($type, $params[$entity]) &&
+ if (isset($params[$entity]) && !empty($params[$entity][$type]) &&
is_array($params[$entity][$type])) {
foreach ($params[$entity][$type] as $entityId) {
$mg->reset();
$transaction->commit();
/**
- * 'approval_status_id' set in
- * CRM_Mailing_Form_Schedule::postProcess() or via API.
+ * create parent job if not yet created
+ * condition on the existence of a scheduled date
*/
- if (isset($params['approval_status_id']) && $params['approval_status_id']) {
+ if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null') {
$job = new CRM_Mailing_BAO_MailingJob();
$job->mailing_id = $mailing->id;
$job->status = 'Scheduled';
$job->is_test = 0;
- $job->scheduled_date = $params['scheduled_date'];
- $job->save();
+
+ if ( !$job->find(TRUE) ) {
+ $job->scheduled_date = $params['scheduled_date'];
+ $job->save();
+ }
+
// Populate the recipients.
$mailing->getRecipients($job->id, $mailing->id, NULL, NULL, TRUE, FALSE);
}
$report['event_totals']['queue'] = self::getRecipientsCount($mailing_id, $mailing_id);
}
- if (CRM_Utils_Array::value('queue', $report['event_totals'])) {
+ if (!empty($report['event_totals']['queue'])) {
$report['event_totals']['delivered_rate'] = (100.0 * $report['event_totals']['delivered']) / $report['event_totals']['queue'];
$report['event_totals']['bounce_rate'] = (100.0 * $report['event_totals']['bounce']) / $report['event_totals']['queue'];
$report['event_totals']['unsubscribe_rate'] = (100.0 * $report['event_totals']['unsubscribe']) / $report['event_totals']['queue'];
) as $key) {
$url = 'mailing/detail';
$reportFilter = "reset=1&mailing_id_value={$mailing_id}";
- $searchFilter = "force=1&mailing_id={$mailing_id}";
+ $searchFilter = "force=1&mailing_id=%%mid%%";
switch ($key) {
case 'delivered':
$reportFilter .= "&delivery_status_value=successful";
if (array_key_exists(CRM_Core_Action::ADVANCED, $actionLinks)) {
$actionLinks[CRM_Core_Action::ADVANCED]['qs'] = $searchFilter;
}
- $report['event_totals']['actionlinks'][$key] = CRM_Core_Action::formLink($actionLinks, $action, array());
+ $report['event_totals']['actionlinks'][$key] = CRM_Core_Action::formLink(
+ $actionLinks,
+ $action,
+ array('mid' => $mailing_id),
+ ts('more'),
+ FALSE,
+ 'mailing.report.action',
+ 'Mailing',
+ $mailing_id
+ );
}
return $report;
CRM_Core_Error::fatal();
}
+ CRM_Utils_Hook::pre('delete', 'Mailing', $id, CRM_Core_DAO::$_nullArray);
+
// delete all file attachments
CRM_Core_BAO_File::deleteEntityFile('civicrm_mailing',
$id
$dao->delete();
CRM_Core_Session::setStatus(ts('Selected mailing has been deleted.'), ts('Deleted'), 'success');
+
+ CRM_Utils_Hook::post('delete', 'Mailing', $id, $dao);
}
/**
*
* @param $form
*
- * @return None
+ * @return void
* @access public
*/
public static function commonCompose(&$form) {
//get the tokens.
$tokens = CRM_Core_SelectValues::contactTokens();
- //token selector for subject
- //CRM-5058
- $form->add('select', 'token3', ts('Insert Token'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onclick' => "return tokenReplText(this);",
- )
- );
$className = CRM_Utils_System::getClassName($form);
if ($className == 'CRM_Mailing_Form_Upload') {
$tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens);
}
//sorted in ascending order tokens by ignoring word case
- natcasesort($tokens);
- $form->assign('tokens', json_encode($tokens));
-
- $form->add('select', 'token1', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onclick' => "return tokenReplText(this);",
- )
- );
-
- $form->add('select', 'token2', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onclick' => "return tokenReplHtml(this);",
- )
- );
-
+ $form->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
$form->_templates = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE);
if (!empty($form->_templates)) {
*
* @param $form
*
- * @return None
+ * @return void
* @access public
*/
public static function commonLetterCompose(&$form) {
$tokens = array_merge($form->listTokens(), $tokens);
}
- //sorted in ascending order tokens by ignoring word case
- natcasesort($tokens);
-
- $form->assign('tokens', json_encode($tokens));
-
- $form->add('select', 'token1', ts('Insert Tokens'),
- $tokens, FALSE,
- array(
- 'size' => "5",
- 'multiple' => TRUE,
- 'onchange' => "return tokenReplHtml(this);",
- )
- );
+ $form->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
$form->_templates = CRM_Core_BAO_MessageTemplate::getMessageTemplates(FALSE);
if (!empty($form->_templates)) {
static function processQueue($mode = NULL) {
$config = &CRM_Core_Config::singleton();
- // CRM_Core_Error::debug_log_message("Beginning processQueue run: {$config->mailerJobsMax}, {$config->mailerJobSize}");
+ // 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 ($config->mailerJobsMax && $config->mailerJobsMax > 1) {
+ if (property_exists($config, 'mailerJobsMax') && $config->mailerJobsMax && $config->mailerJobsMax > 1) {
$lockArray = range(1, $config->mailerJobsMax);
shuffle($lockArray);
// load bootstrap to call hooks
// Split up the parent jobs into multiple child jobs
- CRM_Mailing_BAO_MailingJob::runJobs_pre($config->mailerJobSize, $mode);
+ $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);
return TRUE;
}
- private function addMultipleEmails($mailingID) {
+ private static function addMultipleEmails($mailingID) {
$sql = "
INSERT INTO civicrm_mailing_recipients
(mailing_id, email_id, contact_id)
//CRM-12814
if (!empty($mailings)) {
- $openCounts = CRM_Mailing_Event_BAO_Opened::getMailingTotalCount(array_keys($mailings));
- $clickCounts = CRM_Mailing_Event_BAO_TrackableURLOpen::getMailingTotalCount(array_keys($mailings));
+ $openCounts = CRM_Mailing_Event_BAO_Opened::getMailingContactCount(array_keys($mailings), $params['contact_id']);
+ $clickCounts = CRM_Mailing_Event_BAO_TrackableURLOpen::getMailingContactCount(array_keys($mailings), $params['contact_id']);
}
// format params and add links
"reset=1&cid={$values['creator_id']}");
//CRM-12814
- $contactMailings[$mailingId]['openstats'] = ts('Opens') . ': ' . $openCounts[$values['mailing_id']] .
- '<br />' . ts('Clicks') . ': ' . $clickCounts[$values['mailing_id']];
+ $contactMailings[$mailingId]['openstats'] = "Opens: ".
+ CRM_Utils_Array::value($values['mailing_id'], $openCounts, 0).
+ "<br />Clicks: ".
+ CRM_Utils_Array::value($values['mailing_id'], $clickCounts, 0);
$actionLinks = array(
CRM_Core_Action::VIEW => array(
'name' => ts('View'),
'url' => 'civicrm/mailing/view',
- 'qs' => "reset=1&id={$values['mailing_id']}",
+ 'qs' => "reset=1&id=%%mid%%",
'title' => ts('View Mailing'),
'class' => 'crm-mailing-view',
),
CRM_Core_Action::BROWSE => array(
'name' => ts('Mailing Report'),
'url' => 'civicrm/mailing/report',
- 'qs' => "mid={$values['mailing_id']}&reset=1&cid={$params['contact_id']}&context=mailing",
+ 'qs' => "mid=%%mid%%&reset=1&cid=%%cid%%&context=mailing",
'title' => ts('View Mailing Report'),
)
);
- $contactMailings[$mailingId]['links'] = CRM_Core_Action::formLink($actionLinks);
+ $contactMailings[$mailingId]['links'] = CRM_Core_Action::formLink(
+ $actionLinks,
+ null,
+ array(
+ 'mid' => $values['mailing_id'],
+ 'cid' => $params['contact_id'],
+ ),
+ ts('more'),
+ FALSE,
+ 'mailing.contact.action',
+ 'Mailing',
+ $values['mailing_id']
+ );
}
return $contactMailings;