From f76b1c02b579217b696e28f2d83d52d858d1c2f8 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Thu, 26 Jul 2012 14:57:22 +0800 Subject: [PATCH] first version of mid_site_sync for new i18n var --- lib/tasks/mid_site_sync.rake | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/tasks/mid_site_sync.rake b/lib/tasks/mid_site_sync.rake index dacdb2e5..707a609b 100644 --- a/lib/tasks/mid_site_sync.rake +++ b/lib/tasks/mid_site_sync.rake @@ -18,12 +18,10 @@ namespace :mid_site do sub_role = role.sub_roles.get_sub_role_from_key(key) if sub_role.nil? ut_data = ut_query.find{|ut_data| ut_data["ut_cod"] == key } - # debugger - i18n_for_new_sub_role = I18nVariable.create!( :document_class => 'SubRole', :key => key, :en => (ut_data["ut_eng_m"] rescue ''), :zh_tw => (ut_data["ut_chi_m"] rescue ''), :parent_id => role.i18n_variable.id ) sub_role = role.sub_roles.create!(:key => key) - sub_role.i18n_variable = i18n_for_new_sub_role + sub_role.title_translations ={"en" => (ut_data["ut_eng_m"] rescue ''), "zh_tw" => (ut_data["ut_chi_m"] rescue '')} sub_role.save! - p "Created SubRole(key: #{key}): EN: #{sub_role.i18n_variable.en}, CH: #{sub_role.i18n_variable.zh_tw} ParentRole(#{role.i18n_variable.key}): #{role.i18n_variable.en}" + p "Created SubRole(key: #{key}): EN: #{sub_role.title_translations['en']}, CH: #{sub_role.title_translations['zh_tw']} ParentRole(#{role.key}): #{role.title_translations['en']}" end sub_role end @@ -64,10 +62,10 @@ namespace :mid_site do user_model_mapper = Hash[:ut_cod => mid_user["ut_cod"] ,:up_ut_cod => mid_user["up_ut_cod"],:email => mid_user["eml_adr"],:off_tel_ext => mid_user["off_tel_ext"],:sta_num => mid_user["sta_num"]] user_model_mapper[:admin] = false local_user.update_attributes(user_model_mapper) - - i18n_department_admin = I18nVariable.find_or_create_by( :document_class => 'Role', :key => 'department_admin', :en => 'Department Admin', :zh_tw => '系所使用者' ) + + local_user.role = Role.find_or_create_by( :key => "department_admin",:build_in => true) - local_user.role.i18n_variable = i18n_department_admin + local_user.role.title_translations = {"en" => 'Department Admin', "zh_tw" => '系所使用者' } unless local_user.ut_cod == local_user.up_ut_cod #if the ut_cod has additions info for up ut @@ -128,15 +126,15 @@ namespace :mid_site do task :before_instll_admin => :environment do - var_1 = I18nVariable.find_or_create_by( :document_class => 'Role', :key => 'administrator', :en => 'Administrator', :zh_tw => '管理員' ) - var_1_1 = I18nVariable.find_or_create_by( :document_class => 'SubRole', :key => 'computer_center', :en => 'Computer Center', :zh_tw => '計算機中心', :parent_id => var_1.id ) + var_1 = {"en" => 'Administrator', "zh_tw" => '管理員' } + var_1_1 = {"en" => 'Computer Center', "zh_tw" => '計算機中心'} admin_role = Role.find_or_create_by( :key => 'administrator',:built_in => true) - admin_role.i18n_variable =var_1 + admin_role.title_translations =var_1 admin_role.save! sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center', :built_in => true) - sub_role.i18n_variable =var_1_1 + sub_role.title_translations =var_1_1 sub_role.save! #var_1_1_1 = I18nVariable.create!( :document_class => 'Attribute', :key => 'field', :en => 'Field', :zh_tw => '領域', :parent_id => var_1_1.id )