Recent Topics

1 Sep 12, 2007 08:37    

My b2evolution Version: 1.10.x

Has anyone successfully merged two or more b2 installs? I've got three installs I'm planning on merging into one and am looking for the best process.

I'm thinking about creating MT export files for two of the blogs then importing them into the "main" b2 install. It seems like after each import I'll be able to write some crafty SQL statements that will change all the blog_id columns to a "new" blog. I'll have to keep the categories straight at the same time.

Does this seem like a decent methodology or is there an easier way I'm not imagining?

2 Sep 26, 2007 07:53

This is a perl script I cooked up to export from a b2evolution version 1.9.3 database to MT/b2import format for the purpose of merging multiple b2evolution installs. It requires both the DBI and HTML::Entities perl modules.

Lazy shortcuts I made:
* It assumes a single author for all the posts: admin ($default_user).
* It assumes all comments without a "comment_author" to be admin ($default_user).
* It only assigns the default category
* It only imports published comments


#!/usr/bin/perl

# steven b. cherry
# this script exports a MT compatible output file

use DBI;
use HTML::Entities;

my $driver      = "mysql";
my $database    = "b2evolution";  # replace with your db name
my $hostname    = "localhost";
my $name        = [mysql name];
my $password    = [secret];

my $default_user = "admin";

my $dsn = "DBI:mysql:database=$database;host=$hostname";

my $dbh = DBI->connect($dsn, $user, $password);

my $query = "SELECT * FROM evo_posts, evo_categories
WHERE evo_categories.cat_ID = evo_posts.post_main_cat_ID ORDER BY post_ID;";

$qth = $dbh->prepare($query);

$qth->execute;

while ( $row = $qth->fetchrow_hashref ) {

        print qq(AUTHOR: $default_user\n);
        print qq(TITLE: $row->{'post_title'}\n);
        print qq(DATE: $row->{'post_datecreated'}\n);
        print qq(PRIMARY CATEGORY: $row->{'cat_name'}\n);
        print qq(STATUS: publish\n);

        # section delimiter
        print "-----\n";

        print qq(BODY:\n);

        print qq($row->{'post_content'}\n);

        print "-----\n";

        ## comments ##
        my $cquery = "SELECT * FROM evo_comments
        WHERE evo_comments.comment_post_ID = $row->{'post_ID'} AND comment_status = 'published' ORDER BY comment_ID;";

        $cqth = $dbh->prepare($cquery);

        $cqth->execute;


        while ( $crow = $cqth->fetchrow_hashref ) {

                print qq(COMMENT:\n);

                if($crow->{'comment_author'}){
                        print qq(AUTHOR: $crow->{'comment_author'}\n);
                }
                else{
                        print qq(AUTHOR: $default_user\n);
                }

                print qq(EMAIL: $crow->{'comment_author_email'}\n) if $crow->{'comment_author_email'};
                print qq(URL: $crow->{'comment_author_url'}\n) if $crow->{'comment_author_url'};
                print qq(IP: $crow->{'comment_author_IP'}\n);
                print qq(DATE: $crow->{'comment_date'}\n);


                $crow->{'comment_content'} = encode_entities($crow->{'post_content'});

                print qq($crow->{'comment_content'});

        }


        print "--------\n";     # entry delimiter

}  ## while


$qth->finish;

I had to use HTML::Entities::encode_entities() on the comments or the import script would fail.

I also think it's worth mentioning that the MT-import utility doesn't exactly conform to the MT spec: http://www.sixapart.com/movabletype/docs/mtimport. I found that "AUTHOR:" must precede "TITLE:" in the export file which isn't covered in the format spec. So this script may or may not allow importing into MT.


Form is loading...