orbit-basic/lib/tasks/data_migration.rake

119 lines
3.6 KiB
Ruby
Raw Permalink Normal View History

2012-07-03 07:47:28 +00:00
# encoding: utf-8
2012-07-26 08:58:17 +00:00
require 'resque_scheduler/tasks'
2012-07-03 07:47:28 +00:00
namespace :data_migration do
task :migrate_user_infos_from_1121 => :environment do
AttributeField.all.each do |af|
if af.has_attribute?('locale')
af.title_translations = case af[:locale]
when true
af[:locale_title]
when false
{af[:neutral_for] => af[:neutral_title]}
end
af.unset("locale")
af.unset("locale_title")
af.unset("neutral_for")
af.unset("neutral_title")
af.save
end
end
end
2012-07-03 07:47:28 +00:00
task :add_order_to_announcement_tag_0703 => :environment do
AnnouncementTag.first({conditions:{ key: 'students' }}).update_attributes(:order=>1)
AnnouncementTag.first({conditions:{ key: 'alumni' }}).update_attributes(:order=>2)
AnnouncementTag.first({conditions:{ key: 'employee' }}).update_attributes(:order=>3)
AnnouncementTag.first({conditions:{ key: 'guest' }}).update_attributes(:order=>4)
end
2012-07-04 09:56:51 +00:00
task :add_archive_func_to_bulletin_category_0704 => :environment do
BulletinCategory.all.each{|bc| bc.disable=false;bc.save!}
end
task :add_archive_func_to_news_bulletin_category_0704 => :environment do
NewsBulletinCategory.all.each{|bc| bc.disable=false;bc.save!}
end
task :add_search_widget_to_announcement => :environment do
app = ModuleApp.first({:conditions=>{:title => 'Announcement'}})
2012-07-24 12:58:34 +00:00
app.widgets << "bulletins_search_block" if !app.widgets.include?("bulletins_search_block")
app.save!
p "==DO NOT FORGET TO RUN: rake redis_search:index"
end
2012-07-24 12:58:34 +00:00
task :add_search_func => :environment do
ModuleApp.create!(:key=>'search',:title => 'search',:enable_frontend=> true,:app_pages=>["full_search","optional_search"])
end
2012-07-26 06:12:52 +00:00
task :rename_test_role_name => :environment do
sr = SubRole.first({conditions:{key: 'good_teacher' }})
sr.i18n_variable[:zh_tw] = '銳論數位'
sr.i18n_variable[:en] = 'RulingCom'
sr.save!
sr = SubRole.first({conditions:{key: 'bad_teacher' }})
sr.i18n_variable[:zh_tw] = '銳論數位'
sr.i18n_variable[:en] = 'RulingCom'
sr.save!
end
2012-07-31 10:22:40 +00:00
task :make_bulletins_and_news_has_language_flag => :environment do
2012-07-31 16:58:59 +00:00
a = []
i = 0
2012-07-31 10:22:40 +00:00
[Bulletin,NewsBulletin].each do |bulletin|
puts "="*10 + bulletin.to_s + "="*10
bulletin.admin_manager_all.each do |bt|
2012-07-31 10:22:40 +00:00
result = if (bt.save(:validate => false) rescue false )
"OK"
else
2012-07-31 16:58:59 +00:00
a << bt.id
'Failed'
2012-07-31 10:22:40 +00:00
end
i += 1
2012-07-31 16:58:59 +00:00
puts((bt.title.to_s rescue '') + "----------#{result}")
2012-07-31 10:22:40 +00:00
end
end
2012-07-31 16:58:59 +00:00
p a
p i
2012-07-31 10:22:40 +00:00
puts("#{'='*10}Finished#{'='*10}")
end
task :make_web_link_has_language_flag => :environment do
a=[]
i=0
WebLink.all.each do |wl|
result = if (wl.save(:validate => false) rescue false )
"OK"
else
a << wl.id
'Failed'
end
i += 1
puts((wl.title.to_s rescue '') + "----------#{result}")
end
p a
p i
puts("#{'='*10}Finished#{'='*10}")
end
task :make_bulletin_save_dept_data => :environment do
Bulletin.all.each{|bt| bt.save!}
end
task :extend_exsisted_app_module_for_dept_search => :environment do
app = ModuleApp.first({:conditions=>{:title => 'news'}})
app.app_pages << "index_by_unit" if !app.widgets.include?("index_by_unit")
app.save!
app = ModuleApp.first({:conditions=>{:title => 'Announcement'}})
app.app_pages << "index_by_unit" if !app.widgets.include?("index_by_unit")
app.save!
end
task :rename_attribute_field => :environment do
AttributeField.collection.update({},{'$rename' => {'title' => 'locale_title'}}, multi: true, safe: true)
end
2012-07-03 07:47:28 +00:00
end