v0.19.1 Massive improvement of topic and post migration handling with extra field population

This commit is contained in:
David Sainty 2024-06-28 16:40:37 +10:00
parent c7ce8fdf98
commit cfac3debb0

View File

@ -1,5 +1,5 @@
# gossamer threads migration-import code
# v0.19
# v0.19.1
require 'mysql2'
require 'open-uri'
@ -60,7 +60,7 @@ class GossamerForumsImporter < ImportScripts::Base
);
SQL
@db.execute <<-SQL
CREATE TABLE IF NOT EXISTS url_map (
CREATE TABLE IF NOT EXISTS url_map2 (
old_post_id INTEGER PRIMARY KEY,
new_url TEXT,
title TEXT
@ -104,7 +104,7 @@ class GossamerForumsImporter < ImportScripts::Base
# Insert a URL mapping into the SQLite database
def insert_url_mapping(old_post_id, new_url, title)
@db.execute "INSERT INTO url_map (old_post_id, new_url, title) VALUES (?, ?, ?)", [old_post_id, new_url, title]
@db.execute "INSERT INTO url_map2 (old_post_id, new_url, title) VALUES (?, ?, ?)", [old_post_id, new_url, title]
end
# Export the URL mappings to a CSV file
@ -112,7 +112,7 @@ class GossamerForumsImporter < ImportScripts::Base
CSV.open(filename, "w") do |csv|
# Add headers
csv << ["Old Post ID", "New URL", "Title"]
@db.execute("SELECT old_post_id, new_url, title FROM url_map") do |row|
@db.execute("SELECT old_post_id, new_url, title FROM url_map2") do |row|
csv << row
end
end
@ -122,7 +122,7 @@ class GossamerForumsImporter < ImportScripts::Base
# Method to create Nginx rewrite rules file
def create_nginx_rewrite_rules(filename)
File.open(filename, "w") do |file|
@db.execute("SELECT old_post_id, new_url FROM url_map") do |row|
@db.execute("SELECT old_post_id, new_url FROM url_map2") do |row|
old_post_id, new_url = row
file.puts "rewrite ^/forum/.*P#{old_post_id}/$ #{new_url} permanent;"
end