Class: TopicConverter
- Inherits:
-
Object
- Object
- TopicConverter
- Defined in:
- app/models/topic_converter.rb
Instance Attribute Summary collapse
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
- #convert_to_private_message ⇒ Object
- #convert_to_public_topic(category_id = nil) ⇒ Object
-
#initialize(topic, user) ⇒ TopicConverter
constructor
A new instance of TopicConverter.
Constructor Details
#initialize(topic, user) ⇒ TopicConverter
Returns a new instance of TopicConverter.
6 7 8 9 |
# File 'app/models/topic_converter.rb', line 6 def initialize(topic, user) @topic = topic @user = user end |
Instance Attribute Details
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
4 5 6 |
# File 'app/models/topic_converter.rb', line 4 def topic @topic end |
Instance Method Details
#convert_to_private_message ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/topic_converter.rb', line 45 def Topic.transaction do was_public = !@topic.category.read_restricted @topic.update_category_topic_count_by(-1) if @topic.visible PostRevisor.new(@topic.first_post, @topic).revise!( @user, category_id: nil, archetype: Archetype., ) raise ActiveRecord::Rollback if !@topic.valid? add_allowed_users update_post_uploads_secure_status add_small_action("private_topic") Tag.update_counters(@topic., { public_topic_count: -1 }) if was_public UserProfile.remove_featured_topic_from_all_profiles(@topic) Jobs.enqueue(:topic_action_converter, topic_id: @topic.id) Jobs.enqueue(:delete_inaccessible_notifications, topic_id: @topic.id) watch_topic(@topic) end @topic end |
#convert_to_public_topic(category_id = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/topic_converter.rb', line 11 def convert_to_public_topic(category_id = nil) Topic.transaction do category_id ||= SiteSetting.uncategorized_category_id if SiteSetting.allow_uncategorized_topics @category = Category.find_by(id: category_id) if category_id @category ||= Category .where(read_restricted: false) .where.not(id: SiteSetting.uncategorized_category_id) .first PostRevisor.new(@topic.first_post, @topic).revise!( @user, category_id: @category.id, archetype: Archetype.default, ) raise ActiveRecord::Rollback if !@topic.valid? update_user_stats update_post_uploads_secure_status add_small_action("public_topic") Tag.update_counters(@topic., { public_topic_count: 1 }) if !@category.read_restricted Jobs.enqueue(:topic_action_converter, topic_id: @topic.id) Jobs.enqueue(:delete_inaccessible_notifications, topic_id: @topic.id) watch_topic(@topic) end @topic end |