Fix sync auto not deleting old data

This commit is contained in:
manson666 2013-12-30 18:53:14 +08:00 committed by Manson Wang
parent 3375a41106
commit da75ac771c
1 changed files with 21 additions and 92 deletions

View File

@ -8,7 +8,7 @@ class Admin::ImportDataController < OrbitBackendController
# include Admin::FrontendWidgetInterface # include Admin::FrontendWidgetInterface
def get_teacher_data def get_teacher_data
uri = URI("https://localhost:8000/teachers.xml") uri = URI("https://localhost:8000/teachers.xml")
#params = {"UnitName" => "管理學院".encode('big5-uao'), "account" => "manage"} #params = {"UnitName" => "管理學院".encode('big5-uao'), "account" => "manage"}
#uri.query = URI.encode_www_form(params) #uri.query = URI.encode_www_form(params)
@ -80,10 +80,10 @@ class Admin::ImportDataController < OrbitBackendController
if hash.user_id.present? if hash.user_id.present?
# ntu_seq = hash.ntu_seq # ntu_seq = hash.ntu_seq
u_account = hash.user_id u_account = hash.user_id
books_xml = Nokogiri::XML( \ books_xml = Nokogiri::XML( \
# open("http://ann.cc.ntu.edu.tw/Achv/xmlBook.asp?Seq=#{ntu_seq}")) # open("http://ann.cc.ntu.edu.tw/Achv/xmlBook.asp?Seq=#{ntu_seq}"))
open("http://ann.cc.ntu.edu.tw/Achv/xmlData_useMail.asp?item=Book&account=#{u_account}")) open("http://ann.cc.ntu.edu.tw/Achv/xmlData_useMail.asp?item=Book&account=#{u_account}"))
@books = books_xml.xpath("//Book").map do |book_node| @books = books_xml.xpath("//Book").map do |book_node|
{ {
author: (book_node>"Authors").text, author: (book_node>"Authors").text,
year: (book_node>"PublishYear").text, year: (book_node>"PublishYear").text,
@ -94,14 +94,14 @@ class Admin::ImportDataController < OrbitBackendController
} }
end end
if @books.present? if @books.present?
@books.each do |b| @books.each do |b|
@book = WritingBook.new @book = WritingBook.new
I18n.locale = :zh_tw I18n.locale = :zh_tw
@book.authors = b[:author] @book.authors = b[:author]
@book.paper_title = b[:title] @book.paper_title = b[:title]
@book.book_title = b[:book_title] @book.book_title = b[:book_title]
@book.note = b[:remarks] @book.note = b[:remarks]
@book.publisher = b[:publisher] @book.publisher = b[:publisher]
I18n.locale = :en I18n.locale = :en
@book.authors = b[:author] @book.authors = b[:author]
@book.paper_title = b[:title] @book.paper_title = b[:title]
@ -109,13 +109,13 @@ class Admin::ImportDataController < OrbitBackendController
@book.note = b[:remarks] @book.note = b[:remarks]
@book.publisher = b[:publisher] @book.publisher = b[:publisher]
@book.year = b[:year] @book.year = b[:year]
@book.create_user_id = hash.id @book.create_user_id = hash.id
@book.save @book.save
end end
else else
puts "No books by Teacher" puts "No books by Teacher"
end end
end end
end end
end end
@ -483,8 +483,7 @@ end
def sync_conference_data_auto def sync_conference_data_auto
@user = User.all @user = User.all
@user.each do |user| @user.each do |user|
@conference_data = WritingConference.where(create_user_id: "#{user.id}") WritingConference.delete_all(conditions:{create_user_id: "#{user.id}"})
@conference_data.delete_all
# @user = User.find("#{params[:user_id]}") # @user = User.find("#{params[:user_id]}")
# teachers.each do |hash| # teachers.each do |hash|
@ -563,8 +562,7 @@ end
def sync_journal_paper_data_auto def sync_journal_paper_data_auto
@user = User.all @user = User.all
@user.each do |user| @user.each do |user|
@journal_data = WritingJournal.where(create_user_id: "#{user_id}") WritingJournal.delete_all(conditions:{create_user_id: "#{user.id}"})
@journal_data.delete_all
# @user = User.find("#{params[:user_id]}") # @user = User.find("#{params[:user_id]}")
# teachers.each do |hash| # teachers.each do |hash|
@ -632,7 +630,8 @@ def sync_journal_paper_data_auto
@journal_paper.save! @journal_paper.save!
end end
end end
puts "Sync "+u_account+"\r\n"
sleep(5)
end end
end end
end end
@ -640,8 +639,7 @@ end
def sync_book_data_auto def sync_book_data_auto
@user = User.all @user = User.all
@user.each do |user| @user.each do |user|
@books_data = WritingBook.where(create_user_id: "#{user_id}") WritingBook.delete_all(conditions:{create_user_id: "#{user.id}"})
@books_data.delete_all
# @user = User.find("#{params[:user_id]}") # @user = User.find("#{params[:user_id]}")
# teachers.each do |hash| # teachers.each do |hash|
@ -736,73 +734,4 @@ end
@bulletin.save! @bulletin.save!
end end
end end
# def get_page_data
# f = File.open("/home/rwub/orbit-db/ntu_mb/pages/management_pages.xml")
# page_xml = Nokogiri::XML(f)
# #open("http://versatile.management.ntu.edu.tw/publication1/conference/#{ntuseq}.xml"))
# @pages = page_xml.xpath("//management-page").map do |cp_node|
# {
# menu_title: (cp_node>"menu-title").text,
# content: (cp_node>"content").text
# }
# end
# if @pages.present?
# @i=0
# @pages.each do |b|
# get_variables_for_new
# @page = Page.new
# @page.parent = "4f45f3b9e9d02c5db900005d"
# @page.design = "50ac424983e75219d2000021"
# @page.theme_id = "50ac424a83e75219d2000025"
# @page.menu_enabled_for= ["en", "zh_tw", ""]
# @page.enabled_for= ["en", "zh_tw", ""]
# @page.is_published = false
# if b[:menu_title].blank?
# @page.title = 'No Title Present'
# @i += 1
# @page.name = "#{@i}Page"
# else
# @i += 1
# @page.title = b[:menu_title]
# @page.name = "#{@i}Page"
# end
# if b[:content].blank?
# @page.content = "No Content Present"
# else
# @page.content = b[:content]
# end
# @page.save!
# end
# else
# puts "No Page Data"
# end
# end
# def get_variables_for_new
# @designs = Design.all.entries
# @themes = Design.first.themes
# @module_apps = ModuleApp.for_frontend_select
# @app_frontend_urls = nil
# @categories = nil
# @tags = nil
# @page_frontend_data_counts = nil
# @frontend_styles = nil
# @selected={
# :design => @designs.first,
# :theme=> @themes.first,
# :module_app=>nil,#@module_apps.first
# :app_frontend_url=> nil, #@module_apps.first
# :category=>nil,
# :tag=>nil,
# :page_frontend_data_count=>nil,
# :frontend_style => nil
# }
# end
end end