From 886b3d8bf9c82e85aed5fa16a70b35e9456fc817 Mon Sep 17 00:00:00 2001 From: Ivan Storck Date: Thu, 2 Jun 2011 16:05:16 -0700 Subject: [PATCH] ignore drafts and ignore duplicate titles --- lib/wordpress/post.rb | 44 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/wordpress/post.rb b/lib/wordpress/post.rb index f239020..96d338c 100644 --- a/lib/wordpress/post.rb +++ b/lib/wordpress/post.rb @@ -36,27 +36,35 @@ module Refinery unless user begin - is_draft = draft? ? "true" : false - p "creating post " + title + " Draft status: " + is_draft - post = ::BlogPost.create! :title => title, :body => content_formatted, :draft => draft?, - :published_at => post_date, :created_at => post_date, :author => user, - :tag_list => tag_list + is_draft = draft? ? "true" : "false" + if !draft? + p "creating post " + title + " Draft status: " + is_draft + post = ::BlogPost.create! :title => title, + :body => content_formatted, + :draft => draft?, + :published_at => post_date, + :created_at => post_date, + :author => user, + :tag_list => tag_list + ::BlogPost.transaction do + categories.each do |category| + post.categories << category.to_refinery + end + + comments.each do |comment| + comment = comment.to_refinery + comment.post = post + comment.save + end + end + + else + p "Skipping draft post" + end rescue Exception => e - # if it's not an activerecord validation error about duplicate title then raise e + # TODO if it's not an activerecord validation error about duplicate title then raise e p e end - - ::BlogPost.transaction do - categories.each do |category| - post.categories << category.to_refinery - end - - comments.each do |comment| - comment = comment.to_refinery - comment.post = post - comment.save - end - end post end