Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix BCF exporter

Oliver Güntherc73d4e4f6921
diff --git a/modules/bim/lib/api/bim/bcf_xml/v1/bcf_xml_api.rb b/modules/bim/lib/api/bim/bcf_xml/v1/bcf_xml_api.rb
index c5d0113e01e..37669cbbf35 100644
--- a/modules/bim/lib/api/bim/bcf_xml/v1/bcf_xml_api.rb
+++ b/modules/bim/lib/api/bim/bcf_xml/v1/bcf_xml_api.rb
@@ -73,7 +73,7 @@ module API
exporter = ::OpenProject::Bim::BcfXml::Exporter.new(updated_query.result)
header['Content-Disposition'] = "attachment; filename=\"#{exporter.bcf_filename}\""
env['api.format'] = :binary
- exporter.list_from_api.read
+ exporter.render!.content.read
end
post do
diff --git a/modules/bim/lib/open_project/bim/bcf_xml/exporter.rb b/modules/bim/lib/open_project/bim/bcf_xml/exporter.rb
index 0ee1863255d..33b34557459 100644
--- a/modules/bim/lib/open_project/bim/bcf_xml/exporter.rb
+++ b/modules/bim/lib/open_project/bim/bcf_xml/exporter.rb
@@ -12,23 +12,16 @@ module OpenProject::Bim::BcfXml
User.current
end
- def list
- Dir.mktmpdir do |dir|
- files = create_bcf! dir
-
- zip = zip_folder dir, files
- yield success(zip)
- end
- rescue StandardError => e
- Rails.logger.error "Failed to export work package list #{e} #{e.message}"
- raise e
+ def self.key
+ :bcf
end
- def list_from_api
+ def render!
Dir.mktmpdir do |dir|
files = create_bcf! dir
- zip_folder dir, files
+ zip = zip_folder dir, files
+ success(zip)
end
rescue StandardError => e
Rails.logger.error "Failed to export work package list #{e} #{e.message}"
@@ -36,7 +29,7 @@ module OpenProject::Bim::BcfXml
end
def success(zip)
- WorkPackage::Exporter::Result::Success
+ Exports::Result
.new format: :xls,
content: zip,
title: bcf_filename,
@@ -59,10 +52,11 @@ module OpenProject::Bim::BcfXml
def zip_folder(dir, files)
zip_file = File.join(dir, bcf_filename)
- Zip::File.open(zip_file, Zip::File::CREATE) do |zip|
+ Zip::OutputStream.open(zip_file.path) do |zos|
files.each do |file|
name = file.sub("#{dir}/", "")
- zip.add name, file
+ zos.put_next_entry(name)
+ zos.print File.read(file)
end
end