From 7606b0437dc34b9c7b09be6f93fe1693eeac796f Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 19 Dec 2022 15:33:55 -0800 Subject: [PATCH 1/2] pass update_files to create and import, add new conditional for file_sets in #new_remote_files --- app/controllers/bulkrax/importers_controller.rb | 1 + app/models/concerns/bulkrax/file_factory.rb | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/bulkrax/importers_controller.rb b/app/controllers/bulkrax/importers_controller.rb index 4fdb379d..b325522c 100644 --- a/app/controllers/bulkrax/importers_controller.rb +++ b/app/controllers/bulkrax/importers_controller.rb @@ -76,6 +76,7 @@ def create @importer = Importer.new(importer_params) field_mapping_params @importer.validate_only = true if params[:commit] == 'Create and Validate' + @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' diff --git a/app/models/concerns/bulkrax/file_factory.rb b/app/models/concerns/bulkrax/file_factory.rb index 1cf783b6..323ec90e 100644 --- a/app/models/concerns/bulkrax/file_factory.rb +++ b/app/models/concerns/bulkrax/file_factory.rb @@ -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) From 1f83f60a856c60941102d06320c7f85c576969d9 Mon Sep 17 00:00:00 2001 From: Kirk Wang Date: Mon, 19 Dec 2022 15:46:52 -0800 Subject: [PATCH 2/2] add comment to hopefully explain more --- app/controllers/bulkrax/importers_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/bulkrax/importers_controller.rb b/app/controllers/bulkrax/importers_controller.rb index b325522c..a379842b 100644 --- a/app/controllers/bulkrax/importers_controller.rb +++ b/app/controllers/bulkrax/importers_controller.rb @@ -76,6 +76,8 @@ 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)