forked from saurabh/orbit4-5
fixed bug for member uid problem old site, fixed porgress bar bugs for import
This commit is contained in:
parent
77b31482e5
commit
d2b38cd0da
|
@ -2,6 +2,7 @@
|
|||
require "net/http"
|
||||
require "uri"
|
||||
require 'json'
|
||||
require 'yaml'
|
||||
|
||||
class Admin::ImportController < OrbitAdminController
|
||||
layout "structure"
|
||||
|
@ -202,19 +203,23 @@ class Admin::ImportController < OrbitAdminController
|
|||
end
|
||||
|
||||
def rss2_pages
|
||||
delete_import_file
|
||||
uri = URI.parse(params['url'])
|
||||
@@thread = Thread.new do
|
||||
# @@thread = Thread.new do
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
request = Net::HTTP::Get.new(uri.request_uri)
|
||||
response = http.request(request)
|
||||
data = response.body
|
||||
data = JSON.parse(data)
|
||||
pages = data["pages"]
|
||||
@@import_stats["total"] = data["total_pages"].to_i
|
||||
@@import_stats["current_stattus"] = 0
|
||||
@@import_stats["total_pages"] = data["total_pages"].to_i
|
||||
@@import_stats["current_status"] = 0
|
||||
@@import_stats["success"] = true
|
||||
write_to_file
|
||||
pages.each do |page|
|
||||
@@import_stats["current_page"] = page["page_id"]
|
||||
@@import_stats["current_page_name"] = page["title"]["zh_tw"]
|
||||
write_to_file
|
||||
if Page.where(:rss2_id => page["page_id"]).count == 0
|
||||
page_id = page["page_id"]
|
||||
number = 0
|
||||
|
@ -231,12 +236,14 @@ class Admin::ImportController < OrbitAdminController
|
|||
p = Page.find_by(:rss2_id => page["page_id"])
|
||||
page_id = p.page_id
|
||||
end
|
||||
@@import_stats["current_stattus"] = @@import_stats["current_stattus"] + 1
|
||||
@@import_stats["current_status"] = @@import_stats["current_status"] + 1
|
||||
write_to_file
|
||||
if !page["childpages"].blank?
|
||||
childpages = page["childpages"]
|
||||
childpages.each_with_index do |childpage,i|
|
||||
@@import_stats["current_page"] = childpage["page_id"]
|
||||
@@import_stats["current_page_name"] = page["title"]["zh_tw"]
|
||||
write_to_file
|
||||
if Page.where(:rss2_id => childpage["page_id"]).count == 0
|
||||
p_id = page_id + "_" + i.to_s
|
||||
case childpage["type"]
|
||||
|
@ -262,53 +269,25 @@ class Admin::ImportController < OrbitAdminController
|
|||
cp.save
|
||||
end
|
||||
end
|
||||
@@import_stats["current_stattus"] = @@import_stats["current_stattus"] + 1
|
||||
@@import_stats["current_status"] = @@import_stats["current_status"] + 1
|
||||
write_to_file
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@thread.join
|
||||
@@thread.abort_on_exception = true
|
||||
# end
|
||||
# @@thread.join
|
||||
# @@thread.abort_on_exception = true
|
||||
render :json => {"success"=>true}.to_json
|
||||
end
|
||||
|
||||
def get_import_status
|
||||
case params["module"]
|
||||
when "pages"
|
||||
if @@thread.alive?
|
||||
render :json => {"success" => true, "total_pages" => @@import_stats["total"], "current_status" => @@import_stats["current_stattus"], "current_page" => @@import_stats["current_page"], "current_page_name" => @@import_stats["current_page_name"]}
|
||||
else
|
||||
if @@import_stats["current_stattus"] == @@import_stats["total"]
|
||||
render :json => {"success" => true, "total_pages" => @@import_stats["total"], "current_status" => @@import_stats["current_stattus"], "current_page" => @@import_stats["current_page"], "current_page_name" => @@import_stats["current_page_name"]}
|
||||
|
||||
else
|
||||
render :json => {"success" => false, "current_page" => @@import_stats["current_page"], "current_page_name" => @@import_stats["current_page_name"]}
|
||||
end
|
||||
end
|
||||
when "gallery"
|
||||
# if @@import_stats["current_status"] <= (@@import_stats["total_images"] + 1)
|
||||
# render :json => {"success" => true, "total_images" => @@import_stats["total_images"], "current_status" => @@import_stats["current_status"], "current_album_id" => @@import_stats["current_album_id"], "current_album_name" => @@import_stats["current_album_name"]}
|
||||
# elsif @@import_stats["current_status"] == @@import_stats["total_images"]
|
||||
# render :json => {"success" => true, "total_images" => @@import_stats["total_images"], "current_status" => @@import_stats["current_status"], "current_album_id" => @@import_stats["current_album_id"], "current_album_name" => @@import_stats["current_album_name"]}
|
||||
# else
|
||||
# render :json => {"success" => false, "current_album_id" => @@import_stats["current_album_id"], "current_album_name" => @@import_stats["current_album_name"]}
|
||||
# end
|
||||
render :json => @@import_stats.to_json
|
||||
when "links"
|
||||
if @@thread.alive?
|
||||
render :json => {"success" => true, "current_import" => @@import_stats["current_import"], "total_links" => @@import_stats["total_links"], "current_status" => @@import_stats["current_status"], "current_link_id" => @@import_stats["current_link_id"], "current_link_name" => @@import_stats["current_album_name"]}
|
||||
else
|
||||
if @@import_stats["current_status"] == @@import_stats["total_links"]
|
||||
render :json => {"success" => true, "current_import" => @@import_stats["current_import"], "total_links" => @@import_stats["total_links"], "current_status" => @@import_stats["current_status"], "current_link_id" => @@import_stats["current_link_id"], "current_link_name" => @@import_stats["current_link_name"]}
|
||||
else
|
||||
render :json => {"success" => false, "current_link_id" => @@import_stats["current_link_id"], "current_link_name" => @@import_stats["current_link_name"]}
|
||||
end
|
||||
end
|
||||
end
|
||||
settings = get_settings_from_import_file
|
||||
render :json => settings.to_json
|
||||
end
|
||||
|
||||
def rss2_galleries
|
||||
delete_import_file
|
||||
uri = URI.parse(params['url'])
|
||||
# @@thread = Thread.new do
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
|
@ -318,6 +297,8 @@ class Admin::ImportController < OrbitAdminController
|
|||
data = JSON.parse(data)
|
||||
@@import_stats["total_images"] = data["total_images"].to_i
|
||||
@@import_stats["current_status"] = 0
|
||||
@@import_stats["success"] = true
|
||||
write_to_file
|
||||
albums = data["albums"]
|
||||
current_locale = I18n.locale
|
||||
I18n.locale = :en
|
||||
|
@ -332,8 +313,10 @@ class Admin::ImportController < OrbitAdminController
|
|||
end
|
||||
albums.each do |album|
|
||||
@@import_stats["current_album_id"] = album["albumid"]
|
||||
write_to_file
|
||||
if Album.where(:rss2_id => album["albumid"]).count == 0
|
||||
@@import_stats["current_album_name"] = album["name"]["zh_tw"]
|
||||
write_to_file
|
||||
newalbum = Album.new(:name_translations => {"en" => album["name"]["en"], "zh_tw" => album["name"]["zh_tw"]}, :description_translations => {"en" => album["description"]["en"], "zh_tw" => album["description"]["zh_tw"]},"rss2_id" => album["albumid"])
|
||||
newalbum.category_id = category.id
|
||||
newalbum.save
|
||||
|
@ -347,6 +330,7 @@ class Admin::ImportController < OrbitAdminController
|
|||
img.save
|
||||
end
|
||||
@@import_stats["current_status"] = @@import_stats["current_status"] + 1
|
||||
write_to_file
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -358,8 +342,9 @@ class Admin::ImportController < OrbitAdminController
|
|||
end
|
||||
|
||||
def rss2_links
|
||||
delete_import_file
|
||||
uri = URI.parse(params['url'])
|
||||
@@thread = Thread.new do
|
||||
# @@thread = Thread.new do
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
request = Net::HTTP::Get.new(uri.request_uri)
|
||||
response = http.request(request)
|
||||
|
@ -368,6 +353,8 @@ class Admin::ImportController < OrbitAdminController
|
|||
@@import_stats["total_links"] = data["total_links"].to_i
|
||||
@@import_stats["current_import"] = "categories"
|
||||
@@import_stats["current_status"] = 0
|
||||
@@import_stats["success"] = true
|
||||
write_to_file
|
||||
categories = data["categories"]
|
||||
current_locale = I18n.locale
|
||||
I18n.locale = :zh_tw
|
||||
|
@ -382,23 +369,26 @@ class Admin::ImportController < OrbitAdminController
|
|||
end
|
||||
end
|
||||
@@import_stats["current_import"] = "links"
|
||||
write_to_file
|
||||
links = data["links"]
|
||||
links.each do |link|
|
||||
l = WebLink.where(:rss2_id => link["link_id"]).first
|
||||
if l.nil?
|
||||
@@import_stats["current_link_id"] = link["link_id"]
|
||||
@@import_stats["current_link_name"] = link["title"]["zh_tw"]
|
||||
write_to_file
|
||||
weblink = WebLink.new(:title_translations => {"en" => link["title"]["en"], "zh_tw" => link["title"]["zh_tw"]}, :context_translations => {:en => link["description"]["en"], :zh_tw => link["description"]["zh_tw"]}, :url_translations => {"en" => link["url"], "zh_tw" => link["url"]}, :rss2_id => link["link_id"])
|
||||
category = Category.where(:title => link["category_name"], :module_app_id => module_app).first
|
||||
weblink.category_id = category.id
|
||||
weblink.save
|
||||
end
|
||||
@@import_stats["current_status"] = @@import_stats["current_status"] + 1
|
||||
write_to_file
|
||||
end
|
||||
I18n.locale = current_locale
|
||||
end
|
||||
@@thread.join
|
||||
@@thread.abort_on_exception = true
|
||||
# end
|
||||
# @@thread.join
|
||||
# @@thread.abort_on_exception = true
|
||||
render :json => {"success" => true}.to_json
|
||||
end
|
||||
|
||||
|
@ -432,6 +422,24 @@ class Admin::ImportController < OrbitAdminController
|
|||
@data
|
||||
end
|
||||
|
||||
def write_to_file
|
||||
File.open("#{Rails.root.to_s}/public/import_status.yml", "w") do |file|
|
||||
file.write @@import_stats.to_yaml
|
||||
end
|
||||
end
|
||||
|
||||
def delete_import_file
|
||||
@@import_stats = {}
|
||||
f = File.join(Rails.root,"public","import_status")
|
||||
if File.exists?f
|
||||
File.delete(f)
|
||||
end
|
||||
end
|
||||
|
||||
def get_settings_from_import_file
|
||||
YAML::load_file "#{Rails.root.to_s}/public/import_status.yml"
|
||||
end
|
||||
|
||||
def get_user
|
||||
@user = User.find(current_user.id)
|
||||
end
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
end
|
||||
|
||||
def to_param
|
||||
if self.uid.blank?
|
||||
generate_uid
|
||||
self.save
|
||||
end
|
||||
(self.name.gsub(/[ "'*@#$%^&()+=;:.,?>|\\\/<~_!:,、。!?;「」〈〉【】/]/,'-')+"-"+self.uid).gsub(/-{2,}/,'-') rescue "-"+self.uid
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue