From f254bb921688400c2ad123fee8c07be82b515c02 Mon Sep 17 00:00:00 2001 From: Ivan Storck Date: Thu, 2 Jun 2011 14:26:18 -0700 Subject: [PATCH 1/3] work in progress on duplicate title issue --- lib/wordpress/post.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/wordpress/post.rb b/lib/wordpress/post.rb index 51d5bef..f239020 100644 --- a/lib/wordpress/post.rb +++ b/lib/wordpress/post.rb @@ -34,11 +34,18 @@ module Refinery user = ::User.find_by_username(creator) || ::User.first raise "Referenced User doesn't exist! Make sure the authors are imported first." \ unless user - - post = ::BlogPost.create! :title => title, :body => content_formatted, :draft => draft?, + + 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 - + rescue Exception => e + # 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 From 886b3d8bf9c82e85aed5fa16a70b35e9456fc817 Mon Sep 17 00:00:00 2001 From: Ivan Storck Date: Thu, 2 Jun 2011 16:05:16 -0700 Subject: [PATCH 2/3] 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 From 4c860a053670380e06c0a3e1e8c75b3a604c7271 Mon Sep 17 00:00:00 2001 From: Ivan Storck Date: Thu, 2 Jun 2011 16:07:25 -0700 Subject: [PATCH 3/3] added explanation on ignoring drafts and duplicate titles to readme --- README.rdoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 478a23b..f175a39 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,9 +1,11 @@ = Refinerycms-wordpress-import -This project ist an importer for WordPress XML dumps into refinerycms(-blog). +This project is an importer for WordPress XML dumps into refinerycms(-blog). So far, only blog-relevant data gets imported, I'm working on the cms pages part. +Draft posts and posts with duplicate post titles are ignored (for now) + == Installation As there is no official release out yet, just add this repos to your projects Gemfile: