Sha256: 0705615ed77b6af6e0f8971506b7074a85ba562b7ba8e0a9bffcf4e19aae1c54
Contents?: true
Size: 1016 Bytes
Versions: 15
Compression:
Stored size: 1016 Bytes
Contents
# frozen_string_literal: true require 'dry/monads' module Hyrax module Transactions module Steps ## # Adds a work to a parent work # # @see https://wiki.lyrasis.org/display/samvera/Hydra::Works+Shared+Modeling class AddToParent include Dry::Monads[:result] ## # @param [Hyrax::Work] obj # @param [#to_s] parent_id # # @return [Dry::Monads::Result] def call(obj, parent_id: nil, user: nil) return Success(obj) if parent_id.blank? parent = Hyrax.query_service.find_by(id: parent_id) parent.member_ids << obj.id Hyrax.persister.save(resource: parent) user ||= ::User.find_by_user_key(obj.depositor) Hyrax.publisher.publish('object.metadata.updated', object: parent, user: user) Success(obj) rescue Valkyrie::Persistence::ObjectNotFoundError => _err Failure[:parent_object_not_found, parent_id] end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems