Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wordpress - Add Site Prefix #203

Merged
merged 3 commits into from
Jun 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/jekyll-import/importers/wordpress.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def self.specify_options(c)
c.option 'password', '--password PW', "Database user's password (default: "")"
c.option 'host', '--host HOST', 'Database host name (default: "localhost")'
c.option 'table_prefix', '--table_prefix PREFIX', 'Table prefix name (default: "wp_")'
c.option 'site_prefix', '--site_prefix PREFIX', 'Site prefix name (default: "")'
c.option 'clean_entities', '--clean_entities', 'Whether to clean entities (default: true)'
c.option 'comments', '--comments', 'Whether to import comments (default: true)'
c.option 'categories', '--categories', 'Whether to import categories (default: true)'
Expand All @@ -41,6 +42,9 @@ def self.specify_options(c)
#
# :table_prefix:: Prefix of database tables used by WordPress.
# Default: 'wp_'
# :site_prefix:: Prefix of database tables used by WordPress
# Multisite, eg: 2_.
# Default: ''
# :clean_entities:: If true, convert non-ASCII characters to HTML
# entities in the posts, comments, titles, and
# names. Requires the 'htmlentities' gem to
Expand Down Expand Up @@ -75,6 +79,7 @@ def self.process(opts)
:socket => opts.fetch('socket', nil),
:dbname => opts.fetch('dbname', ''),
:table_prefix => opts.fetch('table_prefix', 'wp_'),
:site_prefix => opts.fetch('site_prefix', nil),
:clean_entities => opts.fetch('clean_entities', true),
:comments => opts.fetch('comments', true),
:categories => opts.fetch('categories', true),
Expand All @@ -101,6 +106,7 @@ def self.process(opts)
:socket => options[:socket], :host => options[:host], :encoding => 'utf8')

px = options[:table_prefix]
sx = options[:site_prefix]

page_name_list = {}

Expand All @@ -110,7 +116,7 @@ def self.process(opts)
posts.post_title AS `title`,
posts.post_name AS `slug`,
posts.post_parent AS `parent`
FROM #{px}posts AS `posts`
FROM #{px}#{sx}posts AS `posts`
WHERE posts.post_type = 'page'"

db[page_name_query].each do |page|
Expand Down Expand Up @@ -140,7 +146,7 @@ def self.process(opts)
users.user_login AS `author_login`,
users.user_email AS `author_email`,
users.user_url AS `author_url`
FROM #{px}posts AS `posts`
FROM #{px}#{sx}posts AS `posts`
LEFT JOIN #{px}users AS `users`
ON posts.post_author = users.ID"

Expand All @@ -162,6 +168,7 @@ def self.process(opts)

def self.process_post(post, db, options, page_name_list)
px = options[:table_prefix]
sx = options[:site_prefix]

title = post[:title]
if options[:clean_entities]
Expand Down Expand Up @@ -208,9 +215,9 @@ def self.process_post(post, db, options, page_name_list)
terms.name AS `name`,
ttax.taxonomy AS `type`
FROM
#{px}terms AS `terms`,
#{px}term_relationships AS `trels`,
#{px}term_taxonomy AS `ttax`
#{px}#{sx}terms AS `terms`,
#{px}#{sx}term_relationships AS `trels`,
#{px}#{sx}term_taxonomy AS `ttax`
WHERE
trels.object_id = '#{post[:id]}' AND
trels.term_taxonomy_id = ttax.term_taxonomy_id AND
Expand Down Expand Up @@ -245,7 +252,7 @@ def self.process_post(post, db, options, page_name_list)
comment_date AS `date`,
comment_date_gmt AS `date_gmt`,
comment_content AS `content`
FROM #{px}comments
FROM #{px}#{sx}comments
WHERE
comment_post_ID = '#{post[:id]}' AND
comment_approved != 'spam'"
Expand Down
1 change: 1 addition & 0 deletions site/_importers/wordpress.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $ ruby -rubygems -e 'require "jekyll-import";
"host" => "localhost",
"socket" => "",
"table_prefix" => "wp_",
"site_prefix" => "",
"clean_entities" => true,
"comments" => true,
"categories" => true,
Expand Down