Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function action_send_daily()
- {
- gc_enable();
- $x = 1;
- while ($x <50)
- {
- echo memory_get_peak_usage(). " start <br>";
- $members = NULL;
- $members = DB::select('id', 'email')
- ->from('members')
- //original member query
- ->where('send_update','=','Y')
- ->where('email_confirmed', '=', 'Y')
- ->where('send_update_frequency','=','daily')
- //->where('members.emailed_am', '=', 'N')
- ->and_where_open()
- ->where('send_update_time','=','am')
- ->or_where('send_update_time', '=', 'am_pm')
- ->and_where_close()
- ->and_where_open()
- ->where('member_type_id', '=', '1') //subscribed
- ->or_where('member_type_id', '=', '4') //trial
- ->or_where('member_type_id', '=', '5') // Prospect
- ->or_where('member_type_id', '=', '6') // Comp
- ->or_where('member_type_id', '=', '7') // Said No
- ->and_where_close()
- ->where('emailed_am','=', "N")
- //->limit(2)
- ->as_object()
- ->execute()
- ->current();
- //echo memory_get_peak_usage(). " members <br>";
- //foreach ($members as $m)
- // {
- $m = $members;
- $emails = NULL;
- $emails = DB::select()
- ->from('emailerscheds')
- //end original
- ->where('sent_day', '=', "0")
- ->where('day', '=', 'Y')
- ->where('member_id', '=', $m->id)
- ->order_by('topic_id')
- ->as_object()
- ->execute();
- echo memory_get_peak_usage(). " emails <br>";
- // echo $emails->count(). " " . $m->id;
- //exit;
- if ($emails->count() > 0 )
- {
- //echo $emails->count()." - $m->id <br>";
- //exit;
- $art = 0;
- //$member_id = 0;
- $topic_id = 0;
- $send = "";
- $next = "N";
- $last_member_id = 0;
- $first = "Y";
- $tpic_id = 0;
- $subject = "";
- $last_email = "";
- $article_push = array();
- $send_html = NULL;
- $send_text = NULL;
- $send = NULL;
- $send_txt = NULL;
- foreach ($emails as $e)
- {
- echo memory_get_peak_usage(). " emails ID $e->id <br>";
- if (! in_array($e->article_id, $article_push))
- {
- if ($topic_id != $e->topic_id)
- {
- $send .= '<h2>'. $e->topic_name. '</h2>';
- $send_txt = "\n". $e->topic_name. "\n \n";
- $topic_id = $e->topic_id;
- }
- $send .='<a href="'. Kohana::$config->load('general')->get('site_url'). '/emailer/check/'. $e->member_id .'_'. $e->article_id. '">'.
- $e->title.
- '</a><br><br>';
- $send_txt .= $e->title. "\n".
- Kohana::$config->load('general')->get('site_url'). '/emailer/check/'. $e->member_id .'_'. $e->article_id.
- "\n \n";
- $subject = '['. Kohana::$config->load('general')->get('site_name') . '] '. $e->title;
- $art = $e->article_id;
- $last_id = $e->id;
- $arr = array(
- "sent_day" => time(),
- );
- $sent_to_member = DB::update("emailerscheds")
- ->set($arr)
- ->where('id', '=', $e->id)
- ->execute();
- $sent_to_member = NULL;
- unset($sent_to_member);
- array_push($article_push, $e->article_id);
- }
- echo memory_get_peak_usage(). " emails after loop ID $e->id <br>";
- }
- echo memory_get_peak_usage(). " emails before saving <br>";
- //send email
- $send_html = View::factory('emailer/daily_v2');
- $send_text = View::factory('emailer/daily_text_v2');
- $send_html->send = $send;
- $send_html->member_id = $last_member_id;
- $send_html->last_id = $e->id;
- $send_text->send_text = $send_txt;
- $send_text->member_id = $last_member_id;
- $member_email = $m->email;
- $save_email = NULL;
- // $save_email = $this->emailer_sendgrid($member_email, $subject, $send_html, $send_text);
- $save_email =NULL;
- $set = array('name', 'from_email', 'email', 'subject', 'body', 'body_text', 'member_id');
- $massemail = NULL;
- $massemail = array( "", "arnold.gamboa@gmail.com",$member_email,$subject,$send_html, $send_text, $last_member_id);
- $emailsent = DB::insert('massemails', $set)->values($massemail)->execute();
- $send_html= NULL;;
- $send_text = NULL;
- $send= NULL;;
- $send_txt = NULL;
- $emailsent = NULL;
- $massemail = NULL;
- echo memory_get_peak_usage(). " after saving <br>";
- //echo $member_email. ' '. $send_text;
- // echo $send. "<br>----";
- // echo memory_get_peak_usage(). " unset email loop <br>";
- }
- $emailed = DB::update('members')
- ->set(array('emailed_am'=>"Y"))
- ->where('id','=', $m->id)
- ->execute();
- // echo memory_get_peak_usage(). " update members <br>";
- $emails = NULL;
- unset($emails);
- echo memory_get_peak_usage(). " emails DESTRUCT <br>";
- //}
- $emails = NULL;
- $members= NULL;
- unset($members);
- unset($emails);
- $m = NULL;
- unset($m);
- unset($emailsent);
- echo memory_get_peak_usage(). " members DESTRUCT <br>";
- gc_collect_cycles();
- //sleep(1);
- $x++;
- }//end of endless loop
- //echo "done";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement