Sha256: 0f2f17cfc09c41dff8a4b29aa9431ee987794a3dbdcc1de1b3f46ae94f7515a2
Contents?: true
Size: 1.35 KB
Versions: 18
Compression:
Stored size: 1.35 KB
Contents
module CurationConcerns module Actors 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 (curation_concern.in_collection_ids - 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 end
Version data entries
18 entries across 18 versions & 1 rubygems