Sha256: 96f033254c03ab3d02b813d3ce2c55451116969a0858d3750ba0cb82692144b8
Contents?: true
Size: 1.38 KB
Versions: 17
Compression:
Stored size: 1.38 KB
Contents
module CurationConcerns class AddToCollectionActor < AbstractActor def create(attributes) collection_ids = attributes.delete(:collection_ids) next_actor.create(attributes) && add_to_collections(collection_ids) end def update(attributes) collection_ids = attributes.delete(:collection_ids) add_to_collections(collection_ids) && next_actor.update(attributes) end private # The default behavior of active_fedora's aggregates association, # when assigning the id accessor (e.g. collection_ids = ['foo:1']) is to add # to new collections, but not remove from old collections. # This method ensures it's removed from the old collections. def add_to_collections(new_collection_ids) return true unless new_collection_ids # remove from old collections # TODO: Implement in_collection_ids https://github.com/projecthydra-labs/hydra-pcdm/issues/157 (curation_concern.in_collections.map(&:id) - new_collection_ids).each do |old_id| collection = ::Collection.find(old_id) collection.members.delete(curation_concern) collection.save end # add to new new_collection_ids.each do |coll_id| collection = ::Collection.find(coll_id) collection.members << curation_concern collection.save end true end end end
Version data entries
17 entries across 17 versions & 1 rubygems