Sha256: 4d96c2c00ef86873419d0d8ffe19e23f58c33c3def6985bb9d3673c3eb91e896
Contents?: true
Size: 1.95 KB
Versions: 10
Compression:
Stored size: 1.95 KB
Contents
# frozen_string_literal: true module Bulkrax module ImporterExporterBehavior extend ActiveSupport::Concern def parser @parser ||= parser_class.new(self) end def parser_class self.parser_klass.constantize end def last_imported_at @last_imported_at ||= self.importer_runs.last&.created_at end def next_import_at (last_imported_at || Time.current) + frequency.to_seconds if schedulable? && last_imported_at.present? end def increment_counters(index, collection: false, file_set: false, work: false) # Only set the totals if they were not set on initialization importer_run = ImporterRun.find(current_run.id) # make sure fresh if collection importer_run.total_collection_entries = index + 1 unless parser.collections_total.positive? elsif file_set importer_run.total_file_set_entries = index + 1 unless parser.file_sets_total.positive? elsif work # TODO: differentiate between work and collection counts for exporters importer_run.total_work_entries = index + 1 unless limit.to_i.positive? || parser.total.positive? end importer_run.enqueued_records += 1 importer_run.save! end def keys_without_numbers(keys) keys.map { |key| key_without_numbers(key) } end def key_without_numbers(key) key.gsub(/_\d+/, '').sub(/^\d+_/, '') end # Is this a file? def file? parser_fields&.[]('import_file_path') && File.file?(parser_fields['import_file_path']) end # Is this a zip file? def zip? filename = parser_fields&.[]('import_file_path') return false unless filename return false unless File.file?(filename) returning_value = false File.open(filename) do |file| mime_type = ::Marcel::MimeType.for(file) returning_value = mime_type.include?('application/zip') || mime_type.include?('application/gzip') end returning_value end end end
Version data entries
10 entries across 10 versions & 1 rubygems