update.rb 2.23 KB
# 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 ""