Commit ce7e745843da4c2bda695e0dfb22c7037f837608
Committed by
Tallys Martins
1 parent
62dab80d
Exists in
master
and in
47 other branches
Add task to create missing blocks in software
Signed-off-by: Tallys Martins <tallysmartins@yahoo.com.br>
Showing
1 changed file
with
145 additions
and
0 deletions
Show diff stats
src/noosfero-spb/spb_migrations/lib/tasks/box_organizer.rake
0 → 100644
| @@ -0,0 +1,145 @@ | @@ -0,0 +1,145 @@ | ||
| 1 | +#encoding: utf-8 | ||
| 2 | + | ||
| 3 | +namespace :software do | ||
| 4 | + desc "Create missing blocks in software and templates" | ||
| 5 | + task :box_organize => :environment do | ||
| 6 | + software_template = Community["software"] | ||
| 7 | + next unless software_template.is_template? | ||
| 8 | + | ||
| 9 | + software_area_four = software_template.boxes.find_by_position 4 | ||
| 10 | + four = false | ||
| 11 | + | ||
| 12 | + puts "Area Four Blocks" | ||
| 13 | + if software_area_four.blocks.first.class != BreadcrumbsPlugin::ContentBreadcrumbsBlock | ||
| 14 | + template_breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" | ||
| 15 | + template_breadcrumbs_block.settings[:fixed] = true | ||
| 16 | + template_breadcrumbs_block.display = "always" | ||
| 17 | + template_breadcrumbs_block.save! | ||
| 18 | + | ||
| 19 | + software_area_four.blocks << template_breadcrumbs_block | ||
| 20 | + software_area_four.save! | ||
| 21 | + | ||
| 22 | + # Puts the breadcrumbs as the first one on area four | ||
| 23 | + pos = software_area_four.blocks.order(:position).first.position | ||
| 24 | + change_block_pos(software_area_four, template_breadcrumbs_block, pos) | ||
| 25 | + print "." | ||
| 26 | + | ||
| 27 | + four = true | ||
| 28 | + end | ||
| 29 | + ############################################################################ | ||
| 30 | + | ||
| 31 | + software_area_two = software_template.boxes.find_by_position 2 | ||
| 32 | + two = false | ||
| 33 | + | ||
| 34 | + puts "Area Two Blocks" | ||
| 35 | + if software_area_two.blocks.last.class != SoftwareEventsBlock | ||
| 36 | + template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" | ||
| 37 | + template_software_events.title = "Outros Eventos" | ||
| 38 | + template_software_events.display = "except_home_page" | ||
| 39 | + template_software_events.save! | ||
| 40 | + | ||
| 41 | + software_area_two.blocks << template_software_events | ||
| 42 | + software_area_two.save! | ||
| 43 | + | ||
| 44 | + # Puts the breadcrumbs as the first one on area four | ||
| 45 | + pos = software_area_two.blocks.order(:position).last.position | ||
| 46 | + change_block_pos(software_area_four, template_software_events, pos+1) | ||
| 47 | + print "." | ||
| 48 | + | ||
| 49 | + two = true | ||
| 50 | + end | ||
| 51 | + ############################################################################ | ||
| 52 | + | ||
| 53 | + software_area_one = software_template.boxes.find_by_position 1 | ||
| 54 | + one = false | ||
| 55 | + | ||
| 56 | + puts "Area One Blocks" | ||
| 57 | + if software_area_one.blocks[-2].class != SoftwareEventsBlock | ||
| 58 | + second_template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" | ||
| 59 | + second_template_software_events.display = "except_home_page" | ||
| 60 | + second_template_software_events.save! | ||
| 61 | + | ||
| 62 | + software_area_one.blocks << second_template_software_events | ||
| 63 | + software_area_one.save! | ||
| 64 | + | ||
| 65 | + # Puts the breadcrumbs as the first one on area four | ||
| 66 | + pos = software_area_one.blocks.order(:position).last.position | ||
| 67 | + change_block_pos(software_area_one, second_template_software_events, pos) | ||
| 68 | + print "." | ||
| 69 | + one = true | ||
| 70 | + end | ||
| 71 | + | ||
| 72 | + | ||
| 73 | + Community.joins(:software_info).each do |software_community| | ||
| 74 | + software_area_four = software_community.boxes.find_by_position 4 | ||
| 75 | + | ||
| 76 | + if four | ||
| 77 | + breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" | ||
| 78 | + breadcrumbs_block.settings[:fixed] = true | ||
| 79 | + breadcrumbs_block.display = "always" | ||
| 80 | + breadcrumbs_block.mirror_block_id = template_breadcrumbs_block.id | ||
| 81 | + breadcrumbs_block.save! | ||
| 82 | + | ||
| 83 | + software_area_four.blocks << breadcrumbs_block | ||
| 84 | + software_area_four.save! | ||
| 85 | + | ||
| 86 | + # Puts the breadcrumbs as the first one on area four | ||
| 87 | + pos = software_area_four.blocks.order(:position).first.position | ||
| 88 | + change_block_pos(software_area_four, breadcrumbs_block, pos) | ||
| 89 | + print "." | ||
| 90 | + | ||
| 91 | + end | ||
| 92 | + ############################################################################ | ||
| 93 | + | ||
| 94 | + software_area_two = software_community.boxes.find_by_position 2 | ||
| 95 | + | ||
| 96 | + if two | ||
| 97 | + software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" | ||
| 98 | + software_events.title = "Outros Eventos" | ||
| 99 | + software_events.display = "except_home_page" | ||
| 100 | + software_events.mirror_block_id = template_software_events.id | ||
| 101 | + software_events.save! | ||
| 102 | + | ||
| 103 | + software_area_two.blocks << software_events | ||
| 104 | + software_area_two.save! | ||
| 105 | + | ||
| 106 | + # Puts the breadcrumbs as the first one on area four | ||
| 107 | + pos = software_area_two.blocks.order(:position).last.position | ||
| 108 | + change_block_pos(software_area_four, software_events, pos+1) | ||
| 109 | + print "." | ||
| 110 | + end | ||
| 111 | + ############################################################################ | ||
| 112 | + | ||
| 113 | + software_area_one = software_community.boxes.find_by_position 1 | ||
| 114 | + | ||
| 115 | + if one | ||
| 116 | + software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" | ||
| 117 | + software_events.display = "except_home_page" | ||
| 118 | + software_events.mirror_block_id = second_template_software_events.id | ||
| 119 | + software_events.save! | ||
| 120 | + | ||
| 121 | + software_area_one.blocks << software_events | ||
| 122 | + software_area_one.save! | ||
| 123 | + | ||
| 124 | + # Puts the breadcrumbs as the first one on area four | ||
| 125 | + pos = software_area_one.blocks.order(:position).last.position | ||
| 126 | + change_block_pos(software_area_one, software_events, pos) | ||
| 127 | + print "." | ||
| 128 | + end | ||
| 129 | + end | ||
| 130 | + | ||
| 131 | + print "\n" | ||
| 132 | + 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 | ||
| 138 | + end | ||
| 139 | + end | ||
| 140 | + | ||
| 141 | + block.position = pos | ||
| 142 | + block.save | ||
| 143 | +end | ||
| 144 | +end | ||
| 145 | + |