Commit 9e6d7e74f4c2e584c1210635c0e53f55782e6b86
1 parent
16987144
Exists in
master
and in
18 other branches
Fix software box organize task
Showing
1 changed file
with
19 additions
and
16 deletions
Show diff stats
src/noosfero-spb/spb_migrations/lib/tasks/box_organizer.rake
| @@ -6,10 +6,14 @@ namespace :software do | @@ -6,10 +6,14 @@ namespace :software do | ||
| 6 | software_template = Community["software"] | 6 | software_template = Community["software"] |
| 7 | next unless software_template.is_template? | 7 | next unless software_template.is_template? |
| 8 | 8 | ||
| 9 | + existing_blocks = Block.count | ||
| 10 | + | ||
| 11 | + puts "Last block id: #{Block.last.id}" | ||
| 12 | + puts "Create template boxes:" | ||
| 13 | + | ||
| 9 | software_area_four = software_template.boxes.find_by_position 4 | 14 | software_area_four = software_template.boxes.find_by_position 4 |
| 10 | four = false | 15 | four = false |
| 11 | 16 | ||
| 12 | - puts "Area Four Blocks" | ||
| 13 | if software_area_four.blocks.first.class != BreadcrumbsPlugin::ContentBreadcrumbsBlock | 17 | if software_area_four.blocks.first.class != BreadcrumbsPlugin::ContentBreadcrumbsBlock |
| 14 | template_breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" | 18 | template_breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" |
| 15 | template_breadcrumbs_block.settings[:fixed] = true | 19 | template_breadcrumbs_block.settings[:fixed] = true |
| @@ -19,7 +23,6 @@ namespace :software do | @@ -19,7 +23,6 @@ namespace :software do | ||
| 19 | software_area_four.blocks << template_breadcrumbs_block | 23 | software_area_four.blocks << template_breadcrumbs_block |
| 20 | software_area_four.save! | 24 | software_area_four.save! |
| 21 | 25 | ||
| 22 | - # Puts the breadcrumbs as the first one on area four | ||
| 23 | pos = software_area_four.blocks.order(:position).first.position | 26 | pos = software_area_four.blocks.order(:position).first.position |
| 24 | change_block_pos(software_area_four, template_breadcrumbs_block, pos) | 27 | change_block_pos(software_area_four, template_breadcrumbs_block, pos) |
| 25 | print "." | 28 | print "." |
| @@ -31,7 +34,6 @@ namespace :software do | @@ -31,7 +34,6 @@ namespace :software do | ||
| 31 | software_area_two = software_template.boxes.find_by_position 2 | 34 | software_area_two = software_template.boxes.find_by_position 2 |
| 32 | two = false | 35 | two = false |
| 33 | 36 | ||
| 34 | - puts "Area Two Blocks" | ||
| 35 | if software_area_two.blocks.last.class != SoftwareEventsBlock | 37 | if software_area_two.blocks.last.class != SoftwareEventsBlock |
| 36 | template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" | 38 | template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" |
| 37 | template_software_events.title = "Outros Eventos" | 39 | template_software_events.title = "Outros Eventos" |
| @@ -41,7 +43,6 @@ namespace :software do | @@ -41,7 +43,6 @@ namespace :software do | ||
| 41 | software_area_two.blocks << template_software_events | 43 | software_area_two.blocks << template_software_events |
| 42 | software_area_two.save! | 44 | software_area_two.save! |
| 43 | 45 | ||
| 44 | - # Puts the breadcrumbs as the first one on area four | ||
| 45 | pos = software_area_two.blocks.order(:position).last.position | 46 | pos = software_area_two.blocks.order(:position).last.position |
| 46 | change_block_pos(software_area_four, template_software_events, pos+1) | 47 | change_block_pos(software_area_four, template_software_events, pos+1) |
| 47 | print "." | 48 | print "." |
| @@ -53,7 +54,6 @@ namespace :software do | @@ -53,7 +54,6 @@ namespace :software do | ||
| 53 | software_area_one = software_template.boxes.find_by_position 1 | 54 | software_area_one = software_template.boxes.find_by_position 1 |
| 54 | one = false | 55 | one = false |
| 55 | 56 | ||
| 56 | - puts "Area One Blocks" | ||
| 57 | if software_area_one.blocks[-2].class != SoftwareEventsBlock | 57 | if software_area_one.blocks[-2].class != SoftwareEventsBlock |
| 58 | second_template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" | 58 | second_template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" |
| 59 | second_template_software_events.display = "except_home_page" | 59 | second_template_software_events.display = "except_home_page" |
| @@ -62,7 +62,6 @@ namespace :software do | @@ -62,7 +62,6 @@ namespace :software do | ||
| 62 | software_area_one.blocks << second_template_software_events | 62 | software_area_one.blocks << second_template_software_events |
| 63 | software_area_one.save! | 63 | software_area_one.save! |
| 64 | 64 | ||
| 65 | - # Puts the breadcrumbs as the first one on area four | ||
| 66 | pos = software_area_one.blocks.order(:position).last.position | 65 | pos = software_area_one.blocks.order(:position).last.position |
| 67 | change_block_pos(software_area_one, second_template_software_events, pos) | 66 | change_block_pos(software_area_one, second_template_software_events, pos) |
| 68 | print "." | 67 | print "." |
| @@ -70,10 +69,11 @@ namespace :software do | @@ -70,10 +69,11 @@ namespace :software do | ||
| 70 | end | 69 | end |
| 71 | 70 | ||
| 72 | 71 | ||
| 72 | + puts "\nCreate software community boxes:" | ||
| 73 | Community.joins(:software_info).each do |software_community| | 73 | Community.joins(:software_info).each do |software_community| |
| 74 | software_area_four = software_community.boxes.find_by_position 4 | 74 | software_area_four = software_community.boxes.find_by_position 4 |
| 75 | 75 | ||
| 76 | - if four | 76 | + if four && software_area_four.blocks.first.class != BreadcrumbsPlugin::ContentBreadcrumbsBlock |
| 77 | breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" | 77 | breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" |
| 78 | breadcrumbs_block.settings[:fixed] = true | 78 | breadcrumbs_block.settings[:fixed] = true |
| 79 | breadcrumbs_block.display = "always" | 79 | breadcrumbs_block.display = "always" |
| @@ -129,17 +129,20 @@ namespace :software do | @@ -129,17 +129,20 @@ namespace :software do | ||
| 129 | end | 129 | end |
| 130 | 130 | ||
| 131 | print "\n" | 131 | print "\n" |
| 132 | + | ||
| 133 | + puts "Created blocks: #{Block.count - existing_blocks}" | ||
| 132 | end | 134 | end |
| 133 | -def change_block_pos(box, block, pos) | ||
| 134 | - box.blocks.each do |b| | ||
| 135 | - if b.position >= pos | ||
| 136 | - b.position += 1 | ||
| 137 | - b.save | 135 | + |
| 136 | + def change_block_pos(box, block, pos) | ||
| 137 | + box.blocks.each do |b| | ||
| 138 | + if b.position >= pos | ||
| 139 | + b.position += 1 | ||
| 140 | + b.save | ||
| 141 | + end | ||
| 138 | end | 142 | end |
| 139 | - end | ||
| 140 | 143 | ||
| 141 | - block.position = pos | ||
| 142 | - block.save | ||
| 143 | -end | 144 | + block.position = pos |
| 145 | + block.save | ||
| 146 | + end | ||
| 144 | end | 147 | end |
| 145 | 148 |