DEV: Add support for various fields in generic bulk importer (#27114)

* user_profiles - `location`
* users - `date_of_birth`
* topics - `pinned_at`, `pinned_until`, `pinned_globally`

This also include changes to correctly import PMs. Currently PM topics
are skipped because of a check in `import_users` step which requires `category_id`
to be present.
This commit is contained in:
Selase Krakani 2024-05-24 13:46:06 +02:00 committed by GitHub
parent d5066336ec
commit 949c70372c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View File

@ -589,6 +589,8 @@ class BulkImport::Base
visible
closed
pinned_at
pinned_until
pinned_globally
views
subtype
created_at

View File

@ -442,6 +442,7 @@ class BulkImport::Generic < BulkImport::Base
suspended_at: suspended_at,
suspended_till: suspended_till,
registration_ip_address: row["registration_ip_address"],
date_of_birth: to_date(row["date_of_birth"]),
}
end
@ -473,9 +474,8 @@ class BulkImport::Generic < BulkImport::Base
puts "", "Importing user profiles..."
users = query(<<~SQL)
SELECT id, bio
SELECT id, bio, location
FROM users
WHERE bio IS NOT NULL
ORDER BY id
SQL
@ -485,7 +485,7 @@ class BulkImport::Generic < BulkImport::Base
user_id = user_id_from_imported_id(row["id"])
next if user_id && existing_user_ids.include?(user_id)
{ user_id: user_id, bio_raw: row["bio"] }
{ user_id: user_id, bio_raw: row["bio"], location: row["location"] }
end
users.close
@ -654,11 +654,10 @@ class BulkImport::Generic < BulkImport::Base
SQL
create_topics(topics) do |row|
unless row["category_id"] && (category_id = category_id_from_imported_id(row["category_id"]))
next
end
category_id = category_id_from_imported_id(row["category_id"]) if row["category_id"].present?
next if topic_id_from_imported_id(row["id"]).present?
next if row["private_message"].blank? && category_id.nil?
{
archetype: row["private_message"] ? Archetype.private_message : Archetype.default,
@ -670,6 +669,9 @@ class BulkImport::Generic < BulkImport::Base
closed: to_boolean(row["closed"]),
views: row["views"],
subtype: row["subtype"],
pinned_at: to_datetime(row["pinned_at"]),
pinned_until: to_datetime(row["pinned_until"]),
pinned_globally: to_boolean(row["pinned_globally"]),
}
end