update.rb 1.95 KB
# Update software dates
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
  print "." if software && software.save
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

softwares = SoftwareInfo.all

softwares.each do |soft|
  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
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 ""