cdm_migrator 3.4.2 → 3.5.2

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: 8b875ba84c55ed42472bfb7bc10a476e49adf23733aa0a8053dc577e66c57203
4
- data.tar.gz: 543cedc0d2926d5f4aa27021cd92fb6de38e8e5fb0f09ace7b76a3d27633be36
3
+ metadata.gz: 9bd9baa9f5c277e22421a1726d4652d2231a4067aabcf2e4f048ac9aa7264fc2
4
+ data.tar.gz: f698973f8726c227326fd7e0c393af4201c7dd9352f43d669cff9659f310da85
5
5
  SHA512:
6
- metadata.gz: d7880e669d69504d69850d5e7d3453a0cc62bcb763bf1f7237c8d3328b07f8c7742f77781a9a5417e2f04172e7a9a398846f5cff5a9b503f19bf6791cefdb062
7
- data.tar.gz: a0cea1c0b7cb2f3f9e8b53adc820fb5a3043e56a3c3ba68aee888798a543e3438a718a4ea08bbfef7a4230d3e37b7858c7a9075cbb903e9a5307b78855ae53f4
6
+ metadata.gz: 6c264c4d7a122f598aef1d746766771b408defb9a15e014490f7a2acd43772197c5e66d15a99120c13089f013fe702f9dc5aeaebbb9cbc9f70b2110b54cac55d
7
+ data.tar.gz: 85241bcb0111ead83629678cfde68fb729d49997890dbc0432857e6f7976f74f3f4296b0e6aecac309b71a84b398ea02fa24f1d346d652912a60eded09c39c0c
@@ -14,32 +14,59 @@ module CdmMigrator
14
14
  # advantage of the same strategy as Hyrax::Actors::FileSetOrderedMembersActor
15
15
  # but you don't need the OrderedMembersActor constant initialized.
16
16
 
17
- # This rescue is a safeguard against creating lots of orphan file sets if there
18
- # are recurring errors (see https://tinyurl.com/nh4c5e9j). Instead, CdmMigrator
19
- # will fall back to creating file sets one-by-one if this job fails once.
20
- rescue_from(StandardError) do |exception|
21
- Rails.logger.error "BatchCreateFilesWithOrderedMembersJob error: #{exception.to_s}"
22
- RestartUploadFromMiddleJob.perform_later(arguments[0], arguments[1], arguments[2])
17
+ def perform work, ingest_work, user
18
+ # Reload the work to get the most recent and accurate member associations
19
+ work.reload
20
+ if work.ordered_members.to_a.empty? && work.file_sets.empty?
21
+ attach_files(work, ingest_work.files, user)
22
+ else
23
+ delete_excess_file_sets(work)
24
+ ordered_count = work.reload.ordered_members.to_a.count
25
+ unless ordered_count == ingest_work.files.count
26
+ # Attach any files that might be missing
27
+ files = ingest_work[ordered_count..]
28
+ attach_files(work, files, user)
29
+ end
30
+ end
31
+ first_file_set = work.ordered_members.to_a.first
32
+ work.representative = first_file_set
33
+ work.thumbnail = first_file_set
34
+ work.save!
35
+ work.file_sets.each { |fs| CdmIngestFilesJob.perform_later(fs, fs.import_url, user, ingest_work) }
23
36
  end
24
37
 
25
- def perform work, ingest_work, user
26
- ordered_members = []
27
- ingest_work.files.each do |file|
28
- url = file[:url]
29
- last_file = ingest_work.files.last==file
30
- ::FileSet.new(import_url: url, label: file[:title]) do |fs|
31
- fs.attributes = file[:metadata]
32
- fs.save!
33
- ordered_members << fs
34
- end
38
+ private
39
+
40
+ def attach_files(work, ingest_work_files, user)
41
+ ingest_work_files.each do |file|
42
+ url = file[:url]
43
+ ordered_members = work.ordered_members
44
+ # last_file = ingest_work.files.last==file
45
+ ::FileSet.new(import_url: url, label: file[:title]) do |fs|
46
+ fs.attributes = file[:metadata]
47
+ fs.save!
48
+ ordered_members << fs
35
49
  end
36
- actor = Hyrax::Actors::OrderedMembersActor.new(ordered_members, user)
37
- actor.attach_ordered_members_to_work(work)
38
- work.representative = work.ordered_members.to_a.first
39
- work.thumbnail_id = work.ordered_member_ids.first
50
+ end
51
+ work.save!
52
+ work.reload.ordered_members.to_a.each do |file_set|
53
+ Hyrax.config.callback.run(:after_create_fileset, file_set, user, warn: false)
54
+ end
55
+ end
56
+
57
+ # Sometimes when this job fails, file sets are attached to the work
58
+ # without attaching them as ordered members. This creates "ghost files"
59
+ # that don't show up in the interface but are still linked to the work as members
60
+ def delete_excess_file_sets(work)
61
+ ordered_members = work.ordered_members.to_a
62
+ ghost_members = work.file_sets.select { |fs| ordered_members.exclude? fs }
63
+ if ghost_members.any?
64
+ # Unlink the file sets from the parent work first because it makes deleting them faster
65
+ work.members = ordered_members
40
66
  work.save!
41
- work.file_sets.each { |fs| CdmIngestFilesJob.perform_later(fs, fs.import_url, user, ingest_work) }
67
+ ghost_members.each(&:destroy!)
68
+ end
42
69
  end
43
-
70
+
44
71
  end
45
72
  end
@@ -1,3 +1,3 @@
1
1
  module CdmMigrator
2
- VERSION = '3.4.2'
2
+ VERSION = '3.5.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdm_migrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.2
4
+ version: 3.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sephirothkod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-23 00:00:00.000000000 Z
11
+ date: 2024-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails