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(pdf-export): create unique image temp files in case multiple pdf-exports for the same work package are running at the same time

as-opb3e7d523c063
diff --git a/app/models/work_package/pdf_export/attachments.rb b/app/models/work_package/pdf_export/attachments.rb
index 5639c525a74..7132e1ba8df 100644
--- a/app/models/work_package/pdf_export/attachments.rb
+++ b/app/models/work_package/pdf_export/attachments.rb
@@ -30,31 +30,23 @@ require 'mini_magick'
module WorkPackage::PDFExport::Attachments
def resize_image(file_path)
- resized_file_path = extend_file_name_in_path(file_path, '__x325')
+ tmp_file = Tempfile.new(['temp_image', File.extname(file_path)])
+ @resized_images << tmp_file
+ resized_file_path = tmp_file.path
+
image = MiniMagick::Image.open(file_path)
image.resize("x325>")
image.write(resized_file_path)
- @resized_image_paths << resized_file_path
-
resized_file_path
end
- def extend_file_name_in_path(file_path, name_suffix)
- dir_path = File.dirname(file_path)
- file_extension = File.extname(file_path)
- file_name = File.basename(file_path, '.*')
-
- File.join(dir_path, "#{file_name}#{name_suffix}#{file_extension}")
- end
-
def pdf_embeddable?(content_type)
%w[image/jpeg image/png].include?(content_type)
end
def delete_all_resized_images
- @resized_image_paths.each do |file_path|
- File.delete(file_path)
- end
+ @resized_images&.each(&:close!)
+ @resized_images = []
end
end