Fix rubocop offenses.

This commit is contained in:
Guo Xiang Tan 2017-08-02 15:09:07 +09:00
parent 17dda66400
commit 639784ec81
1 changed files with 30 additions and 28 deletions

View File

@ -17,7 +17,7 @@ after_initialize do
unless $redis.get('solved_already_upgraded') unless $redis.get('solved_already_upgraded')
unless UserAction.where(action_type: UserAction::SOLVED).exists? unless UserAction.where(action_type: UserAction::SOLVED).exists?
Rails.logger.info("Upgrading storage for solved") Rails.logger.info("Upgrading storage for solved")
sql =<<SQL sql = <<SQL
INSERT INTO user_actions(action_type, INSERT INTO user_actions(action_type,
user_id, user_id,
target_topic_id, target_topic_id,
@ -87,28 +87,30 @@ SQL
post.save! post.save!
if defined?(UserAction::SOLVED) if defined?(UserAction::SOLVED)
UserAction.log_action!(action_type: UserAction::SOLVED, UserAction.log_action!(
user_id: post.user_id, action_type: UserAction::SOLVED,
acting_user_id: guardian.user.id, user_id: post.user_id,
target_post_id: post.id, acting_user_id: guardian.user.id,
target_topic_id: post.topic_id) target_post_id: post.id,
target_topic_id: post.topic_id
)
end end
unless current_user.id == post.user_id unless current_user.id == post.user_id
Notification.create!(
Notification.create!(notification_type: Notification.types[:custom], notification_type: Notification.types[:custom],
user_id: post.user_id, user_id: post.user_id,
topic_id: post.topic_id, topic_id: post.topic_id,
post_number: post.post_number, post_number: post.post_number,
data: { data: {
message: 'solved.accepted_notification', message: 'solved.accepted_notification',
display_username: current_user.username, display_username: current_user.username,
topic_title: topic.title topic_title: topic.title
}.to_json }.to_json
) )
end end
if (auto_close_hours = SiteSetting.solved_topics_auto_close_hours) > 0 and !topic.closed if (auto_close_hours = SiteSetting.solved_topics_auto_close_hours) > (0) && !topic.closed
topic.set_or_create_timer( topic.set_or_create_timer(
TopicTimer.types[:close], TopicTimer.types[:close],
auto_close_hours, auto_close_hours,
@ -187,17 +189,17 @@ SQL
accepted_solutions = TopicCustomField.where(name: "accepted_answer_post_id") accepted_solutions = TopicCustomField.where(name: "accepted_answer_post_id")
accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id = ?", report.category_id) if report.category_id accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id = ?", report.category_id) if report.category_id
accepted_solutions.where("topic_custom_fields.created_at >= ?", report.start_date) accepted_solutions.where("topic_custom_fields.created_at >= ?", report.start_date)
.where("topic_custom_fields.created_at <= ?", report.end_date) .where("topic_custom_fields.created_at <= ?", report.end_date)
.group("DATE(topic_custom_fields.created_at)") .group("DATE(topic_custom_fields.created_at)")
.order("DATE(topic_custom_fields.created_at)") .order("DATE(topic_custom_fields.created_at)")
.count .count
.each do |date, count| .each do |date, count|
report.data << { x: date, y: count } report.data << { x: date, y: count }
end end
report.total = accepted_solutions.count report.total = accepted_solutions.count
report.prev30Days = accepted_solutions.where("topic_custom_fields.created_at >= ?", report.start_date - 30.days) report.prev30Days = accepted_solutions.where("topic_custom_fields.created_at >= ?", report.start_date - 30.days)
.where("topic_custom_fields.created_at <= ?", report.start_date) .where("topic_custom_fields.created_at <= ?", report.start_date)
.count .count
end end
end end
@ -243,9 +245,9 @@ SQL
def accepted_answer_post_info def accepted_answer_post_info
# TODO: we may already have it in the stream ... so bypass query here # TODO: we may already have it in the stream ... so bypass query here
postInfo = Post.where(id: accepted_answer_post_id, topic_id: object.topic.id) postInfo = Post.where(id: accepted_answer_post_id, topic_id: object.topic.id)
.joins(:user) .joins(:user)
.pluck('post_number', 'username', 'cooked') .pluck('post_number', 'username', 'cooked')
.first .first
if postInfo if postInfo
postInfo[2] = PrettyText.excerpt(postInfo[2], SiteSetting.solved_quote_length) postInfo[2] = PrettyText.excerpt(postInfo[2], SiteSetting.solved_quote_length)