diff --git a/app/jobs/pretalx/import_job.rb b/app/jobs/pretalx/import_job.rb index 268289bfaddf98d906a965f39ea5c235f5bd7e31..ff75c19d82995db6f9ead237ed3bda7cb4eb6ff6 100644 --- a/app/jobs/pretalx/import_job.rb +++ b/app/jobs/pretalx/import_job.rb @@ -147,13 +147,13 @@ module Pretalx # Add or update comments data["comments"]&.each do |comment_data| 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! end end 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 (existing_files - new_files).each do |name, checksum| @@ -164,11 +164,17 @@ module Pretalx 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| 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.save end end end + + def parse_datetime_or_nil(datetime_string) + DateTime.iso8601(datetime_string) + rescue + nil + end end end