function process_mail_queue($mysqli) { $sql = " select * from sc_mail_queue where flag = 0 order by id limit 50"; $map = array(); $rows = MySQL\Helper::fetchRows($mysqli, $sql); foreach ($rows as $row) { $email = $row["email"]; $source = $row["source"]; settype($source, "integer"); $khash = md5($email . $source); $name = $row["name"]; if (!in_array($khash, $map)) { // send mail // assume error $code = 1; switch ($source) { case AppConstants::RESET_PASSWORD_MAIL: $code = WebMail::sendResetPassword($name, $email, $row["token"]); \com\indigloo\sc\mysql\Mail::toggle($email); array_push($map, $khash); break; case AppConstants::NEW_ACCOUNT_MAIL: $code = WebMail::newAccountMail($name, $email); break; } if ($code > 0) { $message = sprintf("code %s - error sending mail. aborting!", $code); throw new Exception($message); } //mail went \com\indigloo\sc\mysql\Mail::toggle($email); array_push($map, $khash); } } //:loop //delete old mails in queue $sql2 = " delete from sc_mail_queue where flag = 1 and created_on < (now() - interval 1 DAY)"; MySQL\Helper::executeSQL($mysqli, $sql2); }
function sendMail($row, $feed) { // determine if we want to send mail for this feed // #1 - who is the target for this mail? // the guy who is the "owner", e.g when I create a post // and you LIKE it, I should get a notification. // so "owner of entity" is the target of our mails. // if X created a post and Y liked it then X gets a mail // if Z likes the same post then also only X gets a mail // Y will not receive a mail. $verb = $row["verb"]; $ownerId = $row["owner_id"]; if ($verb == AppConstants::FOLLOW_VERB) { //mail target is the guy you are following $ownerId = $row["object_id"]; } // #2 : I am not interested in receiving mails where // I am the subject or doer of deed! if (!empty($ownerId) && $ownerId != $row["subject_id"]) { // #3 - get my preference for this feed $preferenceDao = new \com\indigloo\sc\dao\Preference(); $preferenceObj = $preferenceDao->get($ownerId); $flag = $this->getMailflag($preferenceObj, $verb); if ($flag) { $activityHtml = new \com\indigloo\sc\html\Activity(); $emailData = $activityHtml->getEmailData($feed); if (empty($emailData)) { $message = sprintf("ACTIVITY_ERROR : getting email data :id %d ", $row["id"]); throw new \Exception($message); } $text = $emailData["text"]; $html = $emailData["html"]; $userDao = new \com\indigloo\sc\dao\User(); $row = $userDao->getOnLoginId($ownerId); $name = $row["name"]; $email = $row["email"]; if (!empty($email)) { $code = WebMail::sendActivityMail($name, $email, $text, $html); if ($code > 0) { $message = sprintf("ACTIVITY_ERROR : sending mail : id %d ", $row["id"]); throw new \Exception($message); } } } //condition:mail_flag } //condition:owner }