Commit 417f1c7e0c3d7dc0fdc206b1e9cb55c5233c77d7
1 parent
e9757353
Exists in
master
and in
5 other branches
Add rake task to export softwares info to csv
Showing
1 changed file
with
82 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,82 @@ |
1 | +require 'csv' | |
2 | + | |
3 | +namespace :export do | |
4 | + namespace :catalog do | |
5 | + desc "Export all softwares to CSV" | |
6 | + task :csv => :environment do | |
7 | + Environment.all.each do |env| | |
8 | + if env.plugin_enabled?("MpogSoftware") or env.plugin_enabled?("SoftwareCommunitiesPlugin") | |
9 | + CSV.open('softwares.csv', 'w') do |csv| | |
10 | + csv << [ | |
11 | + "id", | |
12 | + "community_id", | |
13 | + "identifier", | |
14 | + "name", | |
15 | + "finality", | |
16 | + "acronym", | |
17 | + "created_at", | |
18 | + "image_filename", | |
19 | + "home_page_name", | |
20 | + "home_page_slug", | |
21 | + "home_page_path", | |
22 | + "home_page_body", | |
23 | + "home_page_abstract", | |
24 | + "home_page_published_at" | |
25 | + ] | |
26 | + | |
27 | + SoftwareInfo.all.each do |software| | |
28 | + csv << [ | |
29 | + software.id, | |
30 | + software.community.id, | |
31 | + software.community.identifier, | |
32 | + software.community.name, | |
33 | + software.finality, | |
34 | + software.acronym, | |
35 | + software.community.created_at, | |
36 | + (software.community.image.nil? ? nil : software.community.image.filename), | |
37 | + (software.community.home_page.nil? ? nil : software.community.home_page.name), | |
38 | + (software.community.home_page.nil? ? nil : software.community.home_page.slug), | |
39 | + (software.community.home_page.nil? ? nil : software.community.home_page.path), | |
40 | + (software.community.home_page.nil? ? nil : software.community.home_page.body), | |
41 | + (software.community.home_page.nil? ? nil : software.community.home_page.abstract), | |
42 | + (software.community.home_page.nil? ? nil : software.community.home_page.published_at), | |
43 | + ] | |
44 | + end | |
45 | + end | |
46 | + | |
47 | + CSV.open('categories.csv', 'w') do |csv| | |
48 | + csv << [ | |
49 | + "id", | |
50 | + "name", | |
51 | + "path", | |
52 | + ] | |
53 | + | |
54 | + Category.all.each do |category| | |
55 | + csv << [ | |
56 | + category.id, | |
57 | + category.name, | |
58 | + category.path, | |
59 | + ] | |
60 | + end | |
61 | + end | |
62 | + | |
63 | + CSV.open('software_categories.csv', 'w') do |csv| | |
64 | + csv << [ | |
65 | + "software_id", | |
66 | + "category_id" | |
67 | + ] | |
68 | + | |
69 | + SoftwareInfo.all.each do |software| | |
70 | + software.community.categories.each do |category| | |
71 | + csv << [ | |
72 | + software.id, | |
73 | + category.id | |
74 | + ] | |
75 | + end | |
76 | + end | |
77 | + end | |
78 | + end | |
79 | + end | |
80 | + end | |
81 | + end | |
82 | +end | |
0 | 83 | \ No newline at end of file | ... | ... |