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

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
Topic.calculate_avg_time
ScoreCalculator.new.calculate
ExportCsv.remove_old_exports # delete exported CSV files older than 2 days
end
end
end

View File

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

View File

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

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