FogBugz #135: Use more general 'birthdays in x days' methods.
This commit is contained in:
parent
7ed4c0bf6f
commit
e5b3e22df6
1 changed files with 13 additions and 29 deletions
|
|
@ -12,21 +12,8 @@ class BirthdaysController < ApplicationController
|
|||
# crontab:
|
||||
# 30 3 * * * wget --post-data '' http://contact-o-rama.de/birthdays/do_mailing
|
||||
def do_mailing
|
||||
birthdays_2d = get_birthdays_next_2d
|
||||
birthdays_7d = get_birthdays_next_7d
|
||||
logger.debug "birthdays_2d.nil? = " + birthdays_2d.nil?.to_s + "......"
|
||||
unless birthdays.nil?
|
||||
birthdays_by_email = group_birthdays_by_email(birthdays_7d)
|
||||
birthdays_by_email.each do |email, bdays|
|
||||
UserMailer.next_weeks_birthday_notification(email, bdays).deliver
|
||||
end
|
||||
|
||||
# logger.debug "..... birthdays: " + birthdays.count.to_s + "......"
|
||||
# birthdays.each do |bday|
|
||||
# logger.info "............< do_mailing: " + bday.firstname + " " + bday.lastname + " >.............."
|
||||
# UserMailer.next_weeks_birthday_notification(birthdays).deliver
|
||||
# end
|
||||
end
|
||||
do_mailing_days_in_advance(2)
|
||||
do_mailing_days_in_advance(7)
|
||||
|
||||
logger.debug "........... Mailings done (or had none to do)"
|
||||
respond_to do |format|
|
||||
|
|
@ -38,22 +25,18 @@ class BirthdaysController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def get_birthdays_next_7d
|
||||
get_birthdays_next_n_days(7)
|
||||
end
|
||||
|
||||
def get_birthdays_next_2d
|
||||
get_birthdays_next_n_days(2)
|
||||
end
|
||||
|
||||
def get_birthdays_in_7d
|
||||
get_birthdays_in_n_days(7)
|
||||
end
|
||||
|
||||
def get_birthdays_in_2d
|
||||
get_birthdays_in_n_days(2)
|
||||
def do_mailing_days_in_advance(num_days)
|
||||
birthdays = get_birthdays_in_n_days(num_days)
|
||||
logger.debug "[" + num_days.to_s + "]: birthdays.nil? = " + birthdays.nil?.to_s + "......"
|
||||
unless birthdays.nil?
|
||||
birthdays_by_email = group_birthdays_by_email(birthdays)
|
||||
birthdays_by_email.each do |email, bdays|
|
||||
UserMailer.next_weeks_birthday_notification(email, bdays, num_days).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# returns all birthdays happening during the next num_days.
|
||||
def get_birthdays_next_n_days(num_days)
|
||||
n = Date.today
|
||||
e = Date.today + num_days.days
|
||||
|
|
@ -69,6 +52,7 @@ class BirthdaysController < ApplicationController
|
|||
birthdays
|
||||
end
|
||||
|
||||
# returns all birthdays happening exactly num_days from now.
|
||||
def get_birthdays_in_n_days(num_days)
|
||||
target_date = Date.today + num_days.days
|
||||
birthdays = Contact.where("birth_month = ? AND birth_day = ?", target_date.month, target_date.day)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue