From e8f604b5ae689313de9c9dd08ef89c180935075a Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Mon, 8 Aug 2011 15:22:25 +0200 Subject: [PATCH] Added table prefix option to Drupal migration It's good practice in the Drupal community to always prefix the tables with something so that if you ever need to host two sites in the same database then you will easily know which tables belongs to which site. This commit adds an option to the Drupal migration scripts that makes it possible to add such a prefix to the migration query. --- lib/jekyll/migrators/drupal.rb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/jekyll/migrators/drupal.rb b/lib/jekyll/migrators/drupal.rb index 32e335cc..2301b0e5 100644 --- a/lib/jekyll/migrators/drupal.rb +++ b/lib/jekyll/migrators/drupal.rb @@ -14,19 +14,24 @@ module Jekyll # Reads a MySQL database via Sequel and creates a post file for each post # in wp_posts that has post_status = 'publish'. This restriction is made # because 'draft' posts are not guaranteed to have valid dates. - QUERY = "SELECT node.nid, \ - node.title, \ - node_revisions.body, \ - node.created, \ - node.status \ - FROM node, \ - node_revisions \ - WHERE (node.type = 'blog' OR node.type = 'story') \ - AND node.vid = node_revisions.vid" + QUERY = "SELECT n.nid, \ + n.title, \ + nr.body, \ + n.created, \ + n.status \ + FROM node AS n, \ + node_revisions AS nr \ + WHERE (n.type = 'blog' OR n.type = 'story') \ + AND n.vid = nr.vid" - def self.process(dbname, user, pass, host = 'localhost') + def self.process(dbname, user, pass, host = 'localhost', prefix = '') db = Sequel.mysql(dbname, :user => user, :password => pass, :host => host, :encoding => 'utf8') + if prefix != '' + QUERY[" node "] = " " + prefix + "node " + QUERY[" node_revisions "] = " " + prefix + "node_revisions " + end + FileUtils.mkdir_p "_posts" FileUtils.mkdir_p "_drafts"