mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 03:09:29 +08:00
FIX: error when re-bookmarking a topic/post
This commit is contained in:
parent
873f6b7487
commit
e09e8e0b76
|
@ -242,28 +242,26 @@ class PostAction < ActiveRecord::Base
|
||||||
post_action_type_id: post_action_type_id
|
post_action_type_id: post_action_type_id
|
||||||
}
|
}
|
||||||
|
|
||||||
action_attributes = {
|
action_attrs = {
|
||||||
staff_took_action: staff_took_action,
|
staff_took_action: staff_took_action,
|
||||||
related_post_id: related_post_id,
|
related_post_id: related_post_id,
|
||||||
targets_topic: !!targets_topic
|
targets_topic: !!targets_topic
|
||||||
}
|
}
|
||||||
|
|
||||||
# First try to revive a trashed record
|
# First try to revive a trashed record
|
||||||
row_count = PostAction.where(where_attrs)
|
post_action = PostAction.where(where_attrs)
|
||||||
.with_deleted
|
.with_deleted
|
||||||
.where("deleted_at IS NOT NULL")
|
.where("deleted_at IS NOT NULL")
|
||||||
.update_all(action_attributes.merge(deleted_at: nil))
|
.first
|
||||||
|
|
||||||
if row_count == 0
|
if post_action
|
||||||
post_action = create(where_attrs.merge(action_attributes))
|
post_action.recover!
|
||||||
|
post_action.save
|
||||||
|
else
|
||||||
|
post_action = create(where_attrs.merge(action_attrs))
|
||||||
if post_action && post_action.errors.count == 0
|
if post_action && post_action.errors.count == 0
|
||||||
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: post_action)
|
BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: post_action)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# agree with other flags
|
# agree with other flags
|
||||||
|
|
Loading…
Reference in New Issue
Block a user