Skip to content
Snippets Groups Projects
Commit 58e50906 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Merge branch 'fix_package_download' into 'master'

fixed the error that do the collection download don't work

See merge request portalmec/portalmec!547
parents 12b9430d afc5e74a
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,9 @@ module PackageService
private
def get_package_link
package = PackageItem.select("package_id").where(:packageable => @generator.objects).group("package_id")
ids = @generator.objects.map {|o| o.id.to_s}
classes = @generator.objects.map {|o| "\"#{o.class.to_s}\""}
package = PackageItem.find_by_sql("SELECT package_id, array_agg(pi.packageable_id), array_agg(pi.packageable_type) FROM package_items pi GROUP BY package_id HAVING '{#{ids.join(',')}}' = array_agg(pi.packageable_id) AND '{#{classes.join(',')}}' = array_agg(pi.packageable_type)")
return nil if package.blank?
link = Package.find(package.first.package_id).file_path
if !File.exist?(Rails.root.join('public',link))
......
......@@ -30,7 +30,7 @@ class PackageWorker
Bundler.require(*Rails.groups)
return true if File.exist?(PackageService.file_root(filename))
@parc=""
files = open_files(objects_ids)
create_package(filename, files)
ensure
......@@ -53,18 +53,33 @@ class PackageWorker
files.concat object_files(object)
end
end
if @parc.blank?
@parc = "Se você está vendo esse arquivo significa que você tentou baixar conteúdos que não estão hospedados em nossos servidores, entretanto como essa ação não é possível você pode acessar esses conteúdos com os links abaixo:\n\n#{@parc}"
tx = File.new(Rails.root.join("tmp",'links.txt'), 'w+')
tx.write(@parc)
tx.close
tx = File.open(Rails.root.join("tmp",'links.txt'), 'r')
files << tx
end
files
end
def object_files(object)
files = []
object.attachments.where(bundle_name: 'ORIGINAL').each do |a|
link = a.retrieve_cache_link
link = a.id_dspace.to_s if link =~ %r{^https?:\/\/.*}i
file = open_file(link)
files << file unless file.nil?
attachments = object.attachments.where(bundle_name: 'ORIGINAL')
if attachments.empty? && !object.link.nil?
@parc += "#{object.name}: #{object.link}\n"
else
attachments.each do |a|
link = a.retrieve_cache_link
link = a.id_dspace.to_s if link =~ %r{^https?:\/\/.*}i
file = open_file(link)
files << file unless file.nil?
end
end
files
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment