|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# OVERRIDE Hyrax 3.5.0 to override default_thumbnail |
| 4 | + |
| 5 | +module Hyrax |
| 6 | + module Actors |
| 7 | + module FileSetActorDecorator |
| 8 | + def attach_to_valkyrie_work(work, file_set_params) |
| 9 | + work = Hyrax.query_service.find_by(id: work.id) unless work.new_record |
| 10 | + file_set.visibility = work.visibility unless assign_visibility?(file_set_params) |
| 11 | + fs = Hyrax.persister.save(resource: file_set) |
| 12 | + Hyrax.publisher.publish('object.metadata.updated', object: fs, user: user) |
| 13 | + work.member_ids << fs.id |
| 14 | + work.representative_id = fs.id if work.representative_id.blank? |
| 15 | + # OVERRIDE Hyrax 3.5.0 to override default_thumbnail |
| 16 | + work.thumbnail = file_set if file_set.override_default_thumbnail == 'true' || work.thumbnail_id.blank? |
| 17 | + |
| 18 | + # Save the work so the association between the work and the file_set is persisted (head_id) |
| 19 | + # NOTE: the work may not be valid, in which case this save doesn't do anything. |
| 20 | + Hyrax.persister.save(resource: work) |
| 21 | + Hyrax.publisher.publish('object.metadata.updated', object: work, user: user) |
| 22 | + end |
| 23 | + |
| 24 | + # Adds a FileSet to the work using ore:Aggregations. |
| 25 | + def attach_to_af_work(work, file_set_params) |
| 26 | + work.reload unless work.new_record? |
| 27 | + file_set.visibility = work.visibility unless assign_visibility?(file_set_params) |
| 28 | + work.ordered_members << file_set |
| 29 | + work.representative = file_set if work.representative_id.blank? |
| 30 | + # OVERRIDE Hyrax 3.5.0 to override default_thumbnail |
| 31 | + work.thumbnail = file_set if file_set.override_default_thumbnail == 'true' || work.thumbnail_id.blank? |
| 32 | + |
| 33 | + # Save the work so the association between the work and the file_set is persisted (head_id) |
| 34 | + # NOTE: the work may not be valid, in which case this save doesn't do anything. |
| 35 | + work.save |
| 36 | + end |
| 37 | + end |
| 38 | + end |
| 39 | +end |
| 40 | + |
| 41 | +Hyrax::Actors::FileSetActor.prepend Hyrax::Actors::FileSetActorDecorator |
0 commit comments