A platform for community discussion. Free, open, simple.
FIX: improved category merging in discourse_merger. Use full paths to look for uniqueness instead of category names.
Neil Lalonde8af6d8189186
diff --git a/script/bulk_import/discourse_merger.rb b/script/bulk_import/discourse_merger.rbindex 14cf5a1fdf3..3d0f4131c7e 100644--- a/script/bulk_import/discourse_merger.rb+++ b/script/bulk_import/discourse_merger.rb@@ -177,9 +177,25 @@ class BulkImport::DiscourseMerger < BulkImport::Basesql = "COPY categories (#{columns.map { |c| "\"#{c}\"" }.join(', ')}) FROM STDIN"@raw_connection.copy_data(sql, @encoder) do- source_raw_connection.exec("SELECT #{columns.map { |c| "\"#{c}\"" }.join(', ')} FROM categories").each do |row|-- if existing = Category.where(name: row['name']).first+ source_raw_connection.exec(+ "SELECT concat('/c/', x.parent_slug, '/', x.slug) as path,+ #{columns.map { |c| "c.\"#{c}\"" }.join(', ')}+ FROM categories c+ INNER JOIN (+ SELECT c1.id AS id,+ c2.slug AS parent_slug,+ c1.slug AS slug+ FROM categories c1+ LEFT OUTER JOIN categories c2 ON c1.parent_category_id = c2.id+ ) x ON c.id = x.id"+ ).each do |row|++ source_category_path = row.delete('path')&.squeeze('/')++ existing = Category.where(slug: row['slug']).first+ parent_slug = existing&.parent_category&.slug+ if existing &&+ source_category_path == "/c/#{parent_slug}/#{existing.slug}".squeeze('/')@categories[row['id']] = existing.idnextend