Merge pull request #3959 from gschlager/phpbb3-importer

Improve error handling for phpBB3 importer
This commit is contained in:
Régis Hanol 2016-01-13 23:08:54 +01:00
commit 68026bdab3
4 changed files with 10 additions and 4 deletions

View File

@ -22,7 +22,7 @@ module ImportScripts::PhpBB3
filename = CGI.unescapeHTML(row[:real_filename]) filename = CGI.unescapeHTML(row[:real_filename])
upload = @uploader.create_upload(user_id, path, 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 "Failed to upload #{path}"
puts upload.errors.inspect if upload puts upload.errors.inspect if upload
else else

View File

@ -24,14 +24,15 @@ module ImportScripts::PhpBB3
filename = "avatar#{File.extname(path)}" filename = "avatar#{File.extname(path)}"
upload = @uploader.create_upload(user.id, path, filename) upload = @uploader.create_upload(user.id, path, filename)
if upload.persisted? if upload.present? && upload.persisted?
user.import_mode = false user.import_mode = false
user.create_user_avatar user.create_user_avatar
user.import_mode = true user.import_mode = true
user.user_avatar.update(custom_upload_id: upload.id) user.user_avatar.update(custom_upload_id: upload.id)
user.update(uploaded_avatar_id: upload.id) user.update(uploaded_avatar_id: upload.id)
else 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 end
rescue SystemCallError => err rescue SystemCallError => err
Rails.logger.error("Could not import avatar for user #{user.username}: #{err.message}") Rails.logger.error("Could not import avatar for user #{user.username}: #{err.message}")

View File

@ -22,6 +22,8 @@ module ImportScripts::PhpBB3
poll_text = get_poll_text(options, poll) poll_text = get_poll_text(options, poll)
extracted_poll = extract_default_poll(topic_id, poll_text) extracted_poll = extract_default_poll(topic_id, poll_text)
return if extracted_poll.nil?
update_poll(extracted_poll, options, topic_id, poll) update_poll(extracted_poll, options, topic_id, poll)
mapped_poll = { mapped_poll = {
@ -83,6 +85,9 @@ module ImportScripts::PhpBB3
extracted_polls.each do |poll| extracted_polls.each do |poll|
return poll if poll['name'] == @default_poll_name return poll if poll['name'] == @default_poll_name
end end
puts "Failed to extract poll for topic id #{topic_id}. The poll text is:"
puts poll_text
end end
# @param poll [ImportScripts::PhpBB3::Poll] # @param poll [ImportScripts::PhpBB3::Poll]

View File

@ -65,7 +65,7 @@ module ImportScripts::PhpBB3
filename = File.basename(path) filename = File.basename(path)
upload = @uploader.create_upload(Discourse::SYSTEM_USER_ID, path, filename) 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 "Failed to upload #{path}"
puts upload.errors.inspect if upload puts upload.errors.inspect if upload
html = nil html = nil