Class: PostMover
- Inherits:
-
Object
- Object
- PostMover
- Defined in:
- app/models/post_mover.rb
Instance Attribute Summary collapse
-
#destination_topic ⇒ Object
readonly
Returns the value of attribute destination_topic.
-
#original_topic ⇒ Object
readonly
Returns the value of attribute original_topic.
-
#post_ids ⇒ Object
readonly
Returns the value of attribute post_ids.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(original_topic, user, post_ids, move_to_pm: false, options: {}) ⇒ PostMover
constructor
options: freeze_original: :boolean - if true, the original topic will be frozen but not deleted and posts will be “copied” to topic.
- #to_new_topic(title, category_id = nil, tags = nil) ⇒ Object
- #to_topic(id, participants: nil, chronological_order: false) ⇒ Object
Constructor Details
#initialize(original_topic, user, post_ids, move_to_pm: false, options: {}) ⇒ PostMover
options: freeze_original: :boolean - if true, the original topic will be frozen but not deleted and posts will be “copied” to topic
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/post_mover.rb', line 12 def initialize(original_topic, user, post_ids, move_to_pm: false, options: {}) @original_topic = original_topic @original_topic_title = original_topic.title @user = user @post_ids = post_ids # For now we store a copy of post_ids. If `freeze_original` is present, we will have new post_ids. # When we create the new posts, we will pluck out post_ids out of this and replace with updated ids. @post_ids_after_move = post_ids @move_to_pm = move_to_pm @options = end |
Instance Attribute Details
#destination_topic ⇒ Object (readonly)
Returns the value of attribute destination_topic.
4 5 6 |
# File 'app/models/post_mover.rb', line 4 def destination_topic @destination_topic end |
#original_topic ⇒ Object (readonly)
Returns the value of attribute original_topic.
4 5 6 |
# File 'app/models/post_mover.rb', line 4 def original_topic @original_topic end |
#post_ids ⇒ Object (readonly)
Returns the value of attribute post_ids.
4 5 6 |
# File 'app/models/post_mover.rb', line 4 def post_ids @post_ids end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'app/models/post_mover.rb', line 4 def user @user end |
Class Method Details
Instance Method Details
#to_new_topic(title, category_id = nil, tags = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/post_mover.rb', line 41 def to_new_topic(title, category_id = nil, = nil) @move_type = PostMover.move_types[:new_topic] @creating_new_topic = true post = Post.find_by(id: post_ids.first) raise Discourse::InvalidParameters unless post archetype = @move_to_pm ? Archetype. : Archetype.default topic = Topic.transaction do new_topic = Topic.create!( user: post.user, title: title, category_id: category_id, created_at: post.created_at, archetype: archetype, ) DiscourseTagging.tag_topic_by_names(new_topic, Guardian.new(user), ) move_posts_to new_topic watch_new_topic update_topic_excerpt new_topic new_topic end enqueue_jobs(topic) topic end |
#to_topic(id, participants: nil, chronological_order: false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/post_mover.rb', line 24 def to_topic(id, participants: nil, chronological_order: false) @move_type = PostMover.move_types[:existing_topic] @creating_new_topic = false @chronological_order = chronological_order topic = Topic.find_by_id(id) if topic.archetype != @original_topic.archetype && [@original_topic.archetype, topic.archetype].include?(Archetype.) raise Discourse::InvalidParameters end Topic.transaction { move_posts_to topic } add_allowed_users(participants) if participants.present? && @move_to_pm enqueue_jobs(topic) topic end |