Log when and why an email was not sent in email_logs

This commit is contained in:
Neil Lalonde
2014-02-14 13:06:21 -05:00
parent 42fb9d4fb1
commit 35dae76bbd
15 changed files with 164 additions and 37 deletions

View File

@ -6,13 +6,16 @@ class EmailLog < ActiveRecord::Base
belongs_to :post
belongs_to :topic
scope :sent, -> { where(skipped: false) }
scope :skipped, -> { where(skipped: true) }
after_create do
# Update last_emailed_at if the user_id is present
User.where(id: user_id).update_all("last_emailed_at = CURRENT_TIMESTAMP") if user_id.present?
# Update last_emailed_at if the user_id is present and email was sent
User.where(id: user_id).update_all("last_emailed_at = CURRENT_TIMESTAMP") if user_id.present? and !skipped
end
def self.count_per_day(sinceDaysAgo = 30)
where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
where('created_at > ? and skipped = false', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count
end
def self.for(reply_key)