Migrating from Wackowiki to Wikkawiki


BACKUP YOUR DATABASE BEFORE UPGRADING!!!
BACKUP YOUR DATABASE BEFORE UPGRADING!!!


I've written the following script which makes a valiant effort to import an existing Wacko database into a newly-created Wikka database. Please note that I have tested this script only on Wacko version R3.5 and Wikka version 1.1.6.0; results may vary when using other versions.

#! /usr/bin/perl
#
# wacko_import.pl: An import utility to import a Wacko site into a
# *NEWLY CREATED* Wikka site
#
# Usage: Modify the parameters at the start of the script, between the
# ### markers. Immediately after installing Wikka 1.1.6.0, execute this
# script.
#
# Notes: This script is intended to be used against a newly-created
# Wikka database, and has been tested with Wacko R3.5 and Wikka 1.1.6.
# Results with any other version might be unpredictable.  Whatever you
# do, ALWAYS BACK UP YOUR DATABASE FIRST!  
#
# Copyright (c) 2005 Brian Koontz <brian@pongonova.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public Licence for more details:
#
#           http://www.gnu.org/copyleft/gpl.html
#
#####################################################################

use strict;
use DBI();

### Modify these ###

# Wacko DB
my $wacko_database = "wacko";
my $wacko_host = "127.0.0.1";
my $wacko_username = "wackouser";
my $wacko_password = "wacko_pass";
my $wacko_table_prefix = "wacko"; # No underscore!

# Wikka DB
my $wikka_database = "wikka";
my $wikka_host = "127.0.0.1";
my $wikka_username = "wikkauser";
my $wikka_password = "wikka_pass";
my $wikka_table_prefix = "wikka"; #No underscore!

my $RaiseError = 1;

### End modifications ###

# These pages are created by default during a Wikka install.  To avoid
# conflict with existing Wacko pages with the same name, any Wacko
# page that is imported and matches one of these will have a "2"
# appended (click PageIndex to view these after importing).
my @reserved_pages = qw( HomePage RecentChanges RecentlyCommented
UserSettings PageIndex WikkaReleaseNotes WikkaDocumentation
WantedPages OrphanedPages TextSearch TextSearchExpanded MyPages
MyChanges InterWiki PasswordForgotten WikiCategory CategoryWiki
CategoryCategory FormattingRules HighScores OwnedPages SandBox );

# Connect to DBs
my $wacko_dbh = DBI->connect("DBI:mysql:database=$wacko_database; host=$wacko_host",
                             "$wacko_username", "$wacko_password",
                             {'RaiseError' => $RaiseError});
my $wikka_dbh = DBI->connect("DBI:mysql:database=$wikka_database; host=$wikka_host",
                             "$wikka_username", "$wikka_password",
                             {'RaiseError' => $RaiseError});

#
# Convert acls table
#
# Wacko cols: page_tag(250) supertag privilege list
# Wikka cols: page_tag(75) read_acl write_acl comment_acl
my $sth = $wacko_dbh->prepare("SELECT * FROM ${wacko_table_prefix}_acls");
$sth->execute();
my $aclref = {};
while(my @row = $sth->fetchrow_array) {
    $row[3] = "+" if $row[3] =~ /\$/;
    $aclref->{substr($row[0],0,75)}->{$row[2]} = $row[3];
}
$sth = $wikka_dbh->prepare("INSERT INTO ${wikka_table_prefix}_acls VALUES (?,?,?,?)");
foreach(sort keys %$aclref) {
    $sth->execute($_,
                  $aclref->{$_}->{"read"},
                  $aclref->{$_}->{"write"},
                  $aclref->{$_}->{"comment"});
}

#
# Convert comments table
#
# Wacko cols: id tag(250) supertag(250) time body body_r owner user
#             latest handler comment_on
# Wikka cols: id page_tag(75) time comment user
$sth = $wacko_dbh->prepare("SELECT * FROM ${wacko_table_prefix}_pages");
$sth->execute();
my $commentsref = [];
while(my @row = $sth->fetchrow_array) {
    my $tmpref = [];
    next if $row[1] !~ /^Comment/;
    push(@$tmpref, ''); # id
    push(@$tmpref, substr($row[10],0,75)); # page_tag
    push(@$tmpref, $row[3]); # time
    push(@$tmpref, $row[4]); # comment
    push(@$tmpref, $row[7]); # user
    push(@$commentsref, $tmpref);
}
$sth = $wikka_dbh->prepare("INSERT INTO ${wikka_table_prefix}_comments VALUES (?,?,?,?,?)");
foreach my $comment (@$commentsref) {
    $sth->execute(@$comment);
}

#
# Convert links table
#
# Wacko cols: from_tag(250) to_tag(250)
# Wikka cols: from_tag(250) to_tag(250)
$sth = $wacko_dbh->prepare("SELECT * FROM ${wacko_table_prefix}_links");
$sth->execute();
my $linksref = [];
while(my @row = $sth->fetchrow_array) {
    my $tmpref = [];
    push(@$tmpref, substr($row[0],0,75)); # from_tag
    push(@$tmpref, substr($row[1],0,75)); # from_tag
    push(@$linksref, $tmpref);
}
$sth = $wikka_dbh->prepare("INSERT INTO ${wikka_table_prefix}_links VALUES (?,?)");
foreach my $link (@$linksref) {
    $sth->execute(@$link);
}

#
# Convert pages table
#
# Wacko cols: id tag(250) supertag(250) time body body_r owner user
#             latest handler comment_on
# Wikka cols: id tag(75) time body owner user latest note handler
$sth = $wacko_dbh->prepare("SELECT * FROM ${wacko_table_prefix}_pages");
$sth->execute();
my $pagesref = [];
while(my @row = $sth->fetchrow_array) {
    my $tmpref = [];
    push(@$tmpref, ''); # id
    my $page_title = substr($row[1],0,73);
    next if $page_title =~ /^Comment/; # Don't process comments as pages!
    if(scalar(grep /$page_title/, @reserved_pages)) {
        # Duplicate page name, so rename incoming page
        $page_title .= "2";
    }
    push(@$tmpref, $page_title); # tag
    push(@$tmpref, $row[3]); # time
    push(@$tmpref, $row[4]); # body
    push(@$tmpref, $row[6]); # owner
    push(@$tmpref, $row[7]); # user
    push(@$tmpref, $row[8]); # latest
    push(@$tmpref, ''); # note
    push(@$tmpref, $row[9]); # handler
    push(@$pagesref, $tmpref);
}
$sth = $wikka_dbh->prepare("INSERT INTO ${wikka_table_prefix}_pages VALUES (?,?,?,?,?,?,?,?,?)");
foreach my $page (@$pagesref) {
    $sth->execute(@$page);
}

#
# Convert links table
#
# Wacko cols: page_tag(250) referrer time
# Wikka cols: page_tag(250) referrer time
$sth = $wacko_dbh->prepare("SELECT * FROM ${wacko_table_prefix}_referrers");
$sth->execute();
my $referrersref = [];
while(my @row = $sth->fetchrow_array) {
    my $tmpref = [];
    push(@$tmpref, substr($row[0],0,75)); # page_tag
    push(@$tmpref, $row[1]); # referrer
    push(@$tmpref, $row[2]); # time
    push(@$referrersref, $tmpref);
}
$sth = $wikka_dbh->prepare("INSERT INTO ${wikka_table_prefix}_referrers VALUES (?,?,?)");
foreach my $referrer (@$referrersref) {
    $sth->execute(@$referrer);
}

#
# Convert users table
#
# Wacko cols: name(80) password email motto revisioncount changescount
#             doubleclickedit signuptime show_comments bookmarks lang
#             show_spaces showdatetime typografica
# Wikka cols: name(75) password email revisioncount changescount
#             doubleclickedit signuptime show_comments
$sth = $wacko_dbh->prepare("SELECT * FROM ${wacko_table_prefix}_users");
$sth->execute();
my $usersref = [];
while(my @row = $sth->fetchrow_array) {
    my $tmpref = [];
    push(@$tmpref, substr($row[0],0,75)); # name
    push(@$tmpref, $row[1]); # password
    push(@$tmpref, $row[2]); # email
    push(@$tmpref, $row[4]); # revisioncount
    push(@$tmpref, $row[5]); # changescount
    push(@$tmpref, $row[6]); # doubleclickedit
    push(@$tmpref, $row[7]); # signuptime
    push(@$tmpref, $row[8]); # signuptime
    push(@$usersref, $tmpref);
}
$sth = $wikka_dbh->prepare("INSERT INTO ${wikka_table_prefix}_users VALUES (?,?,?,?,?,?,?,?)");
foreach my $user (@$usersref) {
    eval {$sth->execute(@$user)};
    if($@) { next; }
}

# Close DB
$wacko_dbh->disconnect();
$wikka_dbh->disconnect();




CategoryUserContributions
CategoryDocumentation
There are 2 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki