Skip to content

A platform for community discussion. Free, open, simple.

FIX: Rescue errors in job. (#6745)

Bianca Nenciu5bda4d26b41e
diff --git a/plugins/poll/jobs/regular/close_poll.rb b/plugins/poll/jobs/regular/close_poll.rb
index 6e75241aabf..1c3c77c9afd 100644
--- a/plugins/poll/jobs/regular/close_poll.rb
+++ b/plugins/poll/jobs/regular/close_poll.rb
@@ -14,7 +14,8 @@ module Jobs
args[:post_id],
args[:poll_name],
"closed",
- Discourse.system_user
+ Discourse.system_user,
+ false
)
end
diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb
index 9d62323c55f..b0bc4cd56d5 100644
--- a/plugins/poll/plugin.rb
+++ b/plugins/poll/plugin.rb
@@ -108,28 +108,34 @@ after_initialize do
end
end
- def toggle_status(post_id, poll_name, status, user)
+ def toggle_status(post_id, poll_name, status, user, raise_errors = true)
Poll.transaction do
post = Post.find_by(id: post_id)
# post must not be deleted
if post.nil? || post.trashed?
- raise StandardError.new I18n.t("poll.post_is_deleted")
+ raise StandardError.new I18n.t("poll.post_is_deleted") if raise_errors
+ return
end
# topic must not be archived
if post.topic&.archived
- raise StandardError.new I18n.t("poll.topic_must_be_open_to_toggle_status")
+ raise StandardError.new I18n.t("poll.topic_must_be_open_to_toggle_status") if raise_errors
+ return
end
# either staff member or OP
unless post.user_id == user&.id || user&.staff?
- raise StandardError.new I18n.t("poll.only_staff_or_op_can_toggle_status")
+ raise StandardError.new I18n.t("poll.only_staff_or_op_can_toggle_status") if raise_errors
+ return
end
poll = Poll.find_by(post_id: post_id, name: poll_name)
- raise StandardError.new I18n.t("poll.no_poll_with_this_name", name: poll_name) unless poll
+ if !poll
+ raise StandardError.new I18n.t("poll.no_poll_with_this_name", name: poll_name) if raise_errors
+ return
+ end
poll.status = status
poll.save!