From bed9135f401ce52cb4f740ab3c1c6d40abd07965 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Wed, 13 Jan 2016 22:46:03 +0100 Subject: [PATCH 1/2] Failed file upload shouldn't crash phpBB3 importer --- .../import_scripts/phpbb3/importers/attachment_importer.rb | 2 +- script/import_scripts/phpbb3/importers/avatar_importer.rb | 5 +++-- script/import_scripts/phpbb3/support/smiley_processor.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/script/import_scripts/phpbb3/importers/attachment_importer.rb b/script/import_scripts/phpbb3/importers/attachment_importer.rb index e41ca7a1209..37f7695c9c7 100644 --- a/script/import_scripts/phpbb3/importers/attachment_importer.rb +++ b/script/import_scripts/phpbb3/importers/attachment_importer.rb @@ -22,7 +22,7 @@ module ImportScripts::PhpBB3 filename = CGI.unescapeHTML(row[:real_filename]) upload = @uploader.create_upload(user_id, path, filename) - if upload.nil? || !upload.valid? + if upload.nil? || !upload.persisted? puts "Failed to upload #{path}" puts upload.errors.inspect if upload else diff --git a/script/import_scripts/phpbb3/importers/avatar_importer.rb b/script/import_scripts/phpbb3/importers/avatar_importer.rb index 3db8b701004..825bc445faf 100644 --- a/script/import_scripts/phpbb3/importers/avatar_importer.rb +++ b/script/import_scripts/phpbb3/importers/avatar_importer.rb @@ -24,14 +24,15 @@ module ImportScripts::PhpBB3 filename = "avatar#{File.extname(path)}" upload = @uploader.create_upload(user.id, path, filename) - if upload.persisted? + if upload.present? && upload.persisted? user.import_mode = false user.create_user_avatar user.import_mode = true user.user_avatar.update(custom_upload_id: upload.id) user.update(uploaded_avatar_id: upload.id) else - Rails.logger.error("Could not persist avatar for user #{user.username}") + puts "Failed to upload avatar for user #{user.username}: #{path}" + puts upload.errors.inspect if upload end rescue SystemCallError => err Rails.logger.error("Could not import avatar for user #{user.username}: #{err.message}") diff --git a/script/import_scripts/phpbb3/support/smiley_processor.rb b/script/import_scripts/phpbb3/support/smiley_processor.rb index f79a24c4659..1737e446ce9 100644 --- a/script/import_scripts/phpbb3/support/smiley_processor.rb +++ b/script/import_scripts/phpbb3/support/smiley_processor.rb @@ -65,7 +65,7 @@ module ImportScripts::PhpBB3 filename = File.basename(path) upload = @uploader.create_upload(Discourse::SYSTEM_USER_ID, path, filename) - if upload.nil? || !upload.valid? + if upload.nil? || !upload.persisted? puts "Failed to upload #{path}" puts upload.errors.inspect if upload html = nil From 1164129edcf82296bb6492b35ea99e3361a5fa2c Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Wed, 13 Jan 2016 22:57:57 +0100 Subject: [PATCH 2/2] Better error handling for polls imported from phpBB3 --- script/import_scripts/phpbb3/importers/poll_importer.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/script/import_scripts/phpbb3/importers/poll_importer.rb b/script/import_scripts/phpbb3/importers/poll_importer.rb index b3099f20c1b..e6bae5b40b7 100644 --- a/script/import_scripts/phpbb3/importers/poll_importer.rb +++ b/script/import_scripts/phpbb3/importers/poll_importer.rb @@ -22,6 +22,8 @@ module ImportScripts::PhpBB3 poll_text = get_poll_text(options, poll) extracted_poll = extract_default_poll(topic_id, poll_text) + return if extracted_poll.nil? + update_poll(extracted_poll, options, topic_id, poll) mapped_poll = { @@ -83,6 +85,9 @@ module ImportScripts::PhpBB3 extracted_polls.each do |poll| return poll if poll['name'] == @default_poll_name end + + puts "Failed to extract poll for topic id #{topic_id}. The poll text is:" + puts poll_text end # @param poll [ImportScripts::PhpBB3::Poll]