discourse/app/models/user_export.rb
Arpit Jalan 028121b95b
FIX: delete system generated message when user_export record is deleted (#7595)
FIX: system generated message for user export should be closed by default
2019-05-28 16:38:41 +05:30

47 lines
1.3 KiB
Ruby

# frozen_string_literal: true
class UserExport < ActiveRecord::Base
belongs_to :user
belongs_to :upload, dependent: :destroy
belongs_to :topic, dependent: :destroy
around_destroy :ignore_missing_post_uploads
def ignore_missing_post_uploads
post_ids = upload.post_uploads.pluck(:post_id)
yield
post_ids.each { |post_id| PostCustomField.create!(post_id: post_id, name: Post::MISSING_UPLOADS_IGNORED, value: "t") }
end
def self.remove_old_exports
UserExport.where('created_at < ?', 2.days.ago).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
#
# Table name: user_exports
#
# id :integer not null, primary key
# file_name :string not null
# user_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# upload_id :integer
# topic_id :integer
#