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

354 lines
11 KiB
Ruby
Raw Permalink Normal View History

2012-07-25 18:27:43 +00:00
# encoding: utf-8
namespace :migrate do
task :sitemap_i18n => :environment do
Item.all.each do |item|
item.sitemap_enabled = item.sitemap_enabled ? {'en' => 'true', 'zh_tw' => 'true'} : {}
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.album"}}
2013-11-18 12:02:02 +00:00
a.widget_options = {"widget1"=>{"vertical"=>[1, 2], "horizontal"=>[1, 2, 3, 4, 5, 6], "album_id"=>{"query"=>"Album.all", "value"=>:id, "label"=>:name}}}
2013-01-23 10:51:18 +00:00
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)
2013-02-22 03:57:10 +00:00
# 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
2013-02-25 04:49:06 +00:00
task :convert_cate_tag_type => :environment do
[Page,PagePart].each do |obj|
obj.all.each do |pp|
if pp.category.blank?
pp.category = []
else
pp.category = [pp.category]
end
if pp.tag.blank?
pp.tag = []
else
pp.tag = [pp.tag]
end
pp.save
end
end
end
task :flatten_category_and_tag => :environment do
[Page,PagePart].each do |obj|
obj.all.each do |pp|
unless pp.category.blank?
pp.update_attribute(:category, pp.category.flatten)
end
unless pp.tag.blank?
pp.update_attribute(:tag, pp.tag.flatten)
end
end
end
end
task :clean_parts => :environment do
PagePart.where(widget_style: /\d/, kind: 'module_widget').each{|part| part.update_attributes({kind: 'text', widget_style: nil, widget_field: nil})}
PagePart.where(widget_style: /\d/).each{|part| part.update_attributes({widget_style: nil, widget_field: nil})}
end
task :delete_import_archive => :environment do
categories = ArchiveFileCategory.where(key: /import_/).entries
unless categories.blank?
categories.each do |category|
files = category.archive_files
unless files.blank?
files.each(&:destroy)
end
category.destroy
end
end
2013-02-07 11:08:35 +00:00
end
task :save_pages => :environment do
Page.all.each do |page|
page.save
end
end
task :backup_page_frontend_setting => :environment do
Page.all.each do |page|
if page.frontend_field and page.frontend_field.collect{|t| t.class}.include?(Array)
page["temp_frontend_setting"] = page.frontend_field
end
page.save
end
end
# task :correct_page_frontend_setting => :environment do
# Page.all.each do |page|
# page.frontend_field = {}
# if page["temp_frontend_setting"] and page["temp_frontend_setting"].collect{|t| t.class}.include?(Array)
# page["temp_frontend_setting"].each_with_index do |old_frontend_setting,index|
# for_a_field={
# :field_name=>old_frontend_setting[0],
# :field_type=> old_frontend_setting[1],
# :set_to_link=>old_frontend_setting[2]
# }
# page.frontend_field << for_a_field
# end #of each_with_index
# end # of if Array
# binding.pry unless page.frontend_field.blank?
# page.save
# end #of each page
# end #of task
task :migrate_from_one_frontend_field_to_three_fields => :environment do
Page.all.each do |page|
page.frontend_field_name = []
page.frontend_class = []
page.frontend_sat_to_link = []
if page.frontend_field and page.frontend_field.collect{|t| t.class}.include?(Array)
page.frontend_field.each_with_index do |old_frontend_setting,index|
page.frontend_field_name << old_frontend_setting[0]
page.frontend_class << old_frontend_setting[1]
page.frontend_sat_to_link << old_frontend_setting[2]
end
end
page.save
end
end
task :clean_page_frontend_setting => :environment do
Page.all.each do |page|
if page.frontend_field and page.frontend_field.collect{|t| t.class}.include?(Array)
else
page.frontend_field = []
end
page.unset :temp_frontend_setting
page.unset :frontend_field_is_link
page.save
end
end
2013-04-10 10:16:52 +00:00
task :to_daily_0410 => :environment do
#applying Harry's code
Rake::Task["desktop:upload_all_packages"].execute
#applying Spen's code
Rake::Task["web_link_url:web_link_url_i18n"].execute
end
2013-09-06 07:21:40 +00:00
task :add_missing_user_link => :environment do
User.all.each do |user|
user.role_ids.uniq!
user.sub_role_ids.uniq!
user.save
user.roles.each do |role|
unless role.user_ids.include?(user.id)
role.user_ids << user.id
role.save
end
end
user.sub_roles.each do |sub_role|
unless sub_role.user_ids.include?(user.id)
sub_role.user_ids << user.id
sub_role.save
end
end
end
Role.all.each do |role|
role.user_ids.uniq!
role.save
role.users.each do |user|
unless user.role_ids.include?(role.id)
user.role_ids << role.id
user.save
end
end
end
SubRole.all.each do |sub_role|
sub_role.user_ids.uniq!
sub_role.save
sub_role.users.each do |user|
unless user.sub_role_ids.include?(sub_role.id)
user.sub_role_ids << sub_role.id
user.save
end
end
end
2013-09-06 07:21:40 +00:00
end
2012-07-25 18:27:43 +00:00
end