Description:
oops, tiny bug in 1.00 that kept it from finding subscribers to email...
Box Code:
my @date = localtime();
# get user list
my $where = "userprefs.prefname = 'queue_digest' AND userprefs.uid = users.uid AND userprefs.prefvalue = 'on'";
my ($rv, $sth) = $S->db_select({
WHAT => "userprefs.uid, userprefs.prefvalue, users.realemail, users.nickname",
FROM => "userprefs, users",
WHERE => $where
});
my @users;
while (my($uid, $prefvalue, $email, $nick) = $sth->fetchrow()) {
push(@users, {uid => $uid, nick => $nick, email => $email});
}
$sth->finish();
# Get digest contents
my $rollback = 60 * 24;
# one day; no weekly option for the queue
my $data = "";
my $excl_sql = $S->excluded_from_all_stories();
my ($rv, $sth) = $S->db_select({
FROM => 'stories LEFT JOIN users ON stories.aid = users.uid',
WHAT => 'sid, tid, aid, users.nickname AS nick, time, title, dept, introtext, section',
WHERE => "displaystatus = '-2' $excl_sql AND time >= DATE_SUB(NOW(), INTERVAL $rollback minute)",
ORDER_BY => 'time desc'
});
while (my $storydata = $sth->fetchrow_hashref()) {
$storydata->{nick} = $S->{UI}->{VARS}->{anon_user_nick} if $storydata->{aid} == -1;
$data .= $S->_cron_digest_format_stories($storydata);
warn "(queue_digest) sending story $storydata->{title}";
}
$sth->finish();
return 1 unless $data;
# no emails sent if no stories return
my $header = $S->{UI}->{BLOCKS}->{queue_digest_header} \|\| $S->{UI}->{BLOCKS}->{queue_digest_headerfooter};
my $footer = $S->{UI}->{BLOCKS}->{queue_digest_footer} \|\| $S->{UI}->{BLOCKS}->{queue_digest_headerfooter};
my $mail = join("\n\n",$header,$data,$footer);
my $errors;
foreach my $user (@users) {
# send each user the email
my $usermail = $S->interpolate($mail,$user);
my $ret = $S->mail($user->{email}, $S->{UI}->{BLOCKS}->{queue_digest_subject}, $usermail);
$errors .= $ret if ( $ret != 1 );
}
return $errors if $errors;
return 1;
|