From d1608bdfe985a1b2417341e31edaa56e04a1676f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 8 Sep 2014 11:02:54 +0200 Subject: [PATCH] FIX: better error handling in vBulletin importer --- lib/cooked_post_processor.rb | 2 +- script/import_scripts/vbulletin.rb | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 208aa5d3ab0..d665e9c9080 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -213,7 +213,7 @@ class CookedPostProcessor Oneboxer.apply(@doc) { |url| Oneboxer.onebox(url, args) } # make sure we grab dimensions for oneboxed images - oneboxed_images.each { |img| puts "image: #{img["src"]}"; limit_size!(img) } + oneboxed_images.each { |img| limit_size!(img) } end def optimize_urls diff --git a/script/import_scripts/vbulletin.rb b/script/import_scripts/vbulletin.rb index 174a42d3cd3..5fc8f17a0fd 100644 --- a/script/import_scripts/vbulletin.rb +++ b/script/import_scripts/vbulletin.rb @@ -289,24 +289,29 @@ class ImportScripts::VBulletin < ImportScripts::Base puts "", "Creating groups membership..." Group.find_each do |group| - next if group.automatic + begin + next if group.automatic - puts "\t#{group.name}" + puts "\t#{group.name}" - next if GroupUser.where(group_id: group.id).count > 0 + next if GroupUser.where(group_id: group.id).count > 0 - user_ids_in_group = User.where(primary_group_id: group.id).pluck(:id).to_a - next if user_ids_in_group.size == 0 + user_ids_in_group = User.where(primary_group_id: group.id).pluck(:id).to_a + next if user_ids_in_group.size == 0 - values = user_ids_in_group.map { |user_id| "(#{group.id}, #{user_id})" }.join(",") + values = user_ids_in_group.map { |user_id| "(#{group.id}, #{user_id}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)" }.join(",") - User.exec_sql <<-SQL - BEGIN; - INSERT INTO group_users (group_id, user_id) VALUES #{values}; - COMMIT; - SQL + User.exec_sql <<-SQL + BEGIN; + INSERT INTO group_users (group_id, user_id, created_at, updated_at) VALUES #{values}; + COMMIT; + SQL - Group.reset_counters(group.id, :group_users) + Group.reset_counters(group.id, :group_users) + rescue Exception => e + puts e.message + puts e.backtrace.join("\n") + end end end