Current location

narf Source control manager Git

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshtrom <shtrom@1991c358-8f32-0410-a49a-990740bdf4c2>2014-04-22 11:29:26 +0000
committershtrom <shtrom@1991c358-8f32-0410-a49a-990740bdf4c2>2014-04-22 11:29:26 +0000
commit0dbb61d7030e4747e28aa7fabae8ebac2ee5ffb0 (patch)
tree0148eacf1c215cfda07585c8eb8a82d143607e23
parent25d44d795bb924548d6586176dde9d7aee45367d (diff)
Accessing blogsum articles
git-svn-id: svn+ssh://scm.narf.ssji.net/svn/shtrom/scripts@1805 1991c358-8f32-0410-a49a-990740bdf4c2
-rwxr-xr-xBlogsum2WP.rb53
1 files changed, 30 insertions, 23 deletions
diff --git a/Blogsum2WP.rb b/Blogsum2WP.rb
index 1971518..d4365f0 100755
--- a/Blogsum2WP.rb
+++ b/Blogsum2WP.rb
@@ -14,7 +14,7 @@ settings_file = './database.yml'
#
# blogsum:
# adapter: sqlite3
-# database: ~/site.db
+# database: /PATH/TO/site.db
#
# wordpress:
# adapter: mysql
@@ -26,45 +26,52 @@ settings_file = './database.yml'
exit unless File.exists?(settings_file)
$settings = YAML.load_file(settings_file)
-# Multiple database support from [1,2]
-# [1] http://jonathanng.com/ruby-on-rails/multiple-database-connections-with-rails/
-# [2] http://ilikestuffblog.com/2012/09/21/establishing-a-connection-to-a-non-default-database-in-rails-3-2-2
-class BlogsumTable < ActiveRecord::Base
- establish_connection $settings["blogsum"]
-end
-class WordpressTable < ActiveRecord::Base
- establish_connection $settings["wordpress"]
-end
-
# Blogsum
-class Article < BlogsumTable
- has_many :comments
+class Article < ActiveRecord::Base
+ establish_connection $settings["blogsum"]
+ has_many :comment
end
-class Comment < BlogsumTable
+class Comment < ActiveRecord::Base
+ establish_connection $settings["blogsum"]
+ belongs_to :article
end
# Wordpress
-class WpComment < WordpressTable
+class WpComment < ActiveRecord::Base
+ establish_connection $settings["wordpress"]
self.primary_key = :comment_ID
-
+ belongs_to :wp_post
+ has_many :wp_term_taxonomy, through: :wp_term_relationships
end
-class WpCommentmetum < WordpressTable
+class WpCommentmetum < ActiveRecord::Base
+ establish_connection $settings["wordpress"]
self.primary_key = :meta_id
end
-class WpPost < WordpressTable
+class WpPost < ActiveRecord::Base
+ establish_connection $settings["wordpress"]
self.primary_key = :ID
+ has_many :wp_comment
end
-class WpPostmetum < WordpressTable
+class WpPostmetum < ActiveRecord::Base
+ establish_connection $settings["wordpress"]
self.primary_key = :meta_id
end
-class WpTerm < WordpressTable
+class WpTerm < ActiveRecord::Base
+ establish_connection $settings["wordpress"]
self.primary_key = :term_id
+ belongs_to :wp_term_taxonomy
end
-class WpTermRelationship < WordpressTable
+class WpTermRelationship < ActiveRecord::Base
+ establish_connection $settings["wordpress"]
+ belongs_to :wp_post, foreign_key: :object_id
+ belongs_to :wp_term_taxonomy, foreign_key: :term_taxonomy_id
end
-class WpTermTaxonomy < WordpressTable
+class WpTermTaxonomy < ActiveRecord::Base
+ establish_connection $settings["wordpress"]
self.table_name = 'wp_term_taxonomy'
self.primary_key = :term_taxonomy_id
+ has_one :wp_term, foreign_key: :term_id
end
-# vim: sw=2
+puts Article.find(1).title
+puts Article.find(3).comment.instance_variables.map {|var| "#{var}: #{instance_variable_get(var)}"}