Class: Hyrax::Works::MigrationService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/works/migration_service.rb

Class Method Summary collapse

Class Method Details

.migrate_data(predicate_from, predicate_to, work) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Migrate data



25
26
27
28
29
30
31
# File 'app/services/hyrax/works/migration_service.rb', line 25

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
  Hyrax.logger.info " Data migrated from #{predicate_from} to #{predicate_to} - id: #{work.id}"
end

.migrate_predicate(predicate_from, predicate_to, works_to_update = ActiveFedora::Base.all) ⇒ Object

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.


11
12
13
14
15
16
17
18
19
20
# File 'app/services/hyrax/works/migration_service.rb', line 11

def self.migrate_predicate(predicate_from, predicate_to, works_to_update = ActiveFedora::Base.all)
  migrated = 0
  Hyrax.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
  Hyrax.logger.info "--- Migration Complete (#{migrated} migrated)"
end