bulkrax 4.1.0 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7196362349b79b42a3d22ea7939383d43fbd44332184096dfbce2e37faa0504e
4
- data.tar.gz: bfdf2c501e0c7fc9bbd0ea00586c1457d46c0bc4ebc379c9767bee3bc07418fb
3
+ metadata.gz: 11a3549082d5c6493135ed66fe5729474b4303bb8dec30ee20a8e00fe66f563d
4
+ data.tar.gz: '08a021e73dc020a2791d1cf6e7f086a2cebdc5b511ffa2c83db004f31592a6af'
5
5
  SHA512:
6
- metadata.gz: 8095b741060d85acf813b9fcdb6794d811c5585ead33cc2a530dc0d125dd2224682514414cd352e67aed849d17774b32e9e198c5dcfa44bc002a9a65f352c657
7
- data.tar.gz: fff5bf8fed8bfd1acd314c9e5c05bbe7fe5ba457165a65856d518e27db80873b76bd39bc479e0b6fc8d06185255a61e4e108ab446f6734701c8d8de561309815
6
+ metadata.gz: '049aaefb66b149b6e57857f75ded3408a910578cdbbd3c8094a85fedeffc2416124e0369e22cab136e2620cd56c9516f7fcf9bf906897682f09f8b32b2ef9dcc'
7
+ data.tar.gz: bf1a0ff60588f3b66295f6eb7941c80b4c2cb06cbbc68755145e5ec1688906103a8efd6e7ebb6fab5137460de9f1d3d6b5fe8191beac47cd8241ce0c35b250b2
@@ -12,7 +12,8 @@ module Bulkrax
12
12
  def perform(entry_id, importer_run_id)
13
13
  @importer_run_id = importer_run_id
14
14
  entry = Entry.find(entry_id)
15
- parent_identifier = entry.raw_metadata[entry.related_parents_raw_mapping]&.strip
15
+ # e.g. "parents" or "parents_1"
16
+ parent_identifier = (entry.raw_metadata[entry.related_parents_raw_mapping] || entry.raw_metadata["#{entry.related_parents_raw_mapping}_1"])&.strip
16
17
 
17
18
  validate_parent!(parent_identifier)
18
19
 
@@ -57,7 +58,7 @@ module Bulkrax
57
58
  end
58
59
 
59
60
  def check_parent_exists!(parent_identifier)
60
- raise MissingParentError, %(Unable to find a record with the identifier "#{parent_identifier}") if parent_record.blank?
61
+ raise MissingParentError, %(Unable to find a record with the identifier "#{parent_identifier}") if parent_record.nil?
61
62
  end
62
63
 
63
64
  def check_parent_is_a_work!(parent_identifier)
@@ -66,8 +67,7 @@ module Bulkrax
66
67
  end
67
68
 
68
69
  def find_parent_record(parent_identifier)
69
- @parent_record ||= find_record(parent_identifier, importer_run_id)
70
- @parent_record = parent_record.last if parent_record.is_a? Array
70
+ _, @parent_record = find_record(parent_identifier, importer_run_id)
71
71
  end
72
72
  end
73
73
  end
@@ -75,7 +75,7 @@ module Bulkrax
75
75
  def get_field_mapping_hash_for(key)
76
76
  return instance_variable_get("@#{key}_hash") if instance_variable_get("@#{key}_hash").present?
77
77
 
78
- mapping = importerexporter.field_mapping == [{}] ? {} : importerexporter.field_mapping
78
+ mapping = importerexporter.field_mapping.is_a?(Hash) ? importerexporter.field_mapping : {}
79
79
  instance_variable_set(
80
80
  "@#{key}_hash",
81
81
  mapping&.with_indifferent_access&.select { |_, h| h.key?(key) }
@@ -264,6 +264,8 @@ module Bulkrax
264
264
 
265
265
  Dir["#{exporter_export_path}/**"].each do |folder|
266
266
  zip_path = "#{exporter_export_zip_path.split('/').last}_#{folder.split('/').last}.zip"
267
+ FileUtils.rm_rf("#{exporter_export_zip_path}/#{zip_path}")
268
+
267
269
  Zip::File.open(File.join("#{exporter_export_zip_path}/#{zip_path}"), create: true) do |zip_file|
268
270
  Dir["#{folder}/**/**"].each do |file|
269
271
  zip_file.add(file.sub("#{folder}/", ''), file)
@@ -283,6 +283,10 @@ module Bulkrax
283
283
  CsvFileSetEntry
284
284
  end
285
285
 
286
+ def valid_entry_types
287
+ ['Bulkrax::CsvCollectionEntry', 'Bulkrax::CsvFileSetEntry', 'Bulkrax::CsvEntry']
288
+ end
289
+
286
290
  # TODO: figure out why using the version of this method that's in the bagit parser
287
291
  # breaks specs for the "if importer?" line
288
292
  def total
@@ -324,7 +328,8 @@ module Bulkrax
324
328
  def write_files
325
329
  require 'open-uri'
326
330
  folder_count = 0
327
- sorted_entries = sort_entries(importerexporter.entries)
331
+ sorted_entries = sort_entries(importerexporter.entries.uniq(&:identifier))
332
+ .select { |e| valid_entry_types.include?(e.type) }
328
333
 
329
334
  sorted_entries[0..limit || total].in_groups_of(records_split_count, false) do |group|
330
335
  folder_count += 1
@@ -342,6 +347,8 @@ module Bulkrax
342
347
 
343
348
  def store_files(identifier, folder_count)
344
349
  record = ActiveFedora::Base.find(identifier)
350
+ return unless record
351
+
345
352
  file_sets = record.file_set? ? Array.wrap(record) : record.file_sets
346
353
  file_sets << record.thumbnail if exporter.include_thumbnails && record.thumbnail.present? && record.work?
347
354
  file_sets.each do |fs|
@@ -356,6 +363,8 @@ module Bulkrax
356
363
  f.close
357
364
  end
358
365
  end
366
+ rescue Ldp::Gone
367
+ return
359
368
  end
360
369
 
361
370
  def export_key_allowed(key)
@@ -391,12 +400,12 @@ module Bulkrax
391
400
  # always export models in the same order: work, collection, file set
392
401
  entries.sort_by do |entry|
393
402
  case entry.type
394
- when 'Bulkrax::CsvEntry'
395
- '0'
396
403
  when 'Bulkrax::CsvCollectionEntry'
397
404
  '1'
398
405
  when 'Bulkrax::CsvFileSetEntry'
399
406
  '2'
407
+ else
408
+ '0'
400
409
  end
401
410
  end
402
411
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bulkrax
4
- VERSION = '4.1.0'
4
+ VERSION = '4.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulkrax
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Kaufman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-18 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails