Class: Hyrax::Transactions::Steps::Save
- Inherits:
-
Object
- Object
- Hyrax::Transactions::Steps::Save
- Defined in:
- lib/hyrax/transactions/steps/save.rb
Overview
Saves a given work from a change_set, returning a ‘Dry::Monads::Result` (`Success`|`Failure`).
If the save is successful, publishes an ‘object.metadata.updated` event for the affected resource.
Instance Method Summary collapse
-
#call(change_set, user: nil) ⇒ Dry::Monads::Result
rubocop:disable Metrics/MethodLength, Metrics/AbcSize.
-
#initialize(persister: Hyrax.persister, publisher: Hyrax.publisher) ⇒ Save
constructor
A new instance of Save.
Constructor Details
Instance Method Details
#call(change_set, user: nil) ⇒ Dry::Monads::Result
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hyrax/transactions/steps/save.rb', line 33 def call(change_set, user: nil) begin valid_future_date?(change_set.lease, 'lease_expiration_date') if change_set.respond_to?(:lease) && change_set.lease valid_future_date?(change_set., 'embargo_release_date') if change_set.respond_to?(:embargo) && change_set. new_collections = changed_collection_membership(change_set) unsaved = change_set.sync (unsaved) saved = @persister.save(resource: unsaved) rescue StandardError => err return Failure.new(["Failed save on #{change_set}\n\t#{err.}", change_set.resource], err.backtrace.first) end # if we have a permission manager, it's acting as a local cache of another resource. # we want to resync changes that we had in progress so we can persist them later. saved..acl. = unsaved..acl. if unsaved.respond_to?(:permission_manager) user ||= ::User.find_by_user_key(saved.depositor) publish_changes(resource: saved, user: user, new: unsaved.new_record, new_collections: new_collections) Success(saved) end |