2014-03-04 22:47:53 +00:00
|
|
|
module WordPressImport
|
|
|
|
class Post < Page
|
|
|
|
def tags
|
|
|
|
# xml dump has "post_tag" for wordpress 3.1 and "tag" for 3.0
|
|
|
|
path = if node.xpath("category[@domain='post_tag']").count > 0
|
|
|
|
"category[@domain='post_tag']"
|
|
|
|
else
|
|
|
|
"category[@domain='tag']"
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
2014-03-04 22:47:53 +00:00
|
|
|
node.xpath(path).collect do |tag_node|
|
|
|
|
Tag.new(tag_node.text)
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
2014-03-04 22:47:53 +00:00
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2014-03-04 22:47:53 +00:00
|
|
|
def tag_list
|
|
|
|
tags.collect(&:name).join(',')
|
|
|
|
end
|
|
|
|
|
|
|
|
def categories
|
|
|
|
node.xpath("category[@domain='category']").collect do |cat|
|
|
|
|
Category.new(cat.text)
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
2014-03-04 22:47:53 +00:00
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2014-03-04 22:47:53 +00:00
|
|
|
def comments
|
|
|
|
node.xpath("wp:comment").collect do |comment_node|
|
|
|
|
Comment.new(comment_node)
|
2011-06-02 12:41:31 +00:00
|
|
|
end
|
2014-03-04 22:47:53 +00:00
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2014-03-06 04:27:57 +00:00
|
|
|
def to_rails
|
2011-08-12 16:44:00 +00:00
|
|
|
|
2014-03-06 04:27:57 +00:00
|
|
|
user = ::User.find_by_wp_username(creator)
|
2011-06-03 09:02:25 +00:00
|
|
|
|
2014-03-06 04:27:57 +00:00
|
|
|
if user.nil?
|
|
|
|
raise "User with wp_username #{creator} not found"
|
2011-06-02 12:41:31 +00:00
|
|
|
end
|
2011-06-03 16:50:27 +00:00
|
|
|
|
2014-03-06 04:27:57 +00:00
|
|
|
post = ::Post.find_or_initialize_by(:id => post_id, :slug => post_name)
|
|
|
|
|
|
|
|
post.assign_attributes(
|
|
|
|
:user_id => user.id, :title => title,
|
|
|
|
:created_at => post_date,
|
|
|
|
:published_at => publish_date)
|
|
|
|
# :body => content_formatted taken care of by translation below
|
2014-03-04 22:47:53 +00:00
|
|
|
|
2014-03-06 04:27:57 +00:00
|
|
|
if post.translations.blank?
|
|
|
|
translation = post.translations.build
|
|
|
|
else
|
|
|
|
translation = post.translations.first
|
|
|
|
end
|
|
|
|
|
|
|
|
translation.locale = "en"
|
|
|
|
translation.title = title
|
|
|
|
translation.body = content_formatted
|
|
|
|
translation.save
|
|
|
|
|
|
|
|
post.save
|
2011-06-03 16:50:27 +00:00
|
|
|
|
2014-03-06 04:27:57 +00:00
|
|
|
if post.errors.blank?
|
|
|
|
return post.reload
|
|
|
|
else
|
|
|
|
puts post.inspect
|
|
|
|
raise post.errors.full_messages.to_s
|
2011-06-03 16:50:27 +00:00
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
2014-03-04 22:47:53 +00:00
|
|
|
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
end
|