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.rbindex 6e75241aabf..1c3c77c9afd 100644--- a/plugins/poll/jobs/regular/close_poll.rb+++ b/plugins/poll/jobs/regular/close_poll.rb@@ -14,7 +14,8 @@ module Jobsargs[:post_id],args[:poll_name],"closed",- Discourse.system_user+ Discourse.system_user,+ false)enddiff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rbindex 9d62323c55f..b0bc4cd56d5 100644--- a/plugins/poll/plugin.rb+++ b/plugins/poll/plugin.rb@@ -108,28 +108,34 @@ after_initialize doendend- def toggle_status(post_id, poll_name, status, user)+ def toggle_status(post_id, poll_name, status, user, raise_errors = true)Poll.transaction dopost = Post.find_by(id: post_id)# post must not be deletedif 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+ returnend# topic must not be archivedif 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+ returnend# either staff member or OPunless 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+ returnendpoll = 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+ endpoll.status = statuspoll.save!