$output_messages[] = _l('Waiting %s seconds before next batch of %s emails', $newsletter_send_burst_break, $newsletter_send_burst_count); if (!isset($result['timeout'])) { $result['timeout'] = $newsletter_send_burst_break; } } else { //$output_messages[] = _l('Finished sending, %s people remain',$remain); //$output_messages[] = _l('Please <a href="%s">click here</a> to refresh the page.',module_newsletter::link_queue_watch($newsletter_id,$send_id)); $output_messages[] = _l('Done'); if (!isset($result['timeout'])) { $result['timeout'] = -1; } if (!isset($result['done'])) { $result['done'] = 1; } if (!$send['finish_time']) { // just to make sure we set the finish time. $send_result = module_newsletter::process_send($newsletter_id, $send_id); } } } } } $result['messages'] = $output_messages; $result['update_members'] = $update_members; // put at end of array. bad js hack if (isset($result['done'])) { unset($result['done']); $result['done'] = 1; } echo json_encode($result); exit;
public static function run_cron($debug = false) { // send any scheduled newsletters via cron job $pending = self::get_newsletters(array('pending' => 1)); if (mysql_num_rows($pending) > 0) { while ($send = mysql_fetch_assoc($pending)) { if ($debug) { echo "Attempting to send: "; } if ($debug) { print_r($send['send_id']); } if ($send['send_id']) { $send = module_newsletter::get_send($send['send_id']); $start_time = $send['start_time']; if ($start_time > time()) { if ($debug) { echo 'not sending this one yet due to start time'; } } else { if ($send['status'] == _NEWSLETTER_STATUS_PENDING) { $newsletter_send_burst_count = module_config::c('newsletter_send_burst_count', 40); $newsletter_send_burst_break = module_config::c('newsletter_send_burst_break', 2); for ($x = 0; $x < 10; $x++) { // todo: find a better way to run the cron job, eg: a timeout in configuration, or a max sends per cron run. $send_result = module_newsletter::process_send($send['newsletter_id'], $send['send_id'], $newsletter_send_burst_count, false, false); if (!isset($send_result['send_members']) || !count($send_result['send_members'])) { //$output_messages[] = _l('All done'); } else { foreach ($send_result['send_members'] as $send_member_result) { $update_members[$send_member_result['newsletter_member_id']] = array(); switch ($send_member_result['status']) { case _MAIL_STATUS_SENT: $update_members[$send_member_result['newsletter_member_id']]['.sent_time'] = print_date(time(), true); $update_members[$send_member_result['newsletter_member_id']]['.status'] = _l('sent'); $output_messages[] = _l('Sent successfully: %s', $send_member_result['email']); break; case _MAIL_STATUS_OVER_QUOTA: $output_messages[] = _l('Over quota, please wait: %s', $send_member_result['email']); $update_members[$send_member_result['newsletter_member_id']]['.status'] = _l('pending'); // todo - update the main newsletter status to over quota? nah.. break 2; case _MAIL_STATUS_FAILED: default: $output_messages[] = _l('FAILED: %s Reason: %s', $send_member_result['email'], $send_member_result['error']); $update_members[$send_member_result['newsletter_member_id']]['.status'] = _l('failed'); break; } } } // get an update: $send = module_newsletter::get_send($send['send_id']); $remain = (int) $send['total_member_count'] - (int) $send['total_sent_count']; if ($remain > 0) { if ($debug) { echo " Finished sending, {$remain} people remain\n"; } } else { if ($debug) { echo " Everyone sent!\n"; } if (!$send['finish_time']) { // just to make sure we set the finish time. module_newsletter::process_send($send['newsletter_id'], $send['send_id']); } break; //exit for loop. } } } else { if ($debug) { echo 'not sending due to status of ' . $send['status']; } } } } } } if (!function_exists('imap_open')) { set_error('Please contact hosting provider and enable IMAP for PHP'); echo 'Imap extension not available for php'; return false; } self::check_bounces(); }