mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-10 13:59:56 +08:00
Merge pull request #533 from ZmagoD/zd_SCI_1045_v2
sets file duration to 7 days
This commit is contained in:
commit
0aafab5eb2
3 changed files with 12 additions and 6 deletions
|
@ -51,15 +51,17 @@ class ZipExport < ActiveRecord::Base
|
||||||
private
|
private
|
||||||
|
|
||||||
def fill_content(dir, data, type, options = {})
|
def fill_content(dir, data, type, options = {})
|
||||||
generate_csv(dir, data, options) if type == :csv
|
generate_papertrail_csv(dir, data, options) if type == :papertrail
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_csv(tmp_dir, data, options = {})
|
def generate_papertrail_csv(tmp_dir, data, options = {})
|
||||||
attributes = options.fetch(:attributes) { :attributes_missing }
|
attributes = options.fetch(:attributes) { :attributes_missing }
|
||||||
file = FileUtils.touch("#{tmp_dir}/export.csv").first
|
file = FileUtils.touch("#{tmp_dir}/export.csv").first
|
||||||
|
records = PaperTrail::Version.where(data)
|
||||||
|
.order(created_at: :desc)
|
||||||
CSV.open(file, 'wb') do |csv|
|
CSV.open(file, 'wb') do |csv|
|
||||||
csv << attributes
|
csv << attributes
|
||||||
data.each do |entity|
|
records.find_each do |entity|
|
||||||
csv << entity.audit_record.values_at(*attributes.map(&:to_sym))
|
csv << entity.audit_record.values_at(*attributes.map(&:to_sym))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -223,6 +223,8 @@ class Constants
|
||||||
href src width height alt cite datetime title class name xml:lang abbr style
|
href src width height alt cite datetime title class name xml:lang abbr style
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
|
EXPORTABLE_ZIP_EXPIRATION_DAYS = 7
|
||||||
|
|
||||||
# Very basic regex to check for validity of emails
|
# Very basic regex to check for validity of emails
|
||||||
BASIC_EMAIL_REGEX = URI::MailTo::EMAIL_REGEXP
|
BASIC_EMAIL_REGEX = URI::MailTo::EMAIL_REGEXP
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
namespace :exportable_items do
|
namespace :exportable_items do
|
||||||
desc 'Removes exportable zip files if older than 3 days'
|
desc 'Removes exportable zip files'
|
||||||
task cleanup: :environment do
|
task cleanup: :environment do
|
||||||
ZipExport.where('created_at < ?', 3.days.ago).destroy_all
|
num = Constants::EXPORTABLE_ZIP_EXPIRATION_DAYS
|
||||||
puts "All exportable zip files older than '#{3.days.ago}' have been removed"
|
ZipExport.where('created_at < ?', num.days.ago).destroy_all
|
||||||
|
puts "All exportable zip files older than " \
|
||||||
|
"'#{num.days.ago}' have been removed"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue