app/controllers/bulkrax/importers_controller.rb in bulkrax-8.2.3 vs app/controllers/bulkrax/importers_controller.rb in bulkrax-8.3.0

- old
+ new

@@ -76,26 +76,28 @@ end end # POST /importers # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/AbcSize def create # rubocop:disable Style/IfInsideElse if api_request? return return_json_response unless valid_create_params? end + uploads = Hyrax::UploadedFile.find(params[:uploaded_files]) if params[:uploaded_files].present? file = file_param cloud_files = cloud_params @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) + files_for_import(file, cloud_files, uploads) if params[:commit] == 'Create and Import' Bulkrax::ImporterJob.send(@importer.parser.perform_method, @importer.id) render_request('Importer was successfully created and import has been queued.') elsif params[:commit] == 'Create and Validate' Bulkrax::ImporterJob.send(@importer.parser.perform_method, @importer.id) @@ -110,27 +112,28 @@ render :new end end # rubocop:enable Style/IfInsideElse end + # rubocop:enable Metrics/AbcSize # PATCH/PUT /importers/1 # # @todo refactor so as to not need to disable rubocop # rubocop:disable all def update if api_request? return return_json_response unless valid_update_params? end - + uploads = Hyrax::UploadedFile.find(params[:uploaded_files]) if params[:uploaded_files].present? file = file_param cloud_files = cloud_params # Skipped during a continue field_mapping_params if params[:importer][:parser_fields].present? if @importer.update(importer_params) - files_for_import(file, cloud_files) unless file.nil? && cloud_files.nil? + files_for_import(file, cloud_files, uploads) # do not perform the import unless params[:commit] == 'Update Importer' set_files_parser_fields Bulkrax::ImporterJob.send(@importer.parser.perform_method, @importer.id, update_harvest) end @@ -216,20 +219,28 @@ send_content end private - def files_for_import(file, cloud_files) - return if file.blank? && cloud_files.blank? + def files_for_import(file, cloud_files, uploads) + return if file.blank? && cloud_files.blank? && uploads.blank? + @importer[:parser_fields]['import_file_path'] = @importer.parser.write_import_file(file) if file.present? if cloud_files.present? @importer[:parser_fields]['cloud_file_paths'] = cloud_files # For BagIt, there will only be one bag, so we get the file_path back and set import_file_path # For CSV, we expect only file uploads, so we won't get the file_path back # and we expect the import_file_path to be set already target = @importer.parser.retrieve_cloud_files(cloud_files, @importer) @importer[:parser_fields]['import_file_path'] = target if target.present? end + + if uploads.present? + uploads.each do |upload| + @importer[:parser_fields]['import_file_path'] = @importer.parser.write_import_file(upload.file.file) + end + end + @importer.save end # Use callbacks to share common setup or constraints between actions. def set_importer