static function send_mail_cron() { //@ini_set('max_execution_time',0); global $wpdb; $count = SendPress_Option::get('emails-per-hour'); $count = SendPress_Option::get('wpcron-per-call', 25); $email_count = 0; $attempts = 0; if (SendPress_Manager::limit_reached($count)) { return; } SendPress_Email_Cache::build_cache(); for ($i = 0; $i < $count; $i++) { $email = SendPress_Data::get_single_email_from_queue(); if ($email != null) { $attempts++; SendPress_Data::queue_email_process($email->id); $result = SendPress_Manager::send_email_from_queue($email); $email_count++; if ($result) { if ($result === true) { $wpdb->update(SendPress_Data::queue_table(), array('success' => 1, 'inprocess' => 3), array('id' => $email->id)); //( $sid, $rid, $lid=null, $uid=null, $ip=null, $device_type=null, $device=null, $type='confirm' ) //$wpdb->update( SendPress_Data::queue_table() , array('success'=>1,'inprocess'=>3 ) , array('id'=> $email->id )); //$wpdb->insert(SendPress_Data::subscriber_tracker_table() , array('subscriberID'=>$email->subscriberID,'emailID'=>$email->emailID,'sent_at' => get_gmt_from_date( date('Y-m-d H:i:s') )) ); SPNL()->db("Subscribers_Tracker")->add(array('subscriber_id' => intval($email->subscriberID), 'email_id' => intval($email->emailID))); SendPress_Data::add_subscriber_event($email->subscriberID, $email->emailID, $email->listID, null, null, null, null, 'send'); } else { $wpdb->update(SendPress_Data::queue_table(), array('success' => 2, 'inprocess' => 3), array('id' => $email->id)); SendPress_Data::add_subscriber_event($email->subscriberID, $email->emailID, $email->listID, null, null, null, null, 'bounce'); SendPress_Data::bounce_subscriber_by_id($email->subscriberID); } //$wpdb->insert( $this->subscriber_open_table(), $senddata); $count++; //SendPress_Data::update_report_sent_count( $email->emailID ); } else { $wpdb->update(SendPress_Data::queue_table(), array('attempts' => $email->attempts + 1, 'inprocess' => 0, 'last_attempt' => date('Y-m-d H:i:s')), array('id' => $email->id)); } } else { //We ran out of emails to process. break; } set_time_limit(30); } return; }
function auto_cron() { // make sure we're in wp-cron.php if (false !== strpos($_SERVER['REQUEST_URI'], '/wp-cron.php')) { // make sure a secret string is provided in the ur if (isset($_GET['action']) && $_GET['action'] == 'sendpress') { $time_start = microtime(true); $count = SendPress_Data::emails_in_queue(); $bg = 0; if ($count > 0) { SendPress_Queue::send_mail(); $count = SendPress_Data::emails_in_queue(); } else { SPNL()->log->prune_logs(); SendPress_Data::clean_queue_table(); //SendPress_Logging::prune_logs(); $bg = 1; } $attempted_count = SendPress_Option::get('autocron-per-call', 25); $pro = 0; if (defined('SENDPRESS_PRO_VERSION')) { $pro = SENDPRESS_PRO_VERSION; } $stuck = SendPress_Data::emails_stuck_in_queue(); $limit = SendPress_Manager::limit_reached(); $emails_per_day = SendPress_Option::get('emails-per-day'); $emails_per_hour = SendPress_Option::get('emails-per-hour'); $hourly_emails = SendPress_Data::emails_sent_in_queue("hour"); $emails_so_far = SendPress_Data::emails_sent_in_queue("day"); $limits = array('autocron' => $attempted_count, 'dl' => $emails_per_day, 'hl' => $emails_per_hour, 'ds' => $emails_so_far, 'hs' => $hourly_emails); $time_end = microtime(true); $time = $time_end - $time_start; echo json_encode(array("background" => $bg, "queue" => $count, "stuck" => $stuck, "version" => SENDPRESS_VERSION, "pro" => $pro, "limit" => $limit, 'info' => $limits, 'time' => number_format($time, 3))); die; } } }
static function send_single_from_queue() { global $wpdb; //$emails = $this->wpdbQuery("SELECT * FROM ".$this->queue_table()." WHERE success = 0 AND max_attempts != attempts LIMIT ".$limit,"get_results"); $count = 0; $attempts = 0; $queue_table = SendPress_Data::queue_table(); if (SendPress_Manager::limit_reached()) { return array('attempted' => $attempts, 'sent' => $count); } SendPress_Email_Cache::build_cache(); $email = SendPress_Data::get_single_email_from_queue(true); if (is_object($email)) { //$email = $email[0]; if (SendPress_Manager::limit_reached()) { return array('attempted' => $attempts, 'sent' => $count); } $attempts++; SendPress_Data::queue_email_process($email->id); $result = SendPress_Manager::send_email_from_queue($email); if ($result) { if ($result === true) { $wpdb->update(SendPress_Data::queue_table(), array('success' => 1, 'inprocess' => 3), array('id' => $email->id)); //( $sid, $rid, $lid=null, $uid=null, $ip=null, $device_type=null, $device=null, $type='confirm' ) $wpdb->insert(SendPress_Data::subscriber_tracker_table(), array('subscriberID' => $email->subscriberID, 'emailID' => $email->emailID, 'sent_at' => get_gmt_from_date(date('Y-m-d H:i:s')))); SendPress_Data::add_subscriber_event($email->subscriberID, $email->emailID, $email->listID, null, null, null, null, 'send'); } else { $wpdb->update(SendPress_Data::queue_table(), array('success' => 2, 'inprocess' => 3), array('id' => $email->id)); SendPress_Data::add_subscriber_event($email->subscriberID, $email->emailID, $email->listID, null, null, null, null, 'bounce'); SendPress_Data::bounce_subscriber_by_id($email->subscriberID); } $count++; } else { $wpdb->update($queue_table, array('attempts' => $email->attempts + 1, 'inprocess' => 0, 'last_attempt' => date('Y-m-d H:i:s')), array('id' => $email->id)); } } else { //We ran out of emails to process. return array('attempted' => $attempts, 'sent' => $count); } //SendPress_Manager::increase_email_count( $attempts ); return array('attempted' => $attempts, 'sent' => $count); }
static function auto_cron() { // make sure we're in wp-cron.php if (false !== strpos($_SERVER['REQUEST_URI'], '/wp-cron.php')) { // make sure a secret string is provided in the ur if (isset($_GET['action']) && $_GET['action'] == 'sendpress') { //* Use cache static $cron_bg_run = null; static $cron_bg_run_weekly = null; $time_start = microtime(true); $count = SendPress_Data::emails_in_queue(); $bg = 0; $bg_weekly = 0; $error = ''; try { if ($count > 0) { SendPress_Queue::send_mail(); $count = SendPress_Data::emails_in_queue(); } else { //* If cache is empty, pull transient if (!$cron_bg_run) { $cron_bg_run = get_transient('spnl-background-daily'); } //* If transient has expired, do a fresh update check if (!$cron_bg_run) { //* If cache is empty, pull transient if (!$cron_bg_run_weekly) { $cron_bg_run_weekly = get_transient('spnl-background-weekly'); } //* If transient has expired, do a fresh update check if (!$cron_bg_run_weekly) { SPNL()->log->prune_logs(); SendPress_Data::clean_queue_table(); SendPress_DB_Tables::repair_tables(); $cron_bg_run_weekly = array('runtime' => date("F j, Y, g:i a")); set_transient('spnl-background-weekly', $cron_bg_run_weekly, 60 * 60 * 24 * 7); $bg_weekly = 1; } //SendPress_Logging::prune_logs(); $bg = 1; $cron_bg_run = array('runtime' => date("F j, Y, g:i a")); set_transient('spnl-background-daily', $cron_bg_run, 60 * 60 * 24); } } } catch (Exception $e) { $error = $e->getMessage(); SPNL()->log->add('Autocron', $error, 0, 'error'); } $attempted_count = SendPress_Option::get('autocron-per-call', 25); $pro = 0; if (defined('SENDPRESS_PRO_VERSION')) { $pro = SENDPRESS_PRO_VERSION; } $stuck = SendPress_Data::emails_stuck_in_queue(); $limit = SendPress_Manager::limit_reached(); $emails_per_day = SendPress_Option::get('emails-per-day'); $emails_per_hour = SendPress_Option::get('emails-per-hour'); $hourly_emails = SendPress_Data::emails_sent_in_queue("hour"); $emails_so_far = SendPress_Data::emails_sent_in_queue("day"); $limits = array('autocron' => $attempted_count, 'dl' => $emails_per_day, 'hl' => $emails_per_hour, 'ds' => $emails_so_far, 'hs' => $hourly_emails); $time_end = microtime(true); $time = $time_end - $time_start; echo json_encode(array("error" => $error, "background" => $bg, "weekly" => $bg_weekly, "queue" => $count, "stuck" => $stuck, "version" => SENDPRESS_VERSION, "pro" => $pro, "limit" => $limit, 'info' => $limits, 'time' => number_format($time, 3))); die; } } }
static function fetch_mail_from_queue() { @ini_set('max_execution_time', 0); global $wpdb; $count = SendPress_Option::get('emails-per-hour'); $emails_per_hour = SendPress_Option::get('emails-per-hour'); if (SendPress_Manager::limit_reached()) { return; } for ($i = 0; $i < $count; $i++) { $email = $this->wpdbQuery("SELECT * FROM " . SendPress_Data::queue_table() . " WHERE success = 0 AND max_attempts != attempts AND inprocess = 0 ORDER BY id LIMIT 1", "get_row"); if ($email != null) { if (SendPress_Manager::limit_reached()) { break; } $attempts++; SendPress_Data::queue_email_process($email->id); $result = SendPress_Manager::send_email_from_queue($email); $email_count++; if ($result) { $wpdb->update(SendPress_Data::queue_table(), array('success' => 1, 'inprocess' => 3), array('id' => $email->id)); $senddata = array('sendat' => date('Y-m-d H:i:s'), 'reportID' => $email->emailID, 'subscriberID' => $email->subscriberID); //$wpdb->insert( $this->subscriber_open_table(), $senddata); $count++; SendPress_Data::register_event('send', $email->subscriberID, $email->emailID); // SendPress_Data::update_report_sent_count( $email->emailID ); } else { $wpdb->update(SendPress_Data::queue_table(), array('attempts' => $email->attempts + 1, 'inprocess' => 0, 'last_attempt' => date('Y-m-d H:i:s')), array('id' => $email->id)); } } else { //We ran out of emails to process. break; } } return; }