v0.23 Corner case for duplicate topic name/title, not allowed in Discourse
This commit is contained in:
parent
efb56dba7e
commit
101d7cc0cb
@ -1,5 +1,5 @@
|
|||||||
# gossamer threads migration-import code
|
# gossamer threads migration-import code
|
||||||
# v0.22.3
|
# v0.23
|
||||||
|
|
||||||
require 'mysql2'
|
require 'mysql2'
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
@ -306,6 +306,18 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
email
|
email
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_unique_title(base_title, user_id, timestamp)
|
||||||
|
unique_title = base_title
|
||||||
|
suffix = 1
|
||||||
|
|
||||||
|
while Topic.exists?(title: unique_title)
|
||||||
|
unique_title = "#{base_title} (#{suffix})"
|
||||||
|
suffix += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
unique_title
|
||||||
|
end
|
||||||
|
|
||||||
# Helper method to download an attachment / image from a URL
|
# Helper method to download an attachment / image from a URL
|
||||||
def download_attachment(url)
|
def download_attachment(url)
|
||||||
begin
|
begin
|
||||||
@ -788,7 +800,6 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
# topic_post_numbers = Hash.new { |hash, key| hash[key] = 0 }
|
# topic_post_numbers = Hash.new { |hash, key| hash[key] = 0 }
|
||||||
|
|
||||||
# Fetch the highest old_post_id from the url_map table
|
# Fetch the highest old_post_id from the url_map table
|
||||||
# FIX THIS PROPERLY
|
|
||||||
highest_old_post_id = fetch_highest_old_post_id.to_i
|
highest_old_post_id = fetch_highest_old_post_id.to_i
|
||||||
puts "Highest (OP) old_post_id in url_map: #{highest_old_post_id}"
|
puts "Highest (OP) old_post_id in url_map: #{highest_old_post_id}"
|
||||||
highest_processed_post_id = fetch_highest_processed_post_id.to_i
|
highest_processed_post_id = fetch_highest_processed_post_id.to_i
|
||||||
@ -826,9 +837,10 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
# Create the topic
|
# Create the topic
|
||||||
begin
|
begin
|
||||||
puts "#2"
|
puts "#2"
|
||||||
puts "CREATE TOPIC title #{title} discourse_user_id #{discourse_user_id} category_id #{discourse_category_id}"
|
unique_title = generate_unique_title(title, discourse_user_id, Time.at(row['post_time']))
|
||||||
|
puts "CREATE TOPIC unique_title #{unique_title} title #{title} discourse_user_id #{discourse_user_id} category_id #{discourse_category_id}"
|
||||||
topic = Topic.create!(
|
topic = Topic.create!(
|
||||||
title: title,
|
title: unique_title,
|
||||||
user_id: discourse_user_id,
|
user_id: discourse_user_id,
|
||||||
created_at: Time.at(row['post_time']),
|
created_at: Time.at(row['post_time']),
|
||||||
updated_at: Time.at(row['post_time']),
|
updated_at: Time.at(row['post_time']),
|
||||||
@ -898,7 +910,7 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
# Create URL mappings
|
# Create URL mappings
|
||||||
# old_url = "https://old/forum/#{row['forum_name']}/topics/#{row['post_id']}"
|
# old_url = "https://old/forum/#{row['forum_name']}/topics/#{row['post_id']}"
|
||||||
new_url = "https://new/t/#{topic.slug}/#{topic.id}"
|
new_url = "https://new/t/#{topic.slug}/#{topic.id}"
|
||||||
insert_url_mapping(row['post_id'], new_url, title)
|
insert_url_mapping(row['post_id'], new_url, unique_title)
|
||||||
|
|
||||||
# Update the highest processed post_id
|
# Update the highest processed post_id
|
||||||
puts "Updated highest processed post_id #{post_id}"
|
puts "Updated highest processed post_id #{post_id}"
|
||||||
|
Loading…
Reference in New Issue
Block a user