discourse/app/models/user_export.rb

34 lines
952 B
Ruby
Raw Normal View History

2014-12-28 11:13:49 -05:00
class UserExport < ActiveRecord::Base
def self.get_download_path(filename)
2014-12-28 11:13:49 -05:00
path = File.join(UserExport.base_directory, filename)
File.exists?(path) ? path : nil
end
def self.remove_old_exports
UserExport.where('created_at < ?', 2.days.ago).find_each do |expired_export|
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}"
File.delete(file_path) if File.exist?(file_path)
expired_export.destroy
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
#
2015-02-04 00:34:25 -05:00
# id :integer not null, primary key
2016-02-22 18:33:53 -05:00
# file_name :string not null
2015-02-04 00:34:25 -05:00
# user_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#