Commit 18e74e005f3c3f11fd1dfda6ce746070e8f872e5
Exists in
master
and in
43 other branches
Merge branch 'fix_software_block_migration' into 'master'
Fix software block migration Created a migration for moving saved value and benefited people from statistics block to software info. See merge request !113
Showing
1 changed file
with
22 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,22 @@ |
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 | + 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]}") | |
10 | + | |
11 | + benefited_people += organization_rating["people_benefited"].to_i | |
12 | + saved_resources += organization_rating["saved_value"].to_f | |
13 | + end | |
14 | + execute("UPDATE software_infos SET benefited_people=#{benefited_people}, saved_resources=#{saved_resources} WHERE id=#{software['id']}") | |
15 | + end | |
16 | + | |
17 | + end | |
18 | + | |
19 | + def down | |
20 | + execute("UPDATE software_infos SET benefited_people=0,saved_resources=0") | |
21 | + end | |
22 | +end | ... | ... |