I’m writing an import script for a custom forum.
The importing of categories and users works good, but the script (using the create_posts method) is not able to build the relation between the topic and the replies.
The relevant code
//Topics
create_posts(threads, total: total) do |t|
source_user_id = @usernamesMap[t["username"]]
{
id: t["id"],
user_id: user_id_from_imported_user_id(source_user_id) || Discourse::SYSTEM_USER_ID,
raw: t["Thread_Description"],
created_at: t["created_at"],
posts_count: t["count"],
category: category_id_from_imported_category_id(t["Topic_ID"]),
title: t["title"]
}
end
// Replies
create_posts(posts, total: total) do |t|
next unless topic = topic_lookup_from_imported_post_id(t["Thread_ID"])
source_user_id = @usernamesMap[t["username"]]
opts = {
id: t['id'],
user_id: user_id_from_imported_user_id(source_user_id) || Discourse::SYSTEM_USER_ID,
raw: t["Post_Description"],
created_at: t["created_at"],
title: t["title"],
topic_id: topic_lookup_from_imported_post_id(t["Thread_ID"]), //This is not working correctly
reply_to_post_number: topic_lookup_from_imported_post_id(t["Thread_ID"])
}
end
Trying to work out how to create topic so owned by a particular user rather than adminuser
running the script.
From your post looks like you can just pass user_id to api although not documented, but it doesn’t seem to work for me. Is that the case and if so is user_id the id column of the users table or the username column?