From e09e8e0b76e25391288b9043439b0d5685a7617a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 19 Feb 2015 16:43:12 +0100 Subject: [PATCH] FIX: error when re-bookmarking a topic/post --- app/models/post_action.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/models/post_action.rb b/app/models/post_action.rb index e0330cc93bf..cb7cda7ece7 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -242,28 +242,26 @@ class PostAction < ActiveRecord::Base post_action_type_id: post_action_type_id } - action_attributes = { + action_attrs = { staff_took_action: staff_took_action, related_post_id: related_post_id, targets_topic: !!targets_topic } # First try to revive a trashed record - row_count = PostAction.where(where_attrs) - .with_deleted - .where("deleted_at IS NOT NULL") - .update_all(action_attributes.merge(deleted_at: nil)) + post_action = PostAction.where(where_attrs) + .with_deleted + .where("deleted_at IS NOT NULL") + .first - if row_count == 0 - post_action = create(where_attrs.merge(action_attributes)) + if post_action + post_action.recover! + post_action.save + else + post_action = create(where_attrs.merge(action_attrs)) if post_action && post_action.errors.count == 0 BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: post_action) end - else - post_action = PostAction.where(where_attrs).first - - # after_commit is not called on an 'update_all' so do the notify ourselves - post_action.notify_subscribers end # agree with other flags