|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module Migrations::Converters::Discourse |
| 4 | + class Groups < ::Migrations::Converters::Base::ProgressStep |
| 5 | + attr_accessor :source_db |
| 6 | + |
| 7 | + def max_progress |
| 8 | + @source_db.count <<~SQL |
| 9 | + SELECT COUNT(*) FROM groups |
| 10 | + SQL |
| 11 | + end |
| 12 | + |
| 13 | + def items |
| 14 | + @source_db.query <<~SQL |
| 15 | + SELECT g.*, |
| 16 | + u.id AS original_flair_upload_id, |
| 17 | + u.url AS flair_path, |
| 18 | + u.original_filename AS flair_filename, |
| 19 | + CASE WHEN g.automatic THEN g.name ELSE NULL END AS existing_id |
| 20 | + FROM groups g |
| 21 | + LEFT JOIN uploads u ON g.flair_upload_id = u.id |
| 22 | + SQL |
| 23 | + end |
| 24 | + |
| 25 | + def process_item(item) |
| 26 | + flair_upload = |
| 27 | + if item[:original_flair_upload_id].present? |
| 28 | + IntermediateDB::Upload.create_for_file( |
| 29 | + path: item[:flair_path], |
| 30 | + filename: item[:flair_filename], |
| 31 | + ) |
| 32 | + end |
| 33 | + |
| 34 | + IntermediateDB::Group.create( |
| 35 | + original_id: item[:id], |
| 36 | + allow_membership_requests: item[:allow_membership_requests], |
| 37 | + allow_unknown_sender_topic_replies: item[:allow_unknown_sender_topic_replies], |
| 38 | + automatic: item[:automatic], |
| 39 | + automatic_membership_email_domains: item[:automatic_membership_email_domains], |
| 40 | + bio_raw: item[:bio_raw], |
| 41 | + created_at: item[:created_at], |
| 42 | + default_notification_level: item[:default_notification_level], |
| 43 | + existing_id: item[:existing_id], |
| 44 | + flair_bg_color: item[:flair_bg_color], |
| 45 | + flair_color: item[:flair_color], |
| 46 | + flair_icon: item[:flair_icon], |
| 47 | + flair_upload_id: flair_upload&.id, |
| 48 | + full_name: item[:full_name], |
| 49 | + grant_trust_level: item[:grant_trust_level], |
| 50 | + members_visibility_level: item[:members_visibility_level], |
| 51 | + membership_request_template: item[:membership_request_template], |
| 52 | + mentionable_level: item[:mentionable_level], |
| 53 | + messageable_level: item[:messageable_level], |
| 54 | + name: item[:name], |
| 55 | + primary_group: item[:primary_group], |
| 56 | + public_admission: item[:public_admission], |
| 57 | + public_exit: item[:public_exit], |
| 58 | + title: item[:title], |
| 59 | + visibility_level: item[:visibility_level], |
| 60 | + ) |
| 61 | + end |
| 62 | + end |
| 63 | +end |
0 commit comments