Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make update remote files work for file sets #693

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/controllers/bulkrax/importers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def create
@importer = Importer.new(importer_params)
field_mapping_params
@importer.validate_only = true if params[:commit] == 'Create and Validate'
# the following line is needed to handle updating remote files of a FileSet
# on a new import otherwise it only gets updated during the update path
@importer.parser_fields['update_files'] = true if params[:commit] == 'Create and Import'
if @importer.save
files_for_import(file, cloud_files)
if params[:commit] == 'Create and Import'
Expand Down
12 changes: 9 additions & 3 deletions app/models/concerns/bulkrax/file_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ def parsed_remote_files
end

def new_remote_files
return if object.is_a? FileSet

@new_remote_files ||= if object.present? && object.file_sets.present?
@new_remote_files ||= if object.is_a? FileSet
parsed_remote_files.select do |file|
# is the url valid?
is_valid = file[:url]&.match(URI::ABS_URI)
# does the file already exist
is_existing = object.import_url && object.import_url == file[:url]
is_valid && !is_existing
end
elsif object.present? && object.file_sets.present?
parsed_remote_files.select do |file|
# is the url valid?
is_valid = file[:url]&.match(URI::ABS_URI)
Expand Down