-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare monkeypatch to modify FileSetActor#create_content
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
lib/extensions/hyrax/actors/file_set_actor/create_content.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# unmodified from hyrax | ||
module Extensions | ||
module Hyrax | ||
module Actors | ||
module FileSetActor | ||
module CreateContent | ||
# Spawns asynchronous IngestJob unless ingesting from URL | ||
# Called from FileSetsController, AttachFilesToWorkJob, IngestLocalFileJob, ImportUrlJob | ||
# @param [Hyrax::UploadedFile, File] file the file uploaded by the user | ||
# @param [Symbol, #to_s] relation | ||
# @return [IngestJob, FalseClass] false on failure, otherwise the queued job | ||
def create_content(file, relation = :original_file, from_url: false) | ||
# If the file set doesn't have a title or label assigned, set a default. | ||
file_set.label ||= label_for(file) | ||
file_set.title = [file_set.label] if file_set.title.blank? | ||
return false unless file_set.save # Need to save to get an id | ||
if from_url | ||
# If ingesting from URL, don't spawn an IngestJob; instead | ||
# reach into the FileActor and run the ingest with the file instance in | ||
# hand. Do this because we don't have the underlying UploadedFile instance | ||
file_actor = build_file_actor(relation) | ||
file_actor.ingest_file(wrapper!(file: file, relation: relation)) | ||
# Copy visibility and permissions from parent (work) to | ||
# FileSets even if they come in from BrowseEverything | ||
VisibilityCopyJob.perform_later(file_set.parent) | ||
InheritPermissionsJob.perform_later(file_set.parent) | ||
else | ||
IngestJob.perform_later(wrapper!(file: file, relation: relation)) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |