A platform for community discussion. Free, open, simple.
DEV: raise an exception when trying to create a post within a transaction (#11287)
Régis Hanol7af061fafa67
diff --git a/lib/post_creator.rb b/lib/post_creator.rbindex eab06f329c6..ab3ad240f21 100644--- a/lib/post_creator.rb+++ b/lib/post_creator.rb@@ -59,21 +59,20 @@ class PostCreator# TODO: we should reload user in case it is tainted, should take in a user_id as opposed to user# If we don't do this we introduce a rather risky dependency@user = user+ @spam = false@opts = opts || {}- opts[:title] = pg_clean_up(opts[:title]) if opts[:title] && opts[:title].include?("\u0000")- opts[:raw] = pg_clean_up(opts[:raw]) if opts[:raw] && opts[:raw].include?("\u0000")- opts.delete(:reply_to_post_number) unless opts[:topic_id]++ opts[:title] = pg_clean_up(opts[:title]) if opts[:title]&.include?("\u0000")+ opts[:raw] = pg_clean_up(opts[:raw]) if opts[:raw]&.include?("\u0000")opts[:visible] = false if opts[:visible].nil? && opts[:hidden_reason_id].present?- @guardian = opts[:guardian] if opts[:guardian]- @spam = false+ opts.delete(:reply_to_post_number) unless opts[:topic_id]enddef pg_clean_up(str)str.gsub("\u0000", "")end- # True if the post was considered spamdef spam?@spamend@@ -83,7 +82,7 @@ class PostCreatorenddef guardian- @guardian ||= Guardian.new(@user)+ @guardian ||= @opts[:guardian] || Guardian.new(@user)enddef valid?@@ -200,6 +199,10 @@ class PostCreatorenddef create+ if !Rails.env.test? && ActiveRecord::Base.connection.open_transactions > 0 && !@opts[:skip_jobs]+ raise "You must use 'skip_jobs = true' when creating a post inside a transaction, otherwise jobs won't run properly."+ end+if valid?transaction dobuild_post_stats