mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
FEATURE: add additional fields in user list export
This commit is contained in:
parent
c04b7cfe8a
commit
8d7f4c1944
@ -21,17 +21,13 @@ module Jobs
|
||||
when 'user'
|
||||
query = ::AdminUserIndexQuery.new
|
||||
user_data = query.find_users_query.to_a
|
||||
|
||||
data = Hash.new do |hash, key|
|
||||
hash[key] = {}
|
||||
end
|
||||
data = Array.new
|
||||
|
||||
user_data.each do |user|
|
||||
id = user['id']
|
||||
email = user['email']
|
||||
data[id] = email
|
||||
user_array = Array.new
|
||||
user_array.push(user['id']).push(user['name']).push(user['username']).push(user['email'])
|
||||
data.push(user_array)
|
||||
end
|
||||
data = data.to_a
|
||||
end
|
||||
|
||||
if data && data.length > 0
|
||||
@ -55,7 +51,7 @@ module Jobs
|
||||
# write to CSV file
|
||||
CSV.open(File.expand_path("#{ExportCsv.base_directory}/#{@file_name}", __FILE__), "w") do |csv|
|
||||
data.each do |value|
|
||||
csv << [value[1]]
|
||||
csv << value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
9
app/jobs/scheduled/clean_up_exports.rb
Normal file
9
app/jobs/scheduled/clean_up_exports.rb
Normal file
@ -0,0 +1,9 @@
|
||||
module Jobs
|
||||
class CleanUpExports < Jobs::Scheduled
|
||||
every 2.day
|
||||
|
||||
def execute(args)
|
||||
ExportCsv.remove_old_exports # delete exported CSV files older than 2 days
|
||||
end
|
||||
end
|
||||
end
|
@ -11,7 +11,6 @@ module Jobs
|
||||
Post.calculate_avg_time
|
||||
Topic.calculate_avg_time
|
||||
ScoreCalculator.new.calculate
|
||||
ExportCsv.remove_old_exports # delete exported CSV files older than 2 days
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -10,6 +10,7 @@ class ExportCsv
|
||||
end
|
||||
|
||||
def self.remove_old_exports
|
||||
if Dir.exists?(ExportCsv.base_directory)
|
||||
dir = Dir.new(ExportCsv.base_directory)
|
||||
dir.each do |file|
|
||||
if (File.mtime(File.join(ExportCsv.base_directory, file)) < 2.days.ago)
|
||||
@ -17,6 +18,7 @@ class ExportCsv
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.base_directory
|
||||
File.join(Rails.root, "public", "uploads", "csv_exports", RailsMultisite::ConnectionManagement.current_db)
|
||||
|
@ -1395,6 +1395,8 @@ en:
|
||||
|
||||
Download CSV file: <a class="attachment" href="%{download_link}">%{file_name}</a>
|
||||
|
||||
<small>CSV file download link will expire after 48 hours.</small>
|
||||
|
||||
csv_export_failed:
|
||||
subject_template: "Export failed"
|
||||
text_body_template: "The export has failed. Please check the logs."
|
||||
|
9
spec/jobs/clean_up_exports_spec.rb
Normal file
9
spec/jobs/clean_up_exports_spec.rb
Normal file
@ -0,0 +1,9 @@
|
||||
require 'spec_helper'
|
||||
|
||||
require_dependency 'jobs/scheduled/clean_up_exports'
|
||||
|
||||
describe Jobs::CleanUpExports do
|
||||
it "runs correctly without crashing" do
|
||||
Jobs::CleanUpExports.new.execute(nil)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user