更新「fgu_sync.rake」
This commit is contained in:
parent
0776ba723d
commit
0eae8b354e
|
@ -4,6 +4,7 @@ namespace :fgu_sync do
|
||||||
task :sync_plugins => :environment do
|
task :sync_plugins => :environment do
|
||||||
MemberProfile.each do |mp|
|
MemberProfile.each do |mp|
|
||||||
staff_id = mp.sid rescue nil
|
staff_id = mp.sid rescue nil
|
||||||
|
puts mp.id
|
||||||
if !staff_id.nil? && staff_id != ""
|
if !staff_id.nil? && staff_id != ""
|
||||||
sync_fgu_journals(staff_id, mp)
|
sync_fgu_journals(staff_id, mp)
|
||||||
sync_fgu_conference(staff_id, mp)
|
sync_fgu_conference(staff_id, mp)
|
||||||
|
@ -49,9 +50,9 @@ namespace :fgu_sync do
|
||||||
journal_title = {"en" => dt["journal_title"],"zh_tw" => dt["journal_title"]}
|
journal_title = {"en" => dt["journal_title"],"zh_tw" => dt["journal_title"]}
|
||||||
from_to = dt["from_to"].split("-")
|
from_to = dt["from_to"].split("-")
|
||||||
from_to[1] = "" if !from_to[1].present?
|
from_to[1] = "" if !from_to[1].present?
|
||||||
authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
|
all_authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
|
||||||
authors.delete("")
|
all_authors.delete("")
|
||||||
authors = {"en" => authors.join(", "), "zh_tw" => authors.join(", ")}
|
authors = {"en" => all_authors.join(", "), "zh_tw" => all_authors.join(", ")}
|
||||||
note = dt["department"] + " " + dt["country"] + " " + dt["note"]
|
note = dt["department"] + " " + dt["country"] + " " + dt["note"]
|
||||||
|
|
||||||
if !dt["paper_level"].empty?
|
if !dt["paper_level"].empty?
|
||||||
|
@ -69,19 +70,24 @@ namespace :fgu_sync do
|
||||||
end
|
end
|
||||||
|
|
||||||
jp = JournalPaper.where(:rss2_id => rss2id).first rescue nil
|
jp = JournalPaper.where(:rss2_id => rss2id).first rescue nil
|
||||||
|
jp_data = {
|
||||||
|
:publication_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"),
|
||||||
|
:authors_translations => authors, :paper_title_translations => paper_title,
|
||||||
|
:journal_title_translations => journal_title, :vol_no => dt["vol_no"], :issue_no => dt["issue_no"],
|
||||||
|
:note => note, :form_to_start => from_to[0], :form_to_end => from_to[1]
|
||||||
|
}
|
||||||
if jp.nil?
|
if jp.nil?
|
||||||
jp = JournalPaper.new(:publication_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :journal_title_translations => journal_title, :vol_no => dt["vol_no"], :issue_no => dt["issue_no"], :note => note, :form_to_start => from_to[0], :form_to_end => from_to[1], :member_profile => mp)
|
jp = JournalPaper.new(jp_data)
|
||||||
jp.journal_levels << level if !level.nil?
|
|
||||||
jp.journal_paper_type = type if !type.nil?
|
|
||||||
jp.save
|
|
||||||
puts "Saving new journal."
|
puts "Saving new journal."
|
||||||
else
|
else
|
||||||
jp.update_attributes(:publication_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :journal_title_translations => journal_title, :vol_no => dt["vol_no"], :issue_no => dt["issue_no"], :note => note, :form_to_start => from_to[0], :form_to_end => from_to[1])
|
jp.update_attributes(jp_data)
|
||||||
|
puts "Updating journal #{jp.id}."
|
||||||
|
end
|
||||||
|
jp_mps = MemberProfile.where("tmp_name.zh_tw" => {"$in" => all_authors}).to_a
|
||||||
|
jp.member_profiles = jp_mps.size==0 ? [mp] : jp_mps
|
||||||
jp.journal_levels << level if !level.nil?
|
jp.journal_levels << level if !level.nil?
|
||||||
jp.journal_paper_type = type if !type.nil?
|
jp.journal_paper_type = type if !type.nil?
|
||||||
jp.save
|
jp.save
|
||||||
puts "Updating journal #{jp.id}."
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts "No data found."
|
puts "No data found."
|
||||||
|
@ -112,14 +118,16 @@ namespace :fgu_sync do
|
||||||
note = dt["department"] + " " + dt["note"]
|
note = dt["department"] + " " + dt["note"]
|
||||||
|
|
||||||
cp = WritingConference.where(:rss2_id => rss2id).first rescue nil
|
cp = WritingConference.where(:rss2_id => rss2id).first rescue nil
|
||||||
|
cp_data = {:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => end_date.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :location_translations => {"en" => dt["location"], "zh_tw" => dt["location"]}}
|
||||||
if cp.nil?
|
if cp.nil?
|
||||||
cp = WritingConference.new(:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => end_date.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :member_profile => mp, :location_translations => {"en" => dt["location"], "zh_tw" => dt["location"]})
|
cp = WritingConference.new(cp_data)
|
||||||
cp.save
|
|
||||||
puts "Saving new conference."
|
puts "Saving new conference."
|
||||||
else
|
else
|
||||||
cp.update_attributes(:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => end_date.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :location_translations => {"en" => dt["location"], "zh_tw" => dt["location"]})
|
cp.update_attributes(cp_data)
|
||||||
puts "Updating conference #{cp.id}."
|
puts "Updating conference #{cp.id}."
|
||||||
end
|
end
|
||||||
|
cp.member_profile = mp
|
||||||
|
cp.save
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts "No data found."
|
puts "No data found."
|
||||||
|
@ -163,19 +171,18 @@ namespace :fgu_sync do
|
||||||
end
|
end
|
||||||
|
|
||||||
book = Book.where(:rss2_id => rss2id).first rescue nil
|
book = Book.where(:rss2_id => rss2id).first rescue nil
|
||||||
|
book_data = {:publish_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp}
|
||||||
if book.nil?
|
if book.nil?
|
||||||
book = Book.new(:publish_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp)
|
book = Book.new(book_data)
|
||||||
book.book_author_types << authortype if !authortype.nil?
|
|
||||||
book.book_type = type if !type.nil?
|
|
||||||
book.save
|
|
||||||
puts "Saving new book."
|
puts "Saving new book."
|
||||||
else
|
else
|
||||||
book.update_attributes(:publish_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp)
|
book.update_attributes(book_data)
|
||||||
book.book_author_types << authortype if !authortype.nil?
|
|
||||||
book.book_type = type if !type.nil?
|
|
||||||
book.save
|
|
||||||
puts "Updating book #{book.id}."
|
puts "Updating book #{book.id}."
|
||||||
end
|
end
|
||||||
|
book.book_author_types << authortype if !authortype.nil?
|
||||||
|
book.book_type = type if !type.nil?
|
||||||
|
book.member_profile = mp
|
||||||
|
book.save
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts "No data found."
|
puts "No data found."
|
||||||
|
|
Loading…
Reference in New Issue