This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/lib/tasks/migrate.rake

496 lines
19 KiB
Ruby
Raw Normal View History

2012-07-25 18:27:43 +00:00
# encoding: utf-8
namespace :migrate do
task :i18n => :environment do
2012-07-25 22:40:16 +00:00
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
p 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
p 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
p 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
p 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
p unit.save(:validate => false)
i += 1
end
p 'End UnitListForAnc'
p '====================================================='
p '====================================================='
p 'Start PageContext'
page_contexts = PageContext.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
p page_context.save(:validate => false)
i += 1
end
p 'End PageContext'
p '====================================================='
p '====================================================='
p 'Start WebLink'
links = WebLink.all
i = 1
links.each do |link|
p "#{i}/#{links.size} - #{link.id}"
# the original key was 'name'
title = I18nVariable.first(:conditions => {:key => 'name', :language_value_id => link.id, :language_value_type => link.class})
link.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
context = I18nVariable.first(:conditions => {:key => 'context', :language_value_id => link.id, :language_value_type => link.class})
link.context_translations = {'en' => context['en'], 'zh_tw' => context['zh_tw']} if context
p link.save(:validate => false)
i += 1
end
p 'End WebLink'
p '====================================================='
p 'Start WebLinkCategory'
categories = WebLinkCategory.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
p category.save(:validate => false)
i += 1
end
p 'End WebLinkCategory'
p '====================================================='
p '====================================================='
p 'Start Meta'
metas = Meta.all
i = 1
metas.each do |meta|
p "#{i}/#{metas.size} - #{meta.id}"
title = I18nVariable.first(:conditions => {:language_value_id => meta.id, :language_value_type => meta.class})
meta.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p meta.save(:validate => false)
i += 1
end
p 'End Meta'
p '====================================================='
p '====================================================='
p 'Start Attribute'
attributes = Attribute.all
i = 1
attributes.each do |attribute|
p "#{i}/#{attributes.size} - #{attribute.id}"
title = I18nVariable.first(:conditions => {:language_value_id => attribute.id, :language_value_type => attribute.class})
attribute.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p attribute.save(:validate => false)
i += 1
end
p 'End Attribute'
p '====================================================='
p 'Start AttributeField'
attribute_fields = AttributeField.all
i = 1
attribute_fields.each do |attribute_field|
p "#{i}/#{attribute_fields.size} - #{attribute_field.id}"
title = I18nVariable.first(:conditions => {:language_value_id => attribute_field.id, :language_value_type => attribute_field.class})
attribute_field.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p attribute_field.save(:validate => false)
i += 1
end
p 'End AttributeField'
p '====================================================='
p 'Start Role'
roles = Role.all
i = 1
roles.each do |role|
p "#{i}/#{roles.size} - #{role.id}"
title = I18nVariable.first(:conditions => {:language_value_id => role.id, :language_value_type => role.class})
role.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p role.save(:validate => false)
i += 1
end
p 'End Role'
p '====================================================='
p '====================================================='
p 'Start AdImage'
ad_images = AdImage.all
i = 1
ad_images.each do |image|
p "#{i}/#{ad_images.size} - #{image.id}"
# no key is set and title = context, this is due to original error in the code
title = I18nVariable.first(:conditions => {:language_value_id => image.id, :language_value_type => image.class})
image.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
image.context_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p image.save(:validate => false)
i += 1
end
p 'End AdImage'
p '====================================================='
p '====================================================='
p 'Start Asset'
assets = Asset.all
i = 1
assets.each do |asset|
p "#{i}/#{assets.size} - #{asset.id}"
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => asset.id, :language_value_type => asset.class})
asset.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
description = I18nVariable.first(:conditions => {:key => 'description', :language_value_id => asset.id, :language_value_type => asset.class})
asset.description_translations = {'en' => description['en'], 'zh_tw' => description['zh_tw']} if description
p asset.save(:validate => false)
i += 1
end
p 'End Asset'
p '====================================================='
p 'Start AssetCategory'
categories = AssetCategory.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
p category.save(:validate => false)
i += 1
end
p 'End AssetCategory'
p '====================================================='
p '====================================================='
p 'Start Item'
items = Item.all
i = 1
items.each do |item|
p "#{i}/#{items.size} - #{item.id}"
title = I18nVariable.first(:conditions => {:language_value_id => item.id, :language_value_type => item.class})
item.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p item.save(:validate => false)
i += 1
end
p 'End Item'
p '====================================================='
p 'Start Page'
pages = Page.all
i = 1
pages.each do |item|
p "#{i}/#{pages.size} - #{item.id}"
# the key was originally 'title', changed to 'page_title' to avoit conflict with parent
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => item.id, :language_value_type => item.class})
item.page_title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
p item.save(:validate => false)
i += 1
end
p 'End Page'
p '====================================================='
p 'Start PagePart'
page_parts = PagePart.all
i = 1
page_parts.each do |part|
p "#{i}/#{page_parts.size} - #{part.id}"
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => part.id, :language_value_type => part.class})
part.page_title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
content = I18nVariable.first(:conditions => {:key => 'i18n_variable', :language_value_id => part.id, :language_value_type => part.class})
part.content_translations = {'en' => content['en'], 'zh_tw' => content['zh_tw']} if content
p part.save(:validate => false)
i += 1
end
p 'End PagePart'
p '====================================================='
p '====================================================='
p 'Start Site'
site = Site.first
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => site.id, :language_value_type => site.class})
site.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
footer = I18nVariable.first(:conditions => {:key => 'footer', :language_value_id => site.id, :language_value_type => site.class})
site.footer_translations = {'en' => footer['en'], 'zh_tw' => footer['zh_tw']} if footer
sub_menu = I18nVariable.first(:conditions => {:key => 'sub_menu', :language_value_id => site.id, :language_value_type => site.class})
site.sub_menu_translations = {'en' => sub_menu['en'], 'zh_tw' => sub_menu['zh_tw']} if sub_menu
p site.save(:validate => false)
p 'End Site'
2012-07-25 18:27:43 +00:00
end
task :news_p => :environment do
news_bulletins = NewsBulletin.admin_manager_all rescue nil
i = 1
news_bulletins.each do |news|
p "#{i}/#{news_bulletins.size} - #{news.id}"
2012-09-11 08:32:20 +00:00
news.subtitle_translations = {'en' => (news.subtitle_translations['en'].gsub(/^\<p\>/, '').gsub(/\<\/p\>$/, '') rescue ''), 'zh_tw' => (news.subtitle_translations['zh_tw'].gsub(/^\<p\>/, '').gsub(/\<\/p\>$/, '') rescue nil)}
p news.save(:validate => false) if news.changed?
i += 1
end if news_bulletins
end
task :sitemap_i18n => :environment do
Item.all.each do |item|
item.sitemap_enabled = item.sitemap_enabled ? {'en' => 'true', 'zh_tw' => 'true'} : nil
item.save
end
end
2012-07-25 18:27:43 +00:00
2012-12-27 07:50:05 +00:00
task :recreate_page_parts => :environment do
Page.all.each do |page|
page.create_parts
page.save
end
end
2012-12-28 07:30:46 +00:00
task :add_widget_options_to_gallery => :environment do
a = ModuleApp.where(:key=>'gallery').first
a.widget_options = {"widget1"=>{"vertical"=>[1, 2], "horizontal"=>[1, 2, 3, 4, 5, 6]}}
a.widget_options_fields_i18n = {"widget1"=>{"vertical"=>"gallery.widget_option.vertical", "horizontal"=>"gallery.widget_option.horizontal"}}
a.save
end
task :clean_object_auth => :environment do
ObjectAuth.destroy_all
end
2013-01-02 08:04:11 +00:00
task :correct_gallery_widget => :environment do
@module_app = ModuleApp.where(:key=>'gallery').first
@module_app.widgets=["widget1"]
@module_app.save
end
2013-01-03 02:58:52 +00:00
task :reinstall_calendar => :environment do
old_calendar = ModuleApp.where(key: "calendar")
old_calendar.destroy_all unless old_calendar.empty?
ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/calendar/calendar.json").read).save
end
task :reinstall_gallery => :environment do
old_gallery = ModuleApp.where(key: "gallery")
old_gallery.destroy_all unless old_gallery.empty?
ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/gallery/gallery.json").read).save
end
2013-01-29 02:05:50 +00:00
task :make_default_widget_work_config_for_announcement => :environment do
2013-01-03 11:38:14 +00:00
a = ModuleApp.where(:key=>'announcement').first
a.widgets[:default_widget] = ['typeA','typeC','typeB_style2','typeB_style3','typeB_style4']
2013-01-23 10:51:18 +00:00
a.widgets = {"index"=>["1", "2"], "default_widget"=>["typeA", "typeC", "typeB_style2", "typeB_style3", "typeB_style4"]}
a.widget_fields = [
["title","announcement.default_widget.title"],
["bulletin_category_with_title","announcement.default_widget.bulletin_category_with_title"],
2013-01-07 04:09:36 +00:00
["postdate","announcement.default_widget.postdate"]
]
a.get_default_widget = {:query=>'Bulletin.all',:image=> 'image'}
a.widget_fields_link_method = {
"title"=>{:method => 'panel_announcement_front_end_bulletin_path',
:args=>:self},
"bulletin_category_with_title"=>{
:method => 'panel_announcement_front_end_bulletins_path',
:args=>{:category_id => [:bulletin_category,:id]}}
}
2013-01-03 11:38:14 +00:00
a.save
end
2013-01-29 02:05:50 +00:00
task :make_default_widget_work_config_for_web_link => :environment do
a = ModuleApp.where(:key=>'web_resource').first
a.widgets = { "default_widget"=>["typeA", "typeC", "typeB_style2", "typeB_style3", "typeB_style4"]}
a.widget_fields = [
["title","web_link.default_widget.title"],
["web_link_with_title","web_link.default_widget.bulletin_category_with_title"]
]
a.get_default_widget = {:query=>'WebLink.all'}
a.widget_fields_link_method = {
"title"=>{:method => 'panel_web_resource_front_end_web_link_path',
:args=>:self},
"web_link_with_title"=>{
:method => 'panel_web_resource_front_end_web_link_path',
:args=>{:category_id => [:web_link_category,:id]}}
}
a.save
end
2013-01-03 11:12:52 +00:00
task :reorder_items => :environment do
reorder_children(Item.root)
end
def reorder_children(parent)
parent.children.each_with_index do |child, i|
child.position = i
child.save
reorder_children(child) if child.children
end
end
2013-01-09 08:54:33 +00:00
task :add_inner_page_for_ad_banner => :environment do
a = ModuleApp.where(:key=>'ad_banner').first
a.app_pages = ["inner_page"]
a.save
end
2013-01-14 10:49:23 +00:00
task :correct_gallery_and_web_resoure_config => :environment do
a = ModuleApp.where(:key=>'web_resource').first
2013-01-23 10:51:18 +00:00
if a
a.widgets = {}
a.widgets[:web_links] = []
a.widgets[:home_list] = []
2013-01-24 05:54:14 +00:00
a.app_pages = ["web_links"]
2013-01-23 10:51:18 +00:00
a.save
end
2013-01-14 10:49:23 +00:00
a = ModuleApp.where(:key=>'gallery').first
2013-01-23 10:51:18 +00:00
if a
a.widgets = {}
a.widgets[:widget1] = []
a.widget_options_fields_i18n = {"widget1"=>{"vertical"=>"gallery.widget_option.vertical", "horizontal"=>"gallery.widget_option.horizontal", "album_id"=>"gallery.widget_option.album"}}
a.widget_options = {"widget1"=>{"vertical"=>[1, 2], "horizontal"=>[1, 2, 3, 4, 5, 6], "album_id"=>{"query"=>"GalleryAlbum.all", "value"=>:id, "label"=>:name}}}
a.save
end
2013-01-14 10:49:23 +00:00
end
task :clean_module_app_objects => :environment do
ModuleApp.all.each do |ma|
%w{intro widget_fields_link_method widgets get_default_widget app_pages author enable_frontend get_widget_style get_widget_style organization update_info using_default_widget version widget_fields version create_date}.each do |field|
ma.unset field
end
ma.save
end
end
2013-02-18 07:13:31 +00:00
task :cleanup_page_part_without_page => :environment do
pps = PagePart.all.select{|t| t.page.nil? }
pps.each{|t| t.destroy}
end
task :backup_module_app_info => :environment do
PagePart.all.each do |pp|
pp[:backup_module_app_key] = (pp.module_app ? pp.module_app.key : nil)
puts pp.id
2013-02-18 07:13:31 +00:00
pp.save
# puts pp.inspect
2013-02-18 07:13:31 +00:00
end
Page.all.each do |page|
page[:backup_module_app_key] = (page.module_app ? page.module_app.key : nil)
page.save
# puts page.inspect
2013-02-18 07:13:31 +00:00
end
end
2013-02-18 07:13:31 +00:00
task :rebind_module_app => :environment do
Page.all.each do |page|
if page[:backup_module_app_key].nil?
page.module_app = nil
else
page.module_app = ModuleApp.where(:key=> page[:backup_module_app_key]).first
end
page.save
end
PagePart.all.each do |pp|
if pp[:backup_module_app_key].nil?
pp.module_app = nil
else
pp.module_app = ModuleApp.where(:key=> pp[:backup_module_app_key]).first
end
pp.save
end
end
task :clean_up_module_app_info => :environment do
Page.all.each do |page|
page.unset(:backup_module_app_key)
page.save
end
PagePart.all.each do |pp|
pp.unset(:backup_module_app_key)
pp.save
end
end
2012-07-25 18:27:43 +00:00
end