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

@ -6,7 +6,7 @@ module Admin::AnnouncementsHelper
def page_for_bulletin(bulletin) def page_for_bulletin(bulletin)
ann_page = nil ann_page = nil
pages = Page.where(:module=>'announcement') pages = Page.where(:module=>'announcement')
pages.each do |page| pages.each do |page|
if page.categories.count ==1 if page.categories.count ==1
if page.categories.include?(bulletin.category.id.to_s) if page.categories.include?(bulletin.category.id.to_s)
@ -129,7 +129,7 @@ module Admin::AnnouncementsHelper
mail = Email.new(:mail_to => email, :mail_subject => "Announcement rejected公告未通過 : #{announcement.title}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend}) mail = Email.new(:mail_to => email, :mail_subject => "Announcement rejected公告未通過 : #{announcement.title}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend})
mail.deliver rescue nil mail.deliver rescue nil
end end
end end
end end
def send_notification_mail_to_managers(announcement, type) def send_notification_mail_to_managers(announcement, type)
@ -163,7 +163,7 @@ module Admin::AnnouncementsHelper
def send_email(name, useremail, announcement, type) def send_email(name, useremail, announcement, type)
url = "http://#{request.host_with_port}/admin/announcements?url=#{page_for_bulletin(announcement).sub("http://" + request.host_with_port, "")}&id=#{announcement.id}" url = "http://#{request.host_with_port}/admin/announcements?url=#{page_for_bulletin(announcement).sub("http://" + request.host_with_port, "")}&id=#{announcement.id}"
case type case type
when "approval" when "approval"
datatosend = "<h3>#{t("announcement.approval_mail_hi", :name => name)},</h3><p>#{t("announcement.submitted_new_announcement", :poster => current_user.name)}<br /><br />#{t("announcement.approval_announcement_title")} : #{announcement.title} <br /> #{t("announcement.click_here_to_see")} : <a href='#{url}'> #{url} </a></p>" datatosend = "<h3>#{t("announcement.approval_mail_hi", :name => name)},</h3><p>#{t("announcement.submitted_new_announcement", :poster => current_user.name)}<br /><br />#{t("announcement.approval_announcement_title")} : #{announcement.title} <br /> #{t("announcement.click_here_to_see")} : <a href='#{url}'> #{url} </a></p>"
when "reapproval" when "reapproval"
@ -216,40 +216,46 @@ 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.new
bu.approved = true
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.postdate = itme.xpath('wp:post_date').text
itme.xpath('category').each do |i_cate|
if i_cate["domain"].to_s == "category"
cat = @module_app.categories.where(:title => i_cate.text.to_s).first rescue nil bu = Bulletin.where(:rss2_sn => itme.xpath('wp:post_id').text ).first rescue nil
if cat.nil? if bu.nil?
cat = Category.new bu = Bulletin.new
cat.module_app = @module_app bu.approved = true
cat.title_translations = {"en" => i_cate.text.to_s, "zh_tw" => i_cate.text.to_s} bu.rss2_sn = itme.xpath('wp:post_id').text
cat.save bu.title_translations = {"en" => itme.xpath('title').text, "zh_tw" => itme.xpath('title').text}
end 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.category = cat itme.xpath('category').each do |i_cate|
if i_cate["domain"].to_s == "category"
elsif i_cate["domain"].to_s == "post_tag" cat = @module_app.categories.where(:title => i_cate.text.to_s).first rescue nil
if cat.nil?
tag = Tag.where(:name => i_cate.text.to_s ) cat = Category.new
if tag.nil? == false cat.module_app = @module_app
tag = Tag.new cat.title_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} cat.save
tag.module_app_ids << @module_app.id end
tag.save bu.category = cat
end
bu.tags=tag elsif i_cate["domain"].to_s == "post_tag"
end
end tag = Tag.where(:name => i_cate.text.to_s ).first rescue nil
bu.save if tag.nil?
end tag = Tag.new
tag.name_translations = {"en" => i_cate.text.to_s, "zh_tw" => i_cate.text.to_s}
tag.module_app_ids << @module_app.id
tag.save
end
bu.tags = tag
end
end
bu.save
end
end
end end
File.delete(xmlfile) File.delete(xmlfile)
end end