FogBugz #118: try harder to use correct e-mail address for sending birthday notifications.
This commit is contained in:
parent
0f7001d399
commit
b693145a95
1 changed files with 21 additions and 2 deletions
|
|
@ -14,6 +14,8 @@ class BirthdaysController < ApplicationController
|
|||
birthdays = get_next_weeks_birthdays
|
||||
logger.debug "birthdays.nil? = " + birthdays.nil?.to_s + "......"
|
||||
unless birthdays.nil?
|
||||
birthdays_by_email = group_birthdays_by_email(birthdays)
|
||||
|
||||
logger.debug "..... birthdays: " + birthdays.count.to_s + "......"
|
||||
birthdays.each do |bday|
|
||||
logger.info "............< do_mailing: " + bday.firstname + " " + bday.lastname + " >.............."
|
||||
|
|
@ -35,7 +37,7 @@ class BirthdaysController < ApplicationController
|
|||
n = Date.today
|
||||
e = Date.today + 7.days
|
||||
|
||||
# two cases here: now + 7days iis still the same month. or it's not.
|
||||
# two cases here: now + 7days is still the same month. or it's not.
|
||||
if n.month == e.month
|
||||
birthdays = Contact.where("birth_month = ? AND birth_day <= ? AND birth_day >= ?",
|
||||
e.month, e.day, n.day)
|
||||
|
|
@ -44,5 +46,22 @@ class BirthdaysController < ApplicationController
|
|||
e.month, e.day, n.month, n.day)
|
||||
end
|
||||
birthdays
|
||||
end
|
||||
end
|
||||
|
||||
# in: Array [contact,contact,contact,...]
|
||||
# out: Hash[email] = [contact,contact,contact,....]
|
||||
def group_birthdays_by_email(birthday_contacts)
|
||||
ret = Hash.new
|
||||
birthday_contacts.each do |contact|
|
||||
email = contact.user.email
|
||||
if ret[email].nil? then # haven't seen this email, yet
|
||||
a = Array.new
|
||||
a << contact
|
||||
ret[email] = a
|
||||
else # add contact w/ birthday for this email
|
||||
ret[email] << contact
|
||||
end
|
||||
end
|
||||
ret
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue