From eecc573fbc45d472ca3c5d3168cf6b1c7764f40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 21 Jan 2015 09:36:46 +0100 Subject: [PATCH] FIX: don't break import when raw can't be preprocessed (vBulletin importer) --- script/import_scripts/vbulletin.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/script/import_scripts/vbulletin.rb b/script/import_scripts/vbulletin.rb index dda4f296711..5b755156d70 100644 --- a/script/import_scripts/vbulletin.rb +++ b/script/import_scripts/vbulletin.rb @@ -210,6 +210,8 @@ class ImportScripts::VBulletin < ImportScripts::Base break if topics.size < 1 create_posts(topics, total: topic_count, offset: offset) do |topic| + raw = preprocess_post_raw(topic["raw"]) rescue nil + next if raw.blank? topic_id = "thread-#{topic["threadid"]}" @closed_topic_ids << topic_id if topic["open"] == "0" t = { @@ -217,7 +219,7 @@ class ImportScripts::VBulletin < ImportScripts::Base user_id: user_id_from_imported_user_id(topic["postuserid"]) || Discourse::SYSTEM_USER_ID, title: @htmlentities.decode(topic["title"]).strip[0...255], category: category_from_imported_category_id(topic["forumid"]).try(:name), - raw: preprocess_post_raw(topic["raw"]), + raw: raw, created_at: parse_timestamp(topic["dateline"]), visible: topic["visible"].to_i == 1, views: topic["views"], @@ -231,6 +233,9 @@ class ImportScripts::VBulletin < ImportScripts::Base def import_posts puts "", "importing posts..." + # make sure `firstpostid` is indexed + mysql_query("CREATE INDEX firstpostid_index ON thread (firstpostid)") + post_count = mysql_query("SELECT COUNT(postid) count FROM post WHERE postid NOT IN (SELECT firstpostid FROM thread)").first["count"] batches(BATCH_SIZE) do |offset| @@ -246,12 +251,14 @@ class ImportScripts::VBulletin < ImportScripts::Base break if posts.size < 1 create_posts(posts, total: post_count, offset: offset) do |post| + raw = preprocess_post_raw(post["raw"]) rescue nil + next if raw.blank? next unless topic = topic_lookup_from_imported_post_id("thread-#{post["threadid"]}") p = { id: post["postid"], user_id: user_id_from_imported_user_id(post["userid"]) || Discourse::SYSTEM_USER_ID, topic_id: topic[:topic_id], - raw: preprocess_post_raw(post["raw"]), + raw: raw, created_at: parse_timestamp(post["dateline"]), hidden: post["visible"].to_i == 0, }