Skip to content

Commit

Permalink
WIP to fix migrating files
Browse files Browse the repository at this point in the history
We have to migrate original file before derivatives, so this switches
the order of migration.

We have to remove the id of the pre-migrated file_set's original file
before saving the new FileMetadata object's file_id. This prevents
creating duplicate ORM resources.

Indexing the file_set for the original file's FileMetadata object still
fails while trying to index the thumbnail.
  • Loading branch information
laritakr committed May 23, 2024
1 parent 41cd9b0 commit 297ba11
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/freyja/resource_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def perform(object)

resource = ::Valkyrie::Persistence::Postgres::ORMConverter.new(object, resource_factory:).convert!

migrate_derivatives!(resource:)
migrate_files!(resource:)
migrate_derivatives!(resource:)
ensure
Thread.current[:hyrax_migration_fileset_id] = nil
end
Expand Down Expand Up @@ -103,21 +103,21 @@ def migrate_files!(resource:)
files.each do |file|
# If it doesn't start with fedora, we've likely already migrated it.
next unless /^fedora:/.match?(file.file_identifier.to_s)
resource.file_ids.delete(file.id)

Tempfile.create do |tempfile|
tempfile.binmode
tempfile.write(URI.open(file.file_identifier.to_s.gsub("fedora:", "http:")).read)
tempfile.rewind

# valkyrie_file = Hyrax.storage_adapter.upload(resource: resource, file: tempfile, original_filename: file.original_filename)
Hyrax::ValkyrieUpload.file(
filename: resource.label,
file_set: resource,
io: tempfile,
use: file.pcdm_use.select {|use| Hyrax::FileMetadata::Use.use_list.include?(use)},
user: User.find_or_initialize_by(User.user_key_field => resource.depositor),
mime_type: file.mime_type
)
valkyrie_file = Hyrax::ValkyrieUpload.file(
filename: resource.label,
file_set: resource,
io: tempfile,
use: file.pcdm_use.select {|use| Hyrax::FileMetadata::Use.use_list.include?(use)},
user: User.find_or_initialize_by(User.user_key_field => resource.depositor),
mime_type: file.mime_type
)

file.file_identifier = valkyrie_file.id

Expand Down

0 comments on commit 297ba11

Please sign in to comment.