/** * Process the loaded schedule events. i.e. sent the emails to the commenters. */ public function process() { // mark the processing messages as sent *before* we try to send them. // this helps prevent race condition, since time is not tied up in trying // to send e-mail before marking it as sent foreach ($this->data as $pid => $data) { $this->selectSchedule($pid); $this->setSchedule(array("sent" => 1)); } $this->save(); // go through each schedule event... foreach ($this->data as $pid => $data) { $this->selectSchedule($pid); $message_id = $data["message_id"]; $comment_id = $data["comment_id"]; $comment = get_comment($comment_id); $message = new Bbpp_ThankMeLater_Message($message_id); // try to send email if ($comment && $message->send($comment)) { } else { // email counldn't be sent... mark as such... $this->setSchedule(array("sent" => 0)); // we've tried for at least 3 hours, this mail is not going to // be sent, get rid of it. // (otherwise, we'll keep trying at the regular calls to process -- // hourly if WP-Cron works, every 15 minutes in legacy mode). if ($this->getSendTime() < time() - 3600 * 3) { $sched = new Bbpp_ThankMeLater_Schedule($data["id"]); $sched->delete(); } } } $this->save(); }