Commit 63bae030c8f879e6a1201e872ddf3c297dcd0a67
1 parent
007f77bf
Exists in
master
and in
2 other branches
Fix migrations to consider software template
Showing
4 changed files
with
90 additions
and
32 deletions
Show diff stats
db/migrate/20150727161511_change_software_layout.rb
1 | class ChangeSoftwareLayout < ActiveRecord::Migration | 1 | class ChangeSoftwareLayout < ActiveRecord::Migration |
2 | def up | 2 | def up |
3 | + software_template = Community["software"] | ||
4 | + if software_template | ||
5 | + change_layout(software_template) | ||
6 | + end | ||
7 | + | ||
3 | softwares = SoftwareInfo.all | 8 | softwares = SoftwareInfo.all |
4 | softwares.each do |software| | 9 | softwares.each do |software| |
5 | - software.community.layout_template = "lefttopright" | ||
6 | - print "." if software.community.save | ||
7 | - boxToMove = software.community.boxes.where(:position => 1).first | ||
8 | - blockToMove = boxToMove.blocks.where(:type => "SoftwareInformationBlock").first | ||
9 | - if blockToMove | ||
10 | - newBox = software.community.boxes.where(:position => 4).first | ||
11 | - blockToMove.box = newBox | ||
12 | - print "." if blockToMove.save | ||
13 | - end | 10 | + change_layout(software.community) |
14 | end | 11 | end |
12 | + | ||
13 | + puts "" | ||
15 | end | 14 | end |
16 | 15 | ||
17 | def down | 16 | def down |
18 | end | 17 | end |
18 | + | ||
19 | + def change_layout(community) | ||
20 | + community.layout_template = "lefttopright" | ||
21 | + print "." if community.save | ||
22 | + boxToMove = community.boxes.where(:position => 1).first | ||
23 | + blockToMove = boxToMove.blocks.where(:type => "SoftwareInformationBlock").first | ||
24 | + if blockToMove | ||
25 | + newBox = community.boxes.where(:position => 4).first | ||
26 | + blockToMove.box = newBox | ||
27 | + print "." if blockToMove.save | ||
28 | + end | ||
29 | + end | ||
19 | end | 30 | end |
db/migrate/20150904174335_swap_softwares_blocks_between_areas_2_and_3.rb
1 | class SwapSoftwaresBlocksBetweenAreas2And3 < ActiveRecord::Migration | 1 | class SwapSoftwaresBlocksBetweenAreas2And3 < ActiveRecord::Migration |
2 | def up | 2 | def up |
3 | - swap_software_blocks_between_areas_2_and_3 | 3 | + software_template = Community["software"] |
4 | + if software_template | ||
5 | + swap_software_blocks_between_areas_2_and_3(software_template) | ||
6 | + end | ||
7 | + | ||
8 | + Community.joins(:software_info).each do |software_community| | ||
9 | + swap_software_blocks_between_areas_2_and_3(software_community) | ||
10 | + end | ||
11 | + puts "" | ||
4 | end | 12 | end |
5 | 13 | ||
6 | def down | 14 | def down |
7 | - swap_software_blocks_between_areas_2_and_3 | 15 | + say "This can't be reverted" |
8 | end | 16 | end |
9 | 17 | ||
10 | - def swap_software_blocks_between_areas_2_and_3 | ||
11 | - Community.joins(:software_info).each do |software_community| | ||
12 | - print "." | ||
13 | - | ||
14 | - # Get areas 2 and 3 | ||
15 | - box_area_two = software_community.boxes.find_by_position 2 | ||
16 | - box_area_three = software_community.boxes.find_by_position 3 | 18 | + def swap_software_blocks_between_areas_2_and_3(software_community) |
19 | + print "." | ||
17 | 20 | ||
18 | - # Get all ids of blocks from areas 2 and 3 | ||
19 | - blocks_ids_from_area_two = box_area_two.blocks.select(:id).map(&:id) | ||
20 | - blocks_ids_from_area_three = box_area_three.blocks.select(:id).map(&:id) | 21 | + # Get areas 2 and 3 |
22 | + box_area_two = software_community.boxes.find_by_position 2 | ||
23 | + box_area_three = software_community.boxes.find_by_position 3 | ||
21 | 24 | ||
22 | - # Swap blocks from area 2 to 3 | ||
23 | - Block.update_all({:box_id=>box_area_three.id}, ["id IN (?)", blocks_ids_from_area_two]) | 25 | + # Get all ids of blocks from areas 2 and 3 |
26 | + blocks_ids_from_area_two = box_area_two.blocks.select(:id).map(&:id) | ||
27 | + blocks_ids_from_area_three = box_area_three.blocks.select(:id).map(&:id) | ||
24 | 28 | ||
25 | - # Swap blocks from area 3 to 2 | ||
26 | - Block.update_all({:box_id=>box_area_two.id}, ["id IN (?)", blocks_ids_from_area_three]) | ||
27 | - end | 29 | + # Swap blocks from area 2 to 3 |
30 | + Block.update_all({:box_id=>box_area_three.id}, ["id IN (?)", blocks_ids_from_area_two]) | ||
28 | 31 | ||
29 | - puts "" | 32 | + # Swap blocks from area 3 to 2 |
33 | + Block.update_all({:box_id=>box_area_two.id}, ["id IN (?)", blocks_ids_from_area_three]) | ||
30 | end | 34 | end |
31 | end | 35 | end |
32 | - |
db/migrate/20150904181508_add_communities_ratings_block_to_all_softwares_communities.rb
1 | class AddCommunitiesRatingsBlockToAllSoftwaresCommunities < ActiveRecord::Migration | 1 | class AddCommunitiesRatingsBlockToAllSoftwaresCommunities < ActiveRecord::Migration |
2 | def up | 2 | def up |
3 | + software_template = Community["software"] | ||
4 | + if software_template | ||
5 | + software_area_one = software_template.boxes.find_by_position 1 | ||
6 | + | ||
7 | + template_ratings_block = CommunitiesRatingsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" | ||
8 | + template_ratings_block.settings[:fixed] = true | ||
9 | + template_ratings_block.display = "home_page_only" | ||
10 | + template_ratings_block.save! | ||
11 | + print "." | ||
12 | + | ||
13 | + software_area_one.blocks << template_ratings_block | ||
14 | + software_area_one.save! | ||
15 | + print "." | ||
16 | + | ||
17 | + # Puts the ratings block as the last one on area one | ||
18 | + last_block_position = software_area_one.blocks.order(:position).last.position | ||
19 | + template_ratings_block.position = last_block_position + 1 | ||
20 | + template_ratings_block.save! | ||
21 | + print "." | ||
22 | + end | ||
23 | + | ||
3 | Community.joins(:software_info).each do |software_community| | 24 | Community.joins(:software_info).each do |software_community| |
4 | software_area_one = software_community.boxes.find_by_position 1 | 25 | software_area_one = software_community.boxes.find_by_position 1 |
5 | print "." | 26 | print "." |
6 | 27 | ||
7 | - ratings_block = CommunitiesRatingsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" | 28 | + ratings_block = CommunitiesRatingsBlock.new :move_modes => "none", :edit_modes => "none" |
8 | ratings_block.settings[:fixed] = true | 29 | ratings_block.settings[:fixed] = true |
9 | ratings_block.display = "home_page_only" | 30 | ratings_block.display = "home_page_only" |
31 | + ratings_block.mirror_block_id = template_ratings_block.id | ||
10 | ratings_block.save! | 32 | ratings_block.save! |
11 | print "." | 33 | print "." |
12 | 34 | ||
@@ -25,6 +47,6 @@ class AddCommunitiesRatingsBlockToAllSoftwaresCommunities < ActiveRecord::Migrat | @@ -25,6 +47,6 @@ class AddCommunitiesRatingsBlockToAllSoftwaresCommunities < ActiveRecord::Migrat | ||
25 | end | 47 | end |
26 | 48 | ||
27 | def down | 49 | def down |
28 | - CommunitiesRatingsBlock.destroy_all | 50 | + say "This can't be reverted" |
29 | end | 51 | end |
30 | end | 52 | end |
db/migrate/20150904202116_add_software_tab_data_block_to_all_softwares.rb
1 | class AddSoftwareTabDataBlockToAllSoftwares < ActiveRecord::Migration | 1 | class AddSoftwareTabDataBlockToAllSoftwares < ActiveRecord::Migration |
2 | def up | 2 | def up |
3 | + software_template = Community["software"] | ||
4 | + if software_template | ||
5 | + software_area_one = software_template.boxes.find_by_position 1 | ||
6 | + | ||
7 | + template_soft_tab_block = SoftwareTabDataBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" | ||
8 | + template_soft_tab_block.settings[:fixed] = true | ||
9 | + template_soft_tab_block.display = "except_home_page" | ||
10 | + template_soft_tab_block.save! | ||
11 | + print "." | ||
12 | + | ||
13 | + software_area_one.blocks << template_soft_tab_block | ||
14 | + software_area_one.save! | ||
15 | + print "." | ||
16 | + | ||
17 | + # Puts the ratings block as the last one on area one | ||
18 | + last_block_position = software_area_one.blocks.order(:position).last.position | ||
19 | + template_soft_tab_block.position = last_block_position + 1 | ||
20 | + template_soft_tab_block.save! | ||
21 | + print "." | ||
22 | + end | ||
23 | + | ||
3 | Community.joins(:software_info).each do |software_community| | 24 | Community.joins(:software_info).each do |software_community| |
4 | software_area_one = software_community.boxes.find_by_position 1 | 25 | software_area_one = software_community.boxes.find_by_position 1 |
5 | print "." | 26 | print "." |
6 | 27 | ||
7 | - soft_tab_block = SoftwareTabDataBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" | 28 | + soft_tab_block = SoftwareTabDataBlock.new :move_modes => "none", :edit_modes => "none" |
8 | soft_tab_block.settings[:fixed] = true | 29 | soft_tab_block.settings[:fixed] = true |
9 | soft_tab_block.display = "except_home_page" | 30 | soft_tab_block.display = "except_home_page" |
31 | + soft_tab_block.mirror_block_id = template_soft_tab_block.id | ||
10 | soft_tab_block.save! | 32 | soft_tab_block.save! |
11 | print "." | 33 | print "." |
12 | 34 | ||
@@ -25,6 +47,6 @@ class AddSoftwareTabDataBlockToAllSoftwares < ActiveRecord::Migration | @@ -25,6 +47,6 @@ class AddSoftwareTabDataBlockToAllSoftwares < ActiveRecord::Migration | ||
25 | end | 47 | end |
26 | 48 | ||
27 | def down | 49 | def down |
28 | - SoftwareTabDataBlock.destroy_all | 50 | + say "This can't be reverted" |
29 | end | 51 | end |
30 | end | 52 | end |