Fix inventories attachment/CSV file path

This commit is contained in:
Jure Grabnar 2018-10-15 08:55:00 +02:00
parent 46da1e6b7d
commit ab71471a49

View file

@ -191,14 +191,17 @@ class TeamZipExport < ZipExport
# Helper method for saving inventories to CSV # Helper method for saving inventories to CSV
def save_inventories_to_csv(path, repo, repo_rows, id) def save_inventories_to_csv(path, repo, repo_rows, id)
repo_name = "#{path}/#{to_filesystem_name(repo.name)}_#{id}.csv" repo_name = "#{to_filesystem_name(repo.name)}_#{id}"
file = FileUtils.touch(repo_name).first
# Attachment folder # Attachment folder
rel_attach_path = "#{repo_name}_attachments" rel_attach_path = "#{repo_name}_attachments"
attach_path = "#{path}/#{rel_attach_path}" attach_path = "#{path}/#{rel_attach_path}"
FileUtils.mkdir_p(attach_path) FileUtils.mkdir_p(attach_path)
# CSV file
csv_file_path = "#{path}/#{to_filesystem_name(repo.name)}_#{id}.csv"
csv_file = FileUtils.touch(csv_file_path).first
# Define headers and columns IDs # Define headers and columns IDs
col_ids = [-3, -4, -5, -6] + repo.repository_columns.map(&:id) col_ids = [-3, -4, -5, -6] + repo.repository_columns.map(&:id)
@ -220,7 +223,7 @@ class TeamZipExport < ZipExport
# Generate CSV # Generate CSV
csv_data = RepositoryZipExport.to_csv(repo_rows, col_ids, @user, @team, csv_data = RepositoryZipExport.to_csv(repo_rows, col_ids, @user, @team,
handle_name_func) handle_name_func)
File.open(file, 'wb') { |f| f.write(csv_data) } File.open(csv_file, 'wb') { |f| f.write(csv_data) }
# Save all attachments (it doesn't work directly in callback function # Save all attachments (it doesn't work directly in callback function
assets.each do |asset, asset_path| assets.each do |asset, asset_path|