orbit-basic/lib/tasks/migrate.rake

162 lines
6.7 KiB
Ruby

# encoding: utf-8
namespace :migrate do
task :i18n => :environment do
p 'Start Bulletin'
bulletins = Bulletin.admin_manager_all
i = 1
bulletins.each do |bulletin|
p "#{i}/#{bulletins.size} - #{bulletin.id}"
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => bulletin.id, :language_value_type => bulletin.class})
bulletin.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
subtitle = I18nVariable.first(:conditions => {:key => 'subtitle', :language_value_id => bulletin.id, :language_value_type => bulletin.class})
bulletin.subtitle_translations = {'en' => subtitle['en'], 'zh_tw' => subtitle['zh_tw']} if subtitle
text = I18nVariable.first(:conditions => {:key => 'text', :language_value_id => bulletin.id, :language_value_type => bulletin.class})
bulletin.text_translations = {'en' => text['en'], 'zh_tw' => text['zh_tw']} if text
bulletin.save(:validate => false)
i += 1
end
p 'End Bulletin'
p '====================================================='
p 'Start BulletinCategory'
categories = BulletinCategory.admin_manager_all
i = 1
categories.each do |category|
p "#{i}/#{categories.size} - #{category.id}"
title = I18nVariable.first(:conditions => {:language_value_id => category.id, :language_value_type => category.class})
category.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
category.save(:validate => false)
i += 1
end
p 'End BulletinCategory'
p '====================================================='
p 'Start BulletinFile'
files = BulletinFile.all
i = 1
files.each do |file|
p "#{i}/#{files.size} - #{file.id}"
description = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class})
file.description_translations = {'en' => description['en'], 'zh_tw' => description['zh_tw']} if description
title = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class})
file.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
file.save(:validate => false)
i += 1
end
p 'End BulletinFile'
p '====================================================='
p 'Start BulletinLink'
links = BulletinLink.all
i = 1
links.each do |link|
p "#{i}/#{links.size} - #{link.id}"
title = I18nVariable.first(:conditions => {:language_value_id => link.id, :language_value_type => link.class})
link.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
link.save(:validate => false)
i += 1
end
p 'End BulletinLink'
p '====================================================='
p 'Start UnitListForAnc'
units = UnitListForAnc.all
i = 1
units.each do |unit|
p "#{i}/#{units.size} - #{unit.id}"
title = I18nVariable.first(:conditions => {:language_value_id => unit.id, :language_value_type => unit.class})
unit.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
unit.save(:validate => false)
i += 1
end
p 'End UnitListForAnc'
p '====================================================='
p '====================================================='
p 'Start NewsBulletin'
news_bulletins = NewsBulletin.admin_manager_all
i = 1
news_bulletins.each do |news_bulletin|
p "#{i}/#{news_bulletins.size} - #{news_bulletin.id}"
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => news_bulletin.id, :language_value_type => news_bulletin.class})
news_bulletin.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
subtitle = I18nVariable.first(:conditions => {:key => 'subtitle', :language_value_id => news_bulletin.id, :language_value_type => news_bulletin.class})
news_bulletin.subtitle_translations = {'en' => subtitle['en'], 'zh_tw' => subtitle['zh_tw']} if subtitle
text = I18nVariable.first(:conditions => {:key => 'text', :language_value_id => news_bulletin.id, :language_value_type => news_bulletin.class})
news_bulletin.text_translations = {'en' => text['en'], 'zh_tw' => text['zh_tw']} if text
news_bulletin.save(:validate => false)
i += 1
end
p 'End NewsBulletin'
p '====================================================='
p 'Start NewsBulletinCategory'
categories = NewsBulletinCategory.admin_manager_all
i = 1
categories.each do |category|
p "#{i}/#{categories.size} - #{category.id}"
title = I18nVariable.first(:conditions => {:language_value_id => category.id, :language_value_type => category.class})
category.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
category.save(:validate => false)
i += 1
end
p 'End NewsBulletinCategory'
p '====================================================='
p 'Start NewsBulletinFile'
files = NewsBulletinFile.all
i = 1
files.each do |file|
p "#{i}/#{files.size} - #{file.id}"
description = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class})
file.description_translations = {'en' => description['en'], 'zh_tw' => description['zh_tw']} if description
title = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class})
file.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
file.save(:validate => false)
i += 1
end
p 'End NewsBulletinFile'
p '====================================================='
p 'Start NewsBulletinLink'
links = NewsBulletinLink.all
i = 1
links.each do |link|
p "#{i}/#{links.size} - #{link.id}"
title = I18nVariable.first(:conditions => {:language_value_id => link.id, :language_value_type => link.class})
link.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
link.save(:validate => false)
i += 1
end
p 'End NewsBulletinLink'
p '====================================================='
p '====================================================='
p 'Start PageContext'
page_contexts = PageContext.admin_manager_all
i = 1
page_contexts.each do |page_context|
p "#{i}/#{page_contexts.size} - #{page_context.id}"
context = I18nVariable.first(:conditions => {:language_value_id => page_context.id, :language_value_type => page_context.class})
page_context.context_translations = {'en' => context['en'], 'zh_tw' => context['zh_tw']} if context
page_context.save(:validate => false)
i += 1
end
p 'End PageContext'
end
end