Commit 78d0d8f649c18a8df0a045e50f2210d2ea577fa8
Committed by
Thiago Ribeiro
1 parent
9451d3bf
Exists in
update_software_api
and in
1 other branch
Fix: migration skips softwares without community
(cherry picked from commit c100e4e86e5d4b457ad3f5aecd463fca882ae440)
Showing
1 changed file
with
24 additions
and
0 deletions
Show diff stats
src/noosfero-spb/software_communities/db/migrate/20160104170028_changing_software_statistics_from_block_to_software_info.rb
0 → 100644
... | ... | @@ -0,0 +1,24 @@ |
1 | +class ChangingSoftwareStatisticsFromBlockToSoftwareInfo < ActiveRecord::Migration | |
2 | + def up | |
3 | + select_all("SELECT * FROM software_infos").each do |software| | |
4 | + benefited_people = 0 | |
5 | + saved_resources = 0 | |
6 | + | |
7 | + if software['community_id'] | |
8 | + select_all("SELECT * FROM tasks WHERE status=3 AND type='CreateOrganizationRatingComment' AND target_id=#{software['community_id']}").each do |task| | |
9 | + settings = YAML.load(task['data']) | |
10 | + organization_rating = select_one("SELECT * FROM organization_ratings WHERE id=#{settings[:organization_rating_id]}") | |
11 | + | |
12 | + benefited_people += organization_rating["people_benefited"].to_i | |
13 | + saved_resources += organization_rating["saved_value"].to_f | |
14 | + end | |
15 | + execute("UPDATE software_infos SET benefited_people=#{benefited_people}, saved_resources=#{saved_resources} WHERE id=#{software['id']}") | |
16 | + end | |
17 | + end | |
18 | + | |
19 | + end | |
20 | + | |
21 | + def down | |
22 | + execute("UPDATE software_infos SET benefited_people=0,saved_resources=0") | |
23 | + end | |
24 | +end | ... | ... |