ignore drafts and ignore duplicate titles
This commit is contained in:
parent
f254bb9216
commit
886b3d8bf9
|
@ -36,27 +36,35 @@ module Refinery
|
||||||
unless user
|
unless user
|
||||||
|
|
||||||
begin
|
begin
|
||||||
is_draft = draft? ? "true" : false
|
is_draft = draft? ? "true" : "false"
|
||||||
p "creating post " + title + " Draft status: " + is_draft
|
if !draft?
|
||||||
post = ::BlogPost.create! :title => title, :body => content_formatted, :draft => draft?,
|
p "creating post " + title + " Draft status: " + is_draft
|
||||||
:published_at => post_date, :created_at => post_date, :author => user,
|
post = ::BlogPost.create! :title => title,
|
||||||
:tag_list => tag_list
|
: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
|
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
|
p e
|
||||||
end
|
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
|
post
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user