diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2015-05-23 20:12:37 +0300 |
---|---|---|
committer | Dennis Schubert <mail@dennis-schubert.de> | 2015-05-24 03:30:02 +0300 |
commit | 8531b160a6c8407749411d44ac6bf72ca40408c1 (patch) | |
tree | 0e6297d7cd487c77c8ea50d23a7f8bf39b8b05c0 /app/mailers | |
parent | 68f7208ff5e30e1870d7234efe0316af9db6793d (diff) |
gracefully handle when a like is already deleted again
closes #5983
Diffstat (limited to 'app/mailers')
-rw-r--r-- | app/mailers/notification_mailers/base.rb | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/app/mailers/notification_mailers/base.rb b/app/mailers/notification_mailers/base.rb index 086228b06..b3cc8136a 100644 --- a/app/mailers/notification_mailers/base.rb +++ b/app/mailers/notification_mailers/base.rb @@ -8,8 +8,8 @@ module NotificationMailers def initialize(recipient_id, sender_id=nil, *args) @headers = {} - @recipient = User.find_by_id(recipient_id) - @sender = Person.find_by_id(sender_id) if sender_id.present? + @recipient = User.find(recipient_id) + @sender = Person.find(sender_id) if sender_id.present? log_mail(recipient_id, sender_id, self.class.to_s.underscore) @@ -29,11 +29,12 @@ module NotificationMailers end private + def default_headers headers = { - :from => AppConfig.mail.sender_address.get, - :host => "#{AppConfig.pod_uri.host}", - :to => name_and_address(@recipient.name, @recipient.email) + from: AppConfig.mail.sender_address.get, + host: "#{AppConfig.pod_uri.host}", + to: name_and_address(@recipient.name, @recipient.email) } headers[:from] = "\"#{@sender.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>" if @sender.present? @@ -46,14 +47,15 @@ module NotificationMailers end def log_mail(recipient_id, sender_id, type) - log_string = "event=mail mail_type=#{type} recipient_id=#{recipient_id} sender_id=#{sender_id}" - if @recipient && @sender - log_string << "models_found=true sender_handle=#{@sender.diaspora_handle} recipient_handle=#{@recipient.diaspora_handle}" - else - log_string << "models_found=false" - end + log_string = "event=mail mail_type=#{type} recipient_id=#{recipient_id} sender_id=#{sender_id} " \ + " recipient_handle=#{@recipient.diaspora_handle}" + log_string << " sender_handle=#{@sender.diaspora_handle}" if sender_id.present? + + logger.info(log_string) + end - Rails.logger.info(log_string) + def logger + @logger ||= ::Logging::Logger[self] end end end |