diff options
author | shtrom <shtrom@1991c358-8f32-0410-a49a-990740bdf4c2> | 2014-04-22 14:38:31 +0000 |
---|---|---|
committer | shtrom <shtrom@1991c358-8f32-0410-a49a-990740bdf4c2> | 2014-04-22 14:38:31 +0000 |
commit | 0846504be498cbdd6090362c8689db9e0c63b073 (patch) | |
tree | 86369094e660a383292b1c29d24e96825de77cd5 | |
parent | da5242c4a2b96eda09fe35f155505ceef69fb368 (diff) |
Wow, this seems to have worked
git-svn-id: svn+ssh://scm.narf.ssji.net/svn/shtrom/scripts@1809 1991c358-8f32-0410-a49a-990740bdf4c2
-rwxr-xr-x | Blogsum2WP.rb | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/Blogsum2WP.rb b/Blogsum2WP.rb index 0fb7e13..ec0a912 100755 --- a/Blogsum2WP.rb +++ b/Blogsum2WP.rb @@ -42,6 +42,7 @@ class WpComment < ActiveRecord::Base self.primary_key = :comment_ID has_many :wp_commentmeta belongs_to :wp_post + belongs_to :wp_user end class WpCommentmetum < ActiveRecord::Base establish_connection $settings["wordpress"] @@ -85,7 +86,7 @@ class WpUser < ActiveRecord::Base establish_connection $settings["wordpress"] self.primary_key = :ID has_many :wp_posts, foreign_key: :post_author - has_many :wp_comments + has_many :wp_comments, foreign_key: :user_id end # Blogsum @@ -101,7 +102,64 @@ end Article.all.each do |a| print "P #{a.title} #{a.date} #{a.author} #{a.uri} #{a.tags} #{a.body[0..19]}\n" - a.comments.each do |c| - print "C #{c.name} #{c.email} #{c.url} #{c.date} #{c.comment[0..19]}\n" + u = WpUser.find_by_user_login(a.author) || WpUser.all[0] # Map unknown users to admin + p = WpPost.find_by_post_title(a.title) || WpPost.create( + post_author: u.id, + post_date: a.date, + post_date_gmt: a.date, + post_content: a.body, + post_title: a.title, + post_excerpt: "", + post_name: a.uri, + to_ping: "", + pinged: "", + post_content_filtered: "", + ) + a.tags.split(/\ *, */).each do |tg| + t = WpTerm.find_by_name(tg) + if t.nil? + puts "New tag #{tg}" + t = WpTerm.create( + name: tg, + slug: tg.downcase.gsub(/ /, "-"), + ) + tt = WpTermTaxonomy.create( + term_id: t.term_id, + description: "", + taxonomy: "post_tag", + ) + t.save + tt.save + end + begin + tt = WpTermTaxonomy.find_by_term_id(t.term_id) + tr = WpTermRelationship.create( + term_taxonomy_id: tt.term_taxonomy_id, + object_id: p.ID, + ) + tr.save + rescue + # the relationship already exists + end end + + a.comments.each do |cm| + print "C #{cm.name} #{cm.email} #{cm.url} #{cm.date} #{cm.comment[0..19]}\n" + c = WpComment.find_by_comment_content(cm.comment) || WpComment.create( + comment_author: cm.name, + comment_author_email: cm.email, + comment_author_url: cm.url, + comment_date: cm.date, + comment_date_gmt: cm.date, + comment_content: cm.comment, + ) + cu = WpUser.find_by_user_email(cm.email) + if not cu.nil? + c.wp_user = cu.id + end + p.wp_comments << c + c.save + end + p.comment_count = p.wp_comments.length + p.save end |