fix post_tag and if bulletin's rss2_sn is the same not insert

This commit is contained in:
tseng yen chi 2017-02-03 17:12:37 +08:00
parent 673afd2f5a
commit d6cb086a4a
1 changed files with 39 additions and 33 deletions

View File

@ -216,8 +216,12 @@ module Admin::AnnouncementsHelper
doc.xpath("//channel").each do|channel_data| doc.xpath("//channel").each do|channel_data|
channel_data.xpath('//item').each do|itme| channel_data.xpath('//item').each do|itme|
bu = Bulletin.where(:rss2_sn => itme.xpath('wp:post_id').text ).first rescue nil
if bu.nil?
bu = Bulletin.new bu = Bulletin.new
bu.approved = true bu.approved = true
bu.rss2_sn = itme.xpath('wp:post_id').text
bu.title_translations = {"en" => itme.xpath('title').text, "zh_tw" => itme.xpath('title').text} bu.title_translations = {"en" => itme.xpath('title').text, "zh_tw" => itme.xpath('title').text}
bu.text_translations = {"en" => itme.xpath('content:encoded').text, "zh_tw" => itme.xpath('content:encoded').text} bu.text_translations = {"en" => itme.xpath('content:encoded').text, "zh_tw" => itme.xpath('content:encoded').text}
bu.postdate = itme.xpath('wp:post_date').text bu.postdate = itme.xpath('wp:post_date').text
@ -232,24 +236,26 @@ module Admin::AnnouncementsHelper
cat.title_translations = {"en" => i_cate.text.to_s, "zh_tw" => i_cate.text.to_s} cat.title_translations = {"en" => i_cate.text.to_s, "zh_tw" => i_cate.text.to_s}
cat.save cat.save
end end
bu.category = cat bu.category = cat
elsif i_cate["domain"].to_s == "post_tag" elsif i_cate["domain"].to_s == "post_tag"
tag = Tag.where(:name => i_cate.text.to_s ) tag = Tag.where(:name => i_cate.text.to_s ).first rescue nil
if tag.nil? == false if tag.nil?
tag = Tag.new tag = Tag.new
tag.name_translations = {"en" => i_cate.text.to_s, "zh_tw" => i_cate.text.to_s} tag.name_translations = {"en" => i_cate.text.to_s, "zh_tw" => i_cate.text.to_s}
tag.module_app_ids << @module_app.id tag.module_app_ids << @module_app.id
tag.save tag.save
end end
bu.tags=tag bu.tags = tag
end end
end end
bu.save bu.save
end end
end
end end
File.delete(xmlfile) File.delete(xmlfile)
end end