mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #2662 from techAPJ/patch-3
FEATURE: add additional fields in user list export
This commit is contained in:
@@ -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,10 +10,12 @@ class ExportCsv
|
||||
end
|
||||
|
||||
def self.remove_old_exports
|
||||
dir = Dir.new(ExportCsv.base_directory)
|
||||
dir.each do |file|
|
||||
if (File.mtime(File.join(ExportCsv.base_directory, file)) < 2.days.ago)
|
||||
File.delete(File.join(ExportCsv.base_directory, file))
|
||||
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)
|
||||
File.delete(File.join(ExportCsv.base_directory, file))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user