diff --git a/app/controllers/admin/import_data_controller.rb b/app/controllers/admin/import_data_controller.rb index 2660df84..acf67de9 100644 --- a/app/controllers/admin/import_data_controller.rb +++ b/app/controllers/admin/import_data_controller.rb @@ -8,7 +8,7 @@ class Admin::ImportDataController < OrbitBackendController # include Admin::FrontendWidgetInterface 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"} #uri.query = URI.encode_www_form(params) @@ -80,10 +80,10 @@ class Admin::ImportDataController < OrbitBackendController if hash.user_id.present? # ntu_seq = hash.ntu_seq 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/xmlData_useMail.asp?item=Book&account=#{u_account}")) - @books = books_xml.xpath("//Book").map do |book_node| + 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| { author: (book_node>"Authors").text, year: (book_node>"PublishYear").text, @@ -94,14 +94,14 @@ class Admin::ImportDataController < OrbitBackendController } end if @books.present? - @books.each do |b| - @book = WritingBook.new + @books.each do |b| + @book = WritingBook.new I18n.locale = :zh_tw - @book.authors = b[:author] - @book.paper_title = b[:title] - @book.book_title = b[:book_title] - @book.note = b[:remarks] - @book.publisher = b[:publisher] + @book.authors = b[:author] + @book.paper_title = b[:title] + @book.book_title = b[:book_title] + @book.note = b[:remarks] + @book.publisher = b[:publisher] I18n.locale = :en @book.authors = b[:author] @book.paper_title = b[:title] @@ -109,13 +109,13 @@ class Admin::ImportDataController < OrbitBackendController @book.note = b[:remarks] @book.publisher = b[:publisher] @book.year = b[:year] - @book.create_user_id = hash.id - @book.save - end + @book.create_user_id = hash.id + @book.save + end else - puts "No books by Teacher" + puts "No books by Teacher" end - end + end end end @@ -483,8 +483,7 @@ end def sync_conference_data_auto @user = User.all @user.each do |user| - @conference_data = WritingConference.where(create_user_id: "#{user.id}") - @conference_data.delete_all + WritingConference.delete_all(conditions:{create_user_id: "#{user.id}"}) # @user = User.find("#{params[:user_id]}") # teachers.each do |hash| @@ -563,8 +562,7 @@ end def sync_journal_paper_data_auto @user = User.all @user.each do |user| - @journal_data = WritingJournal.where(create_user_id: "#{user_id}") - @journal_data.delete_all + WritingJournal.delete_all(conditions:{create_user_id: "#{user.id}"}) # @user = User.find("#{params[:user_id]}") # teachers.each do |hash| @@ -632,7 +630,8 @@ def sync_journal_paper_data_auto @journal_paper.save! end end - + puts "Sync "+u_account+"\r\n" + sleep(5) end end end @@ -640,8 +639,7 @@ end def sync_book_data_auto @user = User.all @user.each do |user| - @books_data = WritingBook.where(create_user_id: "#{user_id}") - @books_data.delete_all + WritingBook.delete_all(conditions:{create_user_id: "#{user.id}"}) # @user = User.find("#{params[:user_id]}") # teachers.each do |hash| @@ -736,73 +734,4 @@ end @bulletin.save! 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