Commit c100e4e86e5d4b457ad3f5aecd463fca882ae440
1 parent
8909cf9e
Exists in
master
and in
12 other branches
Fix: migration skips softwares without community
Showing
1 changed file
with
8 additions
and
6 deletions
Show diff stats
src/noosfero-spb/software_communities/db/migrate/20160104170028_changing_software_statistics_from_block_to_software_info.rb
@@ -4,14 +4,16 @@ class ChangingSoftwareStatisticsFromBlockToSoftwareInfo < ActiveRecord::Migratio | @@ -4,14 +4,16 @@ class ChangingSoftwareStatisticsFromBlockToSoftwareInfo < ActiveRecord::Migratio | ||
4 | benefited_people = 0 | 4 | benefited_people = 0 |
5 | saved_resources = 0 | 5 | saved_resources = 0 |
6 | 6 | ||
7 | - select_all("SELECT * FROM tasks WHERE status=3 AND type='CreateOrganizationRatingComment' AND target_id=#{software['community_id']}").each do |task| | ||
8 | - settings = YAML.load(task['data']) | ||
9 | - organization_rating = select_one("SELECT * FROM organization_ratings WHERE id=#{settings[:organization_rating_id]}") | 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]}") | ||
10 | 11 | ||
11 | - benefited_people += organization_rating["people_benefited"].to_i | ||
12 | - saved_resources += organization_rating["saved_value"].to_f | 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']}") | ||
13 | end | 16 | end |
14 | - execute("UPDATE software_infos SET benefited_people=#{benefited_people}, saved_resources=#{saved_resources} WHERE id=#{software['id']}") | ||
15 | end | 17 | end |
16 | 18 | ||
17 | end | 19 | end |