mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08:00
Merge pull request #2662 from techAPJ/patch-3
FEATURE: add additional fields in user list export
This commit is contained in:
commit
0ce2df36e0
6 changed files with 31 additions and 14 deletions
|
@ -21,17 +21,13 @@ module Jobs
|
||||||
when 'user'
|
when 'user'
|
||||||
query = ::AdminUserIndexQuery.new
|
query = ::AdminUserIndexQuery.new
|
||||||
user_data = query.find_users_query.to_a
|
user_data = query.find_users_query.to_a
|
||||||
|
data = Array.new
|
||||||
data = Hash.new do |hash, key|
|
|
||||||
hash[key] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
user_data.each do |user|
|
user_data.each do |user|
|
||||||
id = user['id']
|
user_array = Array.new
|
||||||
email = user['email']
|
user_array.push(user['id']).push(user['name']).push(user['username']).push(user['email'])
|
||||||
data[id] = email
|
data.push(user_array)
|
||||||
end
|
end
|
||||||
data = data.to_a
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if data && data.length > 0
|
if data && data.length > 0
|
||||||
|
@ -55,7 +51,7 @@ module Jobs
|
||||||
# write to CSV file
|
# write to CSV file
|
||||||
CSV.open(File.expand_path("#{ExportCsv.base_directory}/#{@file_name}", __FILE__), "w") do |csv|
|
CSV.open(File.expand_path("#{ExportCsv.base_directory}/#{@file_name}", __FILE__), "w") do |csv|
|
||||||
data.each do |value|
|
data.each do |value|
|
||||||
csv << [value[1]]
|
csv << value
|
||||||
end
|
end
|
||||||
end
|
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
|
Post.calculate_avg_time
|
||||||
Topic.calculate_avg_time
|
Topic.calculate_avg_time
|
||||||
ScoreCalculator.new.calculate
|
ScoreCalculator.new.calculate
|
||||||
ExportCsv.remove_old_exports # delete exported CSV files older than 2 days
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@ class ExportCsv
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.remove_old_exports
|
def self.remove_old_exports
|
||||||
|
if Dir.exists?(ExportCsv.base_directory)
|
||||||
dir = Dir.new(ExportCsv.base_directory)
|
dir = Dir.new(ExportCsv.base_directory)
|
||||||
dir.each do |file|
|
dir.each do |file|
|
||||||
if (File.mtime(File.join(ExportCsv.base_directory, file)) < 2.days.ago)
|
if (File.mtime(File.join(ExportCsv.base_directory, file)) < 2.days.ago)
|
||||||
|
@ -17,6 +18,7 @@ class ExportCsv
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.base_directory
|
def self.base_directory
|
||||||
File.join(Rails.root, "public", "uploads", "csv_exports", RailsMultisite::ConnectionManagement.current_db)
|
File.join(Rails.root, "public", "uploads", "csv_exports", RailsMultisite::ConnectionManagement.current_db)
|
||||||
|
|
|
@ -1407,6 +1407,8 @@ en:
|
||||||
|
|
||||||
Download CSV file: <a class="attachment" href="%{download_link}">%{file_name}</a>
|
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:
|
csv_export_failed:
|
||||||
subject_template: "Export failed"
|
subject_template: "Export failed"
|
||||||
text_body_template: "The export has failed. Please check the logs."
|
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…
Add table
Add a link
Reference in a new issue