2014-12-28 11:13:49 -05:00
|
|
|
class UserExport < ActiveRecord::Base
|
2014-12-24 04:11:41 -05:00
|
|
|
|
|
|
|
def self.get_download_path(filename)
|
2014-12-28 11:13:49 -05:00
|
|
|
path = File.join(UserExport.base_directory, filename)
|
2016-05-25 16:20:35 -04:00
|
|
|
File.exists?(path) ? path : nil
|
2014-12-24 04:11:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.remove_old_exports
|
2016-05-25 16:20:35 -04:00
|
|
|
UserExport.where('created_at < ?', 2.days.ago).find_each do |expired_export|
|
2015-01-15 12:30:59 -05:00
|
|
|
file_name = "#{expired_export.file_name}-#{expired_export.id}.csv.gz"
|
2014-12-28 11:13:49 -05:00
|
|
|
file_path = "#{UserExport.base_directory}/#{file_name}"
|
|
|
|
|
2016-05-25 16:20:35 -04:00
|
|
|
File.delete(file_path) if File.exist?(file_path)
|
|
|
|
expired_export.destroy
|
2014-12-24 04:11:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.base_directory
|
|
|
|
File.join(Rails.root, "public", "uploads", "csv_exports", RailsMultisite::ConnectionManagement.current_db)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
2014-12-28 11:13:49 -05:00
|
|
|
# Table name: user_exports
|
2014-12-24 04:11:41 -05:00
|
|
|
#
|
2015-02-04 00:34:25 -05:00
|
|
|
# id :integer not null, primary key
|
2017-12-05 10:29:14 -05:00
|
|
|
# file_name :string(255) not null
|
2015-02-04 00:34:25 -05:00
|
|
|
# user_id :integer not null
|
2017-12-05 10:29:14 -05:00
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
2014-12-24 04:11:41 -05:00
|
|
|
#
|