mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Resfactor: improve syntax extended user stats in user export csv
This commit is contained in:
parent
757cea05a4
commit
61ff64d011
1 changed files with 17 additions and 4 deletions
|
@ -26,10 +26,7 @@ module Jobs
|
||||||
user_data.each do |user|
|
user_data.each do |user|
|
||||||
user_array = Array.new
|
user_array = Array.new
|
||||||
group_names = get_group_names(user).join(';')
|
group_names = get_group_names(user).join(';')
|
||||||
user_array.push(user['id']).push(user['name']).push(user['username']).push(user['email']).push(user['created_at'])
|
user_array = get_user_fields(user)
|
||||||
.push(user.user_stat['topics_entered']).push(user.user_stat['posts_read_count']).push(user.user_stat['time_read'])
|
|
||||||
.push(user.user_stat['topic_count']).push(user.user_stat['post_count']).push(user.user_stat['likes_given'])
|
|
||||||
.push(user.user_stat['likes_received'])
|
|
||||||
user_array.push(group_names) if group_names != ''
|
user_array.push(group_names) if group_names != ''
|
||||||
data.push(user_array)
|
data.push(user_array)
|
||||||
end
|
end
|
||||||
|
@ -54,6 +51,22 @@ module Jobs
|
||||||
return group_names
|
return group_names
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_user_fields(user)
|
||||||
|
csv_user_attrs = ['id','name','username','email','created_at']
|
||||||
|
csv_user_stats_attr = ['topics_entered','posts_read_count','time_read','topic_count','post_count','likes_given','likes_received']
|
||||||
|
user_array = []
|
||||||
|
|
||||||
|
csv_user_attrs.each do |user_attr|
|
||||||
|
user_array.push(user.attributes[user_attr])
|
||||||
|
end
|
||||||
|
|
||||||
|
csv_user_stats_attr.each do |user_stat_attr|
|
||||||
|
user_array.push(user.user_stat.attributes[user_stat_attr])
|
||||||
|
end
|
||||||
|
|
||||||
|
return user_array
|
||||||
|
end
|
||||||
|
|
||||||
def set_file_path
|
def set_file_path
|
||||||
@file_name = "export_#{SecureRandom.hex(4)}.csv"
|
@file_name = "export_#{SecureRandom.hex(4)}.csv"
|
||||||
# ensure directory exists
|
# ensure directory exists
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue