Commit caaeb140 authored by jcnventura's avatar jcnventura

Fix #449446 by rsantiag: Use the job_queue module to send emails during the cron run

parent d4ead7a5
......@@ -137,6 +137,15 @@ function print_mail_settings() {
'#description' => t('If checked, the user will be able to choose between sending the full content or only the teaser at send time.'),
);
if (module_exists('job_queue')) {
$form['settings']['print_mail_job_queue'] = array(
'#type' => 'checkbox',
'#title' => t('Send e-mails using Job Queue'),
'#default_value' => variable_get('print_mail_job_queue', PRINT_MAIL_JOB_QUEUE_DEFAULT),
'#description' => t("Selecting this option, e-mail delivery will be performed by the Job Queue module during each cron run. Leaving this unselected, the e-mail will be sent immediately, but the site will take slightly longer to reply to the user."),
);
}
return system_settings_form($form);
}
......
......@@ -264,6 +264,14 @@ function print_mail_form_submit($form, &$form_state) {
ob_end_clean();
$ok = FALSE;
if (function_exists('job_queue_add') && variable_get('print_mail_job_queue', PRINT_MAIL_JOB_QUEUE_DEFAULT)) {
$use_job_queue = TRUE;
$this_file = drupal_get_path('module', 'print_mail') .'/print_mail.inc';
}
else {
$use_job_queue = FALSE;
}
$addresses = explode(', ', $form_state['values']['txt_to_addrs']);
foreach ($addresses as $to) {
// Call to hook_print_mail_before_send in order to know if the mail can be sent
......@@ -271,8 +279,15 @@ function print_mail_form_submit($form, &$form_state) {
$can_send = module_invoke_all('print_mail_before_send', $node, $to, $from, $params);
if (!in_array(FALSE, $can_send)) {
$ret = drupal_mail('print_mail', 'sendpage', $to, language_default(), $params, $from, TRUE);
if ($ret['result']) {
if ($use_job_queue) {
// Use job queue to send mails during cron runs
job_queue_add('drupal_mail', t('print_mail: From %from', array('%from' => $from)), array('print_mail', 'sendpage', $to, language_default(), $params, $from, TRUE), $this_file, TRUE);
}
else {
// Send mail immediately using Drupal's mail handler
$ret = drupal_mail('print_mail', 'sendpage', $to, language_default(), $params, $from, TRUE);
}
if ($ret['result'] || $use_job_queue) {
// Call to hook_print_mail_after_send in order to provide information to other modules.
module_invoke_all('print_mail_after_send', $node, $to, $from, $params);
......
......@@ -36,6 +36,7 @@ function print_mail_uninstall() {
variable_del('print_mail_text_confirmation');
variable_del('print_mail_text_message');
variable_del('print_mail_text_subject');
variable_del('print_mail_job_queue');
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_mail\_display\_%'");
foreach ($settings as $variable) {
variable_del($variable->name);
......
......@@ -22,6 +22,7 @@ define('PRINT_MAIL_BOOK_LINK_DEFAULT', 1);
define('PRINT_MAIL_HOURLY_THRESHOLD', 3);
define('PRINT_MAIL_TEASER_DEFAULT_DEFAULT', 1);
define('PRINT_MAIL_TEASER_CHOICE_DEFAULT', 1);
define('PRINT_MAIL_JOB_QUEUE_DEFAULT', 0);
/**
* Implementation of hook_theme().
......@@ -251,6 +252,16 @@ function print_mail_form_alter(&$form, $form_state, $form_id) {
}
}
/**
* Implementation of hook_job_queue_functions.
*/
function print_mail_job_queue_functions() {
$functions['print_mail'] = array(
'title' => t('Send to friend'),
);
return $functions;
}
/**
* Auxiliary function to assign the per-node settings to the node object fields
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment