FIX: do not raise error if topic not found while logging

This commit is contained in:
Arpit Jalan 2016-04-11 09:20:08 +05:30
parent 9997ab6937
commit 8da446c8bc

View File

@ -40,16 +40,17 @@ class StaffActionLogger
def log_post_deletion(deleted_post, opts={})
raise Discourse::InvalidParameters.new(:deleted_post) unless deleted_post && deleted_post.is_a?(Post)
topic = deleted_post.topic || Topic.with_deleted.find(deleted_post.topic_id)
topic = deleted_post.topic || Topic.with_deleted.find_by(id: deleted_post.topic_id)
username = deleted_post.user.try(:username) || "unknown"
name = deleted_post.user.try(:name) || "unknown"
topic_title = topic.try(:title) || "not found"
details = [
"id: #{deleted_post.id}",
"created_at: #{deleted_post.created_at}",
"user: #{username} (#{name})",
"topic: #{topic.title}",
"topic: #{topic_title}",
"post_number: #{deleted_post.post_number}",
"raw: #{deleted_post.raw}"
]