FEATURE: add additional fields in user list export

This commit is contained in:
Arpit Jalan 2014-08-15 23:23:17 +05:30
parent c04b7cfe8a
commit 8d7f4c1944
6 changed files with 31 additions and 14 deletions

View File

@ -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

View 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

View File

@ -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

View File

@ -10,10 +10,12 @@ class ExportCsv
end end
def self.remove_old_exports def self.remove_old_exports
dir = Dir.new(ExportCsv.base_directory) if Dir.exists?(ExportCsv.base_directory)
dir.each do |file| dir = Dir.new(ExportCsv.base_directory)
if (File.mtime(File.join(ExportCsv.base_directory, file)) < 2.days.ago) dir.each do |file|
File.delete(File.join(ExportCsv.base_directory, 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 end
end end

View File

@ -1395,6 +1395,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."

View 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