app/actors/sufia/generic_file/actor.rb in sufia-models-5.0.0.beta1 vs app/actors/sufia/generic_file/actor.rb in sufia-models-5.0.0.rc1
- old
+ new
@@ -18,28 +18,30 @@
generic_file.date_uploaded = Date.today
generic_file.date_modified = Date.today
generic_file.creator = [user.name]
if batch_id
- generic_file.batch_id = batch_id
+ generic_file.batch_id = Sufia::Noid.namespaceize(batch_id)
else
ActiveFedora::Base.logger.warn "unable to find batch to attach to"
end
yield(generic_file) if block_given?
end
def create_content(file, file_name, dsid)
- generic_file.add_file(file, dsid, file_name.truncate(255))
+ fname = generic_file.label.blank? ? file_name.truncate(255) : generic_file.label
+ generic_file.add_file(file, dsid, fname)
save_characterize_and_record_committer do
if Sufia.config.respond_to?(:after_create_content)
Sufia.config.after_create_content.call(generic_file, user)
end
end
end
- def revert_content(revision_id)
- generic_file.content.restore_version(revision_id)
+ def revert_content(revision_id, datastream_id)
+ revision = generic_file.content.get_version(revision_id)
+ generic_file.add_file(revision.content, datastream_id, revision.label)
save_characterize_and_record_committer do
if Sufia.config.respond_to?(:after_revert_content)
Sufia.config.after_revert_content.call(generic_file, user, revision_id)
end
end
@@ -65,14 +67,15 @@
end
end
end
def destroy
+ pid = generic_file.pid #Work around for https://github.com/projecthydra/active_fedora/issues/422
generic_file.destroy
- FeaturedWork.where(generic_file_id: generic_file.id).destroy_all
+ FeaturedWork.where(generic_file_id: pid).destroy_all
if Sufia.config.respond_to?(:after_destroy)
- Sufia.config.after_destroy.call(generic_file.id, user)
+ Sufia.config.after_destroy.call(pid, user)
end
end
# Takes an optional block and executes the block if the save was successful.
def save_characterize_and_record_committer
@@ -98,10 +101,10 @@
generic_file.record_version_committer(user)
true
end
def push_characterize_job
- Sufia.queue.push(CharacterizeJob.new(@generic_file.id))
+ Sufia.queue.push(CharacterizeJob.new(@generic_file.pid))
end
class << self
def virus_check(file)
path = file.is_a?(String) ? file : file.path