Skip to content

Commit

Permalink
make update remote files work for file sets (#693)
Browse files Browse the repository at this point in the history
* pass update_files to create and import, add new conditional for file_sets in #new_remote_files

* add comment to hopefully explain more
  • Loading branch information
kirkkwang authored Dec 19, 2022
1 parent d36cf36 commit 68c52a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit 68c52a6

Please sign in to comment.