v0.11 Add support for SQLite DB and CSV file generation for mapping of old to new OP / new topic URLs
This commit is contained in:
parent
a6d48e825d
commit
1e62f5ee09
@ -1,5 +1,5 @@
|
|||||||
# gossamer threads migration-import code
|
# gossamer threads migration-import code
|
||||||
# v0.10
|
# v0.11
|
||||||
|
|
||||||
require 'mysql2'
|
require 'mysql2'
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
@ -58,6 +58,13 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
real_name TEXT
|
real_name TEXT
|
||||||
);
|
);
|
||||||
SQL
|
SQL
|
||||||
|
@db.execute <<-SQL
|
||||||
|
CREATE TABLE IF NOT EXISTS url_map (
|
||||||
|
old_url TEXT,
|
||||||
|
new_url TEXT,
|
||||||
|
title TEXT
|
||||||
|
);
|
||||||
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
def insert_user_id_mapping(old_user_id, new_user_id)
|
def insert_user_id_mapping(old_user_id, new_user_id)
|
||||||
@ -91,6 +98,24 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
csv << row
|
csv << row
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
puts "Exported changed username mappings to #{filename}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Insert a URL mapping into the SQLite database
|
||||||
|
def insert_url_mapping(old_url, new_url, title)
|
||||||
|
@db.execute "INSERT INTO url_map (old_url, new_url, title) VALUES (?, ?, ?, ?, ?)", [old_url, new_url, title]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Export the URL mappings to a CSV file
|
||||||
|
def export_url_mapping_to_csv(filename)
|
||||||
|
CSV.open(filename, "wb") do |csv|
|
||||||
|
# Add headers
|
||||||
|
csv << ["Old URL", "New URL", "Title"]
|
||||||
|
@db.execute("SELECT * FROM url_map") do |row|
|
||||||
|
csv << row
|
||||||
|
end
|
||||||
|
end
|
||||||
|
puts "Exported URL mappings to #{filename}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -469,6 +494,12 @@ def import_topics_and_posts
|
|||||||
)
|
)
|
||||||
post.custom_fields['original_gossamer_id'] = row['post_id']
|
post.custom_fields['original_gossamer_id'] = row['post_id']
|
||||||
post.save!
|
post.save!
|
||||||
|
|
||||||
|
# Create URL mappings
|
||||||
|
old_url = "https://old/forum/#{row['forum_name']}/topics/#{row['post_id']}"
|
||||||
|
new_url = "https://new/t/#{topic.slug}/#{topic.id}"
|
||||||
|
insert_url_mapping(old_url, new_url, title)
|
||||||
|
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
puts "Error importing topic with post_id #{row['post_id']}: #{e.message}"
|
puts "Error importing topic with post_id #{row['post_id']}: #{e.message}"
|
||||||
end
|
end
|
||||||
@ -589,15 +620,26 @@ end
|
|||||||
|
|
||||||
# Main method to perform the import
|
# Main method to perform the import
|
||||||
def perform_import
|
def perform_import
|
||||||
|
# Secret trick to disable RateLimiting support in Discourse
|
||||||
RateLimiter.disable
|
RateLimiter.disable
|
||||||
puts "Starting Gossamer Forums import..."
|
|
||||||
# import_users
|
# Set our unique timestamp for this migration run
|
||||||
# export_username_mapping_to_csv
|
timestamp = Time.now.strftime("-%y%m%d%H%M%S")
|
||||||
# import_categories
|
|
||||||
# import_topics_and_posts
|
puts "Starting Gossamer Forums import... #{timestamp}"
|
||||||
|
|
||||||
|
import_users
|
||||||
|
export_username_mapping_to_csv("gossamer-migration-username-mapping#{timestamp}")
|
||||||
|
|
||||||
|
import_categories
|
||||||
|
import_topics_and_posts
|
||||||
|
export_url_mapping_to_csv("gossamer-migration-url-mapping#{timestamp}")
|
||||||
|
|
||||||
import_personal_messages
|
import_personal_messages
|
||||||
|
|
||||||
# import_attachments
|
# import_attachments
|
||||||
puts "Gossamer Forums import complete!"
|
|
||||||
|
puts "Gossamer Forums import complete! #{timestamp}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user