Skip to content
Snippets Groups Projects
Verified Commit 7f71a05b authored by tribut's avatar tribut :man_dancing:
Browse files

Fix import logic from filedrop

parent 800c6681
No related merge requests found
...@@ -147,13 +147,13 @@ module Pretalx ...@@ -147,13 +147,13 @@ module Pretalx
# Add or update comments # Add or update comments
data["comments"]&.each do |comment_data| data["comments"]&.each do |comment_data|
session.filedrop_comments.find_or_initialize_by(body: comment_data['body']).tap do |comment| session.filedrop_comments.find_or_initialize_by(body: comment_data['body']).tap do |comment|
comment.orig_created = comment_data['created'] comment.orig_created = parse_datetime_or_nil(comment_data['meta']['created'])
comment.save! comment.save!
end end
end end
existing_files = session.filedrop_files.pluck(:name, :checksum) existing_files = session.filedrop_files.pluck(:name, :checksum)
new_files = data['filedrop_files']&.pluck('name', 'hash') || [] new_files = data['files']&.map { |d| [d['name'], d.dig('meta', 'hash')] } || []
# Remove files not in the JSON file # Remove files not in the JSON file
(existing_files - new_files).each do |name, checksum| (existing_files - new_files).each do |name, checksum|
...@@ -164,11 +164,17 @@ module Pretalx ...@@ -164,11 +164,17 @@ module Pretalx
data['files']&.each do |file_data| data['files']&.each do |file_data|
session.filedrop_files.find_or_initialize_by(name: file_data['name'], checksum: file_data['meta']['hash']).tap do |file| session.filedrop_files.find_or_initialize_by(name: file_data['name'], checksum: file_data['meta']['hash']).tap do |file|
file.size = file_data['meta']['size'] file.size = file_data['meta']['size']
file.orig_created = file_data['meta']['created'] file.orig_created = parse_datetime_or_nil(file_data['meta']['created'])
file.download(filedrop_config['url'] + file_data['url']) unless filedrop_config.fetch('skip_downloads', false) file.download(filedrop_config['url'] + file_data['url']) unless filedrop_config.fetch('skip_downloads', false)
file.save file.save
end end
end end
end end
def parse_datetime_or_nil(datetime_string)
DateTime.iso8601(datetime_string)
rescue
nil
end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment