discourse/app/models/user_export.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2014-12-29 00:13:49 +08:00
class UserExport < ActiveRecord::Base
belongs_to :user
belongs_to :upload, dependent: :destroy
belongs_to :topic, dependent: :destroy
DESTROY_CREATED_BEFORE = 2.days.ago
def self.remove_old_exports
UserExport.where('created_at < ?', DESTROY_CREATED_BEFORE).find_each do |user_export|
UserExport.transaction do
begin
Post.where(topic_id: user_export.topic_id).find_each { |p| p.destroy! }
user_export.destroy!
rescue => e
Rails.logger.warn("Failed to remove user_export record with id #{user_export.id}: #{e.message}\n#{e.backtrace.join("\n")}")
end
end
end
end
def self.base_directory
File.join(Rails.root, "public", "uploads", "csv_exports", RailsMultisite::ConnectionManagement.current_db)
end
end
# == Schema Information
#
2014-12-29 00:13:49 +08:00
# Table name: user_exports
#
2015-02-04 13:34:25 +08:00
# id :integer not null, primary key
2019-01-12 03:29:56 +08:00
# file_name :string not null
2015-02-04 13:34:25 +08:00
# user_id :integer not null
2019-01-12 03:29:56 +08:00
# created_at :datetime not null
# updated_at :datetime not null
# upload_id :integer
# topic_id :integer
#