ignore drafts and ignore duplicate titles
This commit is contained in:
parent
f254bb9216
commit
886b3d8bf9
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user