diff --git a/app/models/queued_post.rb b/app/models/queued_post.rb index 7e2e65cd7c4..50f2997541b 100644 --- a/app/models/queued_post.rb +++ b/app/models/queued_post.rb @@ -62,7 +62,12 @@ class QueuedPost < ActiveRecord::Base def approve!(approved_by) created_post = nil - creator = PostCreator.new(user, create_options.merge(skip_validations: true, skip_jobs: true)) + creator = PostCreator.new(user, create_options.merge( + skip_validations: true, + skip_jobs: true, + skip_events: true + )) + QueuedPost.transaction do change_to!(:approved, approved_by) @@ -77,6 +82,7 @@ class QueuedPost < ActiveRecord::Base # Do sidekiq work outside of the transaction creator.enqueue_jobs + creator.trigger_after_events DiscourseEvent.trigger(:approved_post, self, created_post) created_post diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 52e7830a77c..4209d245959 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -188,7 +188,7 @@ class PostCreator enqueue_jobs unless @opts[:skip_jobs] BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post) - trigger_after_events(@post) + trigger_after_events unless opts[:skip_events] auto_close unless @opts[:import_mode] end @@ -219,6 +219,11 @@ class PostCreator ).enqueue_jobs end + def trigger_after_events + DiscourseEvent.trigger(:topic_created, @post.topic, @opts, @user) unless @opts[:topic_id] + DiscourseEvent.trigger(:post_created, @post, @opts, @user) + end + def self.track_post_stats Rails.env != "test".freeze || @track_post_stats end @@ -284,11 +289,6 @@ class PostCreator end end - def trigger_after_events(post) - DiscourseEvent.trigger(:topic_created, post.topic, @opts, @user) unless @opts[:topic_id] - DiscourseEvent.trigger(:post_created, post, @opts, @user) - end - def auto_close if @post.topic.private_message? && !@post.topic.closed &&