It is now possible to ignore draft posts on import.
* refactored the code sent by SustainableWebsites * made the ignore feature optional via ENV variable * added docs
This commit is contained in:
@@ -25,10 +25,12 @@ module Refinery
|
||||
end
|
||||
end
|
||||
|
||||
def posts
|
||||
doc.xpath("//item[wp:post_type = 'post']").collect do |post|
|
||||
def posts(only_published=false)
|
||||
posts = doc.xpath("//item[wp:post_type = 'post']").collect do |post|
|
||||
Post.new(post)
|
||||
end
|
||||
posts = posts.select(&:published?) if only_published
|
||||
posts
|
||||
end
|
||||
|
||||
def tags
|
||||
|
||||
@@ -71,6 +71,10 @@ module Refinery
|
||||
status != 'publish'
|
||||
end
|
||||
|
||||
def published?
|
||||
! draft?
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
post_id == other.post_id
|
||||
end
|
||||
|
||||
@@ -36,24 +36,20 @@ module Refinery
|
||||
unless user
|
||||
|
||||
begin
|
||||
unless draft?
|
||||
#p "creating post " + title + " Draft status: " + draft?.to_s
|
||||
|
||||
post = ::BlogPost.new :title => title, :body => content_formatted,
|
||||
:draft => draft?, :published_at => post_date, :created_at => post_date,
|
||||
:author => user, :tag_list => tag_list
|
||||
post.save!
|
||||
post = ::BlogPost.new :title => title, :body => content_formatted,
|
||||
:draft => draft?, :published_at => post_date, :created_at => post_date,
|
||||
:author => user, :tag_list => tag_list
|
||||
post.save!
|
||||
|
||||
::BlogPost.transaction do
|
||||
categories.each do |category|
|
||||
post.categories << category.to_refinery
|
||||
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
|
||||
comments.each do |comment|
|
||||
comment = comment.to_refinery
|
||||
comment.post = post
|
||||
comment.save
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
|
||||
Reference in New Issue
Block a user