Sha256: 6030f4eb0a905476f5b60a0c48cc45277cd7f144f1f2ece457fa226305aee8b8

Contents?: true

Size: 1.41 KB

Versions: 15

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true
module Hyrax
  module Works
    class MigrationService
      # @api public
      #
      # Migrate data stored in FCrepo from one predicate to another
      #   The main use case is where the predicate used for a specific property is changed.
      #   Data already stored in Fedora under the original predicate needs to be transfered
      #   and the original data cleaned up.
      def self.migrate_predicate(predicate_from, predicate_to, works_to_update = ActiveFedora::Base.all)
        migrated = 0
        Rails.logger.info "*** Migrating #{predicate_from} to #{predicate_to} in #{works_to_update.count} works"
        works_to_update.each do |work|
          next unless work.ldp_source.content.include?(predicate_from.to_s)
          migrate_data(predicate_from, predicate_to, work)
          migrated += 1
        end
        Rails.logger.info "--- Migration Complete (#{migrated} migrated)"
      end

      # @api private
      #
      # Migrate data
      def self.migrate_data(predicate_from, predicate_to, work)
        orm = Ldp::Orm.new(work.ldp_source)
        orm.value(predicate_from).each { |val| orm.graph.insert([orm.resource.subject_uri, predicate_to, val.to_s]) }
        orm.graph.delete([orm.resource.subject_uri, predicate_from, nil])
        orm.save
        Rails.logger.info " Data migrated from #{predicate_from} to #{predicate_to} - id: #{work.id}"
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
hyrax-3.6.0 app/services/hyrax/works/migration_service.rb
hyrax-3.5.0 app/services/hyrax/works/migration_service.rb
hyrax-3.4.2 app/services/hyrax/works/migration_service.rb
hyrax-4.0.0.beta1 app/services/hyrax/works/migration_service.rb
hyrax-3.4.1 app/services/hyrax/works/migration_service.rb
hyrax-3.4.0 app/services/hyrax/works/migration_service.rb
hyrax-3.3.0 app/services/hyrax/works/migration_service.rb
hyrax-3.2.0 app/services/hyrax/works/migration_service.rb
hyrax-3.1.0 app/services/hyrax/works/migration_service.rb
hyrax-3.0.2 app/services/hyrax/works/migration_service.rb
hyrax-3.0.1 app/services/hyrax/works/migration_service.rb
hyrax-3.0.0 app/services/hyrax/works/migration_service.rb
hyrax-3.0.0.pre.rc4 app/services/hyrax/works/migration_service.rb
hyrax-3.0.0.pre.rc3 app/services/hyrax/works/migration_service.rb
hyrax-3.0.0.pre.rc2 app/services/hyrax/works/migration_service.rb