Commit 348fb20022880354fb6d4f22436b316aecd257d1
1 parent
7a109b2a
Exists in
update_softwares_boxes
Add task to create missing blocks in software
Showing
1 changed file
with
138 additions
and
0 deletions
Show diff stats
src/noosfero-spb/spb_migrations/lib/tasks/box_organizer.rake
0 → 100644
@@ -0,0 +1,138 @@ | @@ -0,0 +1,138 @@ | ||
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 | + first_block_position = software_area_four.blocks.order(:position).first.position | ||
24 | + template_breadcrumbs_block.position = first_block_position | ||
25 | + template_breadcrumbs_block.save! | ||
26 | + print "." | ||
27 | + | ||
28 | + four = true | ||
29 | + end | ||
30 | + ############################################################################ | ||
31 | + | ||
32 | + software_area_two = software_template.boxes.find_by_position 2 | ||
33 | + two = false | ||
34 | + | ||
35 | + puts "Area Two Blocks" | ||
36 | + if software_area_two.blocks.last.class != SoftwareEventsBlock | ||
37 | + template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" | ||
38 | + template_software_events.title = "Outros Eventos" | ||
39 | + template_software_events.display = "home_page_only" | ||
40 | + template_software_events.save! | ||
41 | + | ||
42 | + software_area_two.blocks << template_software_events | ||
43 | + software_area_two.save! | ||
44 | + | ||
45 | + # Puts the breadcrumbs as the first one on area four | ||
46 | + last_block_position = software_area_two.blocks.order(:position).last.position | ||
47 | + template_software_events.position = last_block_position + 1 | ||
48 | + template_software_events.save! | ||
49 | + print "." | ||
50 | + | ||
51 | + two = true | ||
52 | + end | ||
53 | + ############################################################################ | ||
54 | + | ||
55 | + software_area_one = software_template.boxes.find_by_position 1 | ||
56 | + one = false | ||
57 | + | ||
58 | + puts "Area One Blocks" | ||
59 | + if software_area_one.blocks[-2].class != SoftwareEventsBlock | ||
60 | + second_template_software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" | ||
61 | + second_template_software_events.display = "except_home_page" | ||
62 | + second_template_software_events.save! | ||
63 | + | ||
64 | + software_area_one.blocks << second_template_software_events | ||
65 | + software_area_one.save! | ||
66 | + | ||
67 | + # Puts the breadcrumbs as the first one on area four | ||
68 | + last_block_position = software_area_one.blocks.order(:position).last.position | ||
69 | + second_template_software_events.position = last_block_position | ||
70 | + second_template_software_events.save! | ||
71 | + print "." | ||
72 | + one = true | ||
73 | + end | ||
74 | + | ||
75 | + | ||
76 | + Community.joins(:software_info).each do |software_community| | ||
77 | + software_area_four = software_community.boxes.find_by_position 4 | ||
78 | + | ||
79 | + if four | ||
80 | + breadcrumbs_block = BreadcrumbsPlugin::ContentBreadcrumbsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "none" | ||
81 | + breadcrumbs_block.settings[:fixed] = true | ||
82 | + breadcrumbs_block.display = "always" | ||
83 | + breadcrumbs_block.mirror_block_id = template_breadcrumbs_block.id | ||
84 | + breadcrumbs_block.save! | ||
85 | + | ||
86 | + software_area_four.blocks << breadcrumbs_block | ||
87 | + software_area_four.save! | ||
88 | + | ||
89 | + # Puts the breadcrumbs as the first one on area four | ||
90 | + first_block_position = software_area_four.blocks.order(:position).first.position | ||
91 | + breadcrumbs_block.position = first_block_position | ||
92 | + breadcrumbs_block.save! | ||
93 | + print "." | ||
94 | + end | ||
95 | + ############################################################################ | ||
96 | + | ||
97 | + software_area_two = software_community.boxes.find_by_position 2 | ||
98 | + | ||
99 | + if two | ||
100 | + software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" | ||
101 | + software_events.title = "Outros Eventos" | ||
102 | + software_events.display = "home_page_only" | ||
103 | + software_events.mirror_block_id = template_software_events.id | ||
104 | + software_events.save! | ||
105 | + | ||
106 | + software_area_two.blocks << software_events | ||
107 | + software_area_two.save! | ||
108 | + | ||
109 | + # Puts the breadcrumbs as the first one on area four | ||
110 | + last_block_position = software_area_two.blocks.order(:position).last.position | ||
111 | + software_events.position = last_block_position + 1 | ||
112 | + software_events.save! | ||
113 | + print "." | ||
114 | + end | ||
115 | + ############################################################################ | ||
116 | + | ||
117 | + software_area_one = software_community.boxes.find_by_position 1 | ||
118 | + | ||
119 | + if one | ||
120 | + software_events = SoftwareEventsBlock.new :mirror => true, :move_modes => "none", :edit_modes => "all" | ||
121 | + software_events.display = "except_home_page" | ||
122 | + software_events.mirror_block_id = second_template_software_events.id | ||
123 | + software_events.save! | ||
124 | + | ||
125 | + software_area_one.blocks << software_events | ||
126 | + software_area_one.save! | ||
127 | + | ||
128 | + # Puts the breadcrumbs as the first one on area four | ||
129 | + last_block_position = software_area_one.blocks.order(:position).last.position | ||
130 | + software_events.position = last_block_position | ||
131 | + software_events.save! | ||
132 | + print "." | ||
133 | + end | ||
134 | + end | ||
135 | + | ||
136 | + print "\n" | ||
137 | + end | ||
138 | +end |