update.rb
2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Update software dates
softwares = SoftwareInfo.all
puts "Removing trailling spaces of softwares name and updating the box layout"
softwares.each do |soft|
if soft.community
name = soft.community.name.strip
soft.community.name = name
soft.community.save
soft.community.layout_template = "lefttopright"
print "." if soft.community.save
boxToMove = soft.community.boxes.where(:position => 1).first
blockToMove = boxToMove.blocks.where(:type => "SoftwareInformationBlock").first
newBox = soft.community.boxes.where(:position => 4).first
blockToMove.box = newBox
print "." if blockToMove.save
else
soft.destroy
end
end
puts ""
puts "Updating dates for software"
file = File.new("date-communities.txt", "r")
while (line = file.gets)
result = line.split('|')
software_name = result[2].gsub("/n", "")
software = Community.find(:first, :conditions => ["lower(name) = ?", software_name.strip.downcase])
software.created_at = Time.zone.parse(result[1]) if software
if software && software.save
print "."
else
print "F"
puts software_name
end
end
file.close
puts ""
# Update blocks
puts "Updating blocks settings"
blocks = Block.where(:type => LinkListBlock)
institution = Community["institution"]
software = Community["software"]
boxTemplateInstitution = institution.boxes.where(:position => 2).first
boxTemplateInstitution.blocks.each do |block|
block.mirror = true
print "." if block.save
end
boxTemplateSoftware = software.boxes.where(:position => 2).first
boxTemplateSoftware.blocks.each do |block|
block.mirror = true
print "." if block.save
end
blocks.each do |block|
if block.settings[:fixed] == true
block.move_modes = 'none'
block.edit_modes = 'none'
end
if !(block.owner.class == Environment) && block.owner.organization? && !block.owner.enterprise?
if block.owner.software?
software_block = boxTemplateSoftware.blocks.where(:title => block.title).first
block.mirror_block_id = software_block.id if software_block
elsif block.owner.institution?
institution_block = boxTemplateInstitution.blocks.where(:title => block.title).first
block.mirror_block_id = institution_block.id if institution_block
end
end
print "." if block.save
end
puts ""