Subject: PostNuke to GeekLog conversion

Posted on: 21/08/03 10:10pm
By: kiltotter

Hi there ladies and gentlemen... I would like to convert a postnuke web site to geeklog (move the stories, comments, and so forth), but have no idea where to start.

There was a post on here some time ago about a covnersion script, but that is no longer a working link... so... here\'s my call for assistance.

Anyone able to help?

Thanks
Kilty


Re:PostNuke to GeekLog conversion

Posted on: 21/08/03 11:11pm
By: knuckles

You can find the scripts to get you started right here. Note that you should be fairly comfortable with working in PHP and your DB to customize certain portions for your own setup.

Re:PostNuke to GeekLog conversion

Posted on: 21/08/03 11:41pm
By: Anonymous

Surprised!

Thankyou Simon for the help

- I will be giving that a go

- thankyou for the fast and pleasant support

- some companies out there could learn a few things.

Ady


PostNuke to GeekLog conversion

Posted on: 27/03/04 08:38pm
By: Anonymous

Hi,

I run a postnuke site, and now i am moving to GL, has it rocks
(much faster)

I am using the script to convert the DB, but I am running into troubles.
after fixing a part of the script, i am getting this now:

error with query: (0, '', '', '5f4dcc3b5aa765d61d8327deb882cf99', '', '2004-03-28 02:34:37')

I know it's coming from this part of the script:
}
$uids[] = $gl_users[$hash["uname"]];
//printf("uid [%d]n", $gl_users[$hash["uname"]]);
// print "$sqln";
( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING);
}

could someone please help me solve my issue,
thanks a lot guys.

Stephane
www.sitting-ducks.net/index.php (new website)
www.sitting-ducks.net (old one)

PostNuke to GeekLog conversion

Posted on: 27/03/04 09:52pm
By: Blaine

I don't really see the SQL query - just the data. It appears to be part of an INSERT statement

PostNuke to GeekLog conversion

Posted on: 27/03/04 10:56pm
By: Anonymous

I have done more research on the script :

$sql = "insert into gl_stories (sid, nuke_sid, uid, tid, date, title, introtext, bodytext) values ";
print "[ OK ]n";


$sql .= sprintf("('%s', %d, %d, '%s', '%s', '%s', '%s', '%s')",
$gl_sid,
$hash['sid'],
$gl_uid,
$gl_tid,
$hash['time'],
addslashes($hash['title']),
addslashes($hash['hometext']),
addslashes($hash['bodytext'])
);

//print "$sqln";
mysql_query($sql) or DIE("error with query: $sql");
//( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING);
}



and when i run it it get stuck at :
$sql .= sprintf("('% .............


argh, i really need this script to work. I have several website to migrate.
HELP please

Stephane

PostNuke to GeekLog conversion

Posted on: 27/03/04 10:57pm
By: Anonymous

a bit more :

Warning: query failed: [insert into gl_stories (sid, nuke_sid, uid, tid, date, title, introtext, bodytext) values

PostNuke to GeekLog conversion

Posted on: 27/03/04 11:07pm
By: Blaine

I'd suggest you test the assignment and build of the SQL statement.

Test the sprintf statement and determine if there is a bad parameter being based in - one thats not assigned possibly.

You can also use phpMyAdmin to test the SQL statement once you get it being assigned correctly. There obviously needs to be a value for each field in the INSERT stmt.

PostNuke to GeekLog conversion

Posted on: 27/03/04 11:18pm
By: kermit

Hi,

the anonymous poster was me,
I must say thanks a lot for the help, and Geeklog rules, much faster than postnuke.

there's the script (I have modified it to correct some obvious bug to me) but it still not working.

 

/**
* Convert Nuke-type database to GeekLog
* quick hack
*/

require_once '/usr/share/pear/PEAR.php'; // why am i doing this?!

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'test';
$gl_dbname = 'sitting-ducks'; // new GL
$nuke_dbname = 'OLD'; // old Nuke

$gl_usertable = 'gl_users';
$gl_topictable = 'gl_topics';
$gl_storytable = 'gl_stories';
$gl_commenttable = 'gl_comments';

$nuke_usertable = 'nuke_users'; // change this for maxt_man db
$nuke_topictable = 'nuke_topics';
$nuke_storytable = 'nuke_stories';
$nuke_commenttable = 'nuke_comments';


$dbh = connect_db($dbhost, $dbuser, $dbpass);;
if ( PEAR::isError($dbh) ) {
trigger_error($dbh->getMessage(), E_USER_ERROR);
} else {
print "DB connection [ OK ]n";
}

//* ****************************************************** //

// *** CONVERT USERS
// get existing GL user names
mysql_select_db($gl_dbname, $dbh);
$sql = "select uid, username from $gl_usertable";
$res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
$gl_users = array();
while ( $row = mysql_fetch_assoc($res) ) {
$gl_users[$row["username"]] = $row["uid"];
}
mysql_free_result($res);
print_r($gl_users);

print "[ OK ]n";

// now get nuke users
mysql_select_db($nuke_dbname, $dbh);
$sql = "select * from $nuke_usertable";
$res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
$nuke_users = array();
while ( $row = mysql_fetch_assoc($res) ) {
$nuke_users[] = $row;
}
mysql_free_result($res);
//print_r($nuke_users);

$common_pass = md5("password");
//print "pass = $common_passn";
$regdate = date("Y-m-d H:i:s"); // don't preserve regdate

$uids = array();
mysql_select_db($gl_dbname, $dbh); // back to GL database
foreach ( $nuke_users as $key => $hash ) {
if ( in_array($hash["uname"], array_keys($gl_users)) ) {
// printf("[%-15s] EXISTSn", $hash['uname']);
// update nuke_uid
$sql = "update $gl_usertable set nuke_uid = {$hash['uid']} where uid = {$gl_users[$hash['uname']]}";
} else {
//printf("[%-15s] EXIST NOTn", $hash['uname']);
// insert user
$sql = "insert into $gl_usertable (nuke_uid, username, fullname, passwd, email, regdate ) values ";
$sql .= sprintf("(%d, '%s', '%s', '%s', '%s', '%s')",
$hash['uid'], $hash['uname'], $hash['name'], $common_pass, $hash['email'], $regdate);
}
$uids[] = $gl_users[$hash["uname"]];
//printf("uid [%d]n", $gl_users[$hash["uname"]]);
// print "$sqln";
//( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING);
}

// now cascade to all user* tables
// usercomment
// userindex
// userinfo
// userprefs

mysql_select_db($gl_dbname, $dbh); //make sure you're back to GL database
foreach ( $uids as $id ) {
$sqls = array();
$sqls[] = "replace into usercomment (uid) values ($id)";
$sqls[] = "replace into userindex (uid) values ($id)";
$sqls[] = "replace into userinfo (uid) values ($id)";
$sqls[] = "replace into userprefs (uid) values ($id)";
foreach ($sqls as $statement) {
//( mysql_query($statement, $dbh) ) or trigger_error("query failed: [$statement]", E_USER_WARNING);
}
}


// *** CONVERT TOPICS
// get existing GL topic ids ( in GL they are varchars )
mysql_select_db($gl_dbname, $dbh);
$sql = "select tid from $gl_topictable";
$res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
$gl_topics = array();
while ( $row = mysql_fetch_assoc($res) ) {
$gl_topics[] = $row["tid"];
}
mysql_free_result($res);
//print "GL existing topics:n";
//foreach ( $gl_topics as $key => $topic ) {
// printf("t%2d %sn", ($key + 1), $topic);
//}

// now get nuke topics
mysql_select_db($nuke_dbname, $dbh);
$sql = "select * from $nuke_topictable";
$res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
$nuke_topics = array();
while ( $row = mysql_fetch_assoc($res) ) {
$nuke_topics[] = $row;
}
mysql_free_result($res);
print "nNUKE topics:n";
foreach ( $nuke_topics as $key => $hash ) {
printf("t%2d %sn", ++$key, strtolower($hash["topicname"]) );
}

// make comparison case-insensitive
my_array_map("strtolower_wrapper", $gl_topics);
print "nGL existing topics:n";
foreach ( $gl_topics as $key => $topic ) {
printf("t%2d %sn", ($key + 1), $topic);
}
// back to GL database
mysql_select_db($gl_dbname, $dbh);
$imagepath = '/images/topics/';
$i = 0;
foreach ( $nuke_topics as $key => $hash ) {
if ( ! $hash["topicname"] ) continue;
$topicname = space_to_underscore(strtolower($hash["topicname"]));
if ( in_array($topicname, $gl_topics) ) {
printf("%2d [%-20s] EXISTSn", ++$i, $topicname);
// update nuke_uid
$sql = "update $gl_topictable set nuke_tid = {$hash['topicid']} where LOWER(tid) = '$topicname'";
} else {
printf("%2d [%-20s] EXIST NOTn", ++$i, $topicname);
// insert user
$sql = "insert into $gl_topictable (tid, nuke_tid, topic, imageurl) values ";
$sql .= sprintf("('%s', %d, '%s', '%s')",
$topicname, $hash['topicid'], $hash['topictext'],
($hash['topicimage']) ? $imagepath . $hash['topicimage'] : '' );

}
//print "$sqln";
//( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING);
}


// CONVERT STORIES
$aid_to_username = array(
'god' => 'admin',
'iano' => 'iano',
'simon' => 'slord'
);
// now get nuke stories
mysql_select_db($nuke_dbname, $dbh);
$sql = "select * from $nuke_storytable";
$res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
$nuke_stories = array();
while ( $row = mysql_fetch_assoc($res) ) {
$nuke_stories[] = $row;
}
mysql_free_result($res);
//print "nNUKE stories:n";
//foreach ( $nuke_stories as $key => $hash ) {
// printf("%3d %3d %-10s %-80sn", ++$key, $hash['sid'], $hash["aid"], $hash['title'] );
//}
// back to GL database
mysql_select_db($gl_dbname, $dbh);
// get GL users
$sql = "select username, uid from $gl_usertable";
$res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
$gl_users = array();
while ( $row = mysql_fetch_assoc($res) ) {
$gl_users[$row['username']] = $row['uid'];
}
//print "nGL users:n";
//foreach ( $gl_users as $uname => $uid ) {
// printf("%-10s %3dn", $uname, $uid );
//}
foreach ( $nuke_stories as $key => $hash ) {
// sleep(1) to make sure that a unique $gl_sid is generated
// quick hack ( not good if there are many records to convert )
sleep(1);
$gl_sid = COM_makesid();
printf("sid => %-20s ", $gl_sid);
$gl_uid = aid_to_gl_uid($hash['aid'], $aid_to_username, $gl_users);
printf("uid => %3d ", $gl_uid);
//$gl_tid = get_gl_tid($hash['topic'], $dbh);
//printf("tid => %-20sn", $gl_tid);

$sql = "insert into $gl_storytable (sid, nuke_sid, uid, tid, date, title, introtext, bodytext) values ";
$sql .= sprintf("('%s', %d, %d, '%s', '%s', '%s', '%s', '%s')",
$gl_sid,
$hash['sid'],
$gl_uid,
$gl_tid,
$hash['time'],
addslashes($hash['title']),
addslashes($hash['hometext']),
addslashes($hash['bodytext'])
);

//print "$sqln";
//( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING);
}


// CONVERT COMMENTS
// now get nuke comments
mysql_select_db($nuke_dbname, $dbh);
$sql = "select * from $nuke_commenttable";
$res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
$nuke_comments = array();
while ( $row = mysql_fetch_assoc($res) ) {
$nuke_comments[] = $row;
}
mysql_free_result($res);
//print_r($nuke_comments);
print("total comments: " . count($nuke_comments) . "n");

// back to GL database
$comment_count = array();
mysql_select_db($gl_dbname, $dbh);
foreach ( $nuke_comments as $key => $hash ) {
$gl_sid = get_gl_sid($hash['sid']);
if ( ! $gl_sid ) continue;
$gl_uid = get_gl_uid($hash['name']);

//printf("sid => %-20s ", $gl_sid);
//printf("uid => %3d n", $gl_uid);

$comment_count[$gl_sid]++;

$sql = "insert into $gl_commenttable (nuke_cid, sid, date, title, comment, score, reason, uid) values ";
$sql .= sprintf("(%d, '%s', '%s', '%s', '%s', %d, %d, %d)",
$hash['tid'],
$gl_sid,
$hash['date'],
addslashes($hash['subject']),
addslashes($hash['comment']),
$hash['score'],
$hash['reason'],
$gl_uid
);

//print "$sqln";
//( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING);
}
// update stories.comments field in GL database
print_r($comment_count);
foreach ( $comment_count as $sid => $count ) {
$sql = "update $gl_storytable set comments = $count where sid = '$sid'";
//print $sql . "n";
//( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING);
}

print "oops, done Surprised!)n";

// **************************************** */

///////////////////////////////////////////////////////////////////////////

function get_gl_uid ($username)
{
global $dbh, $gl_dbname, $gl_usertable;
mysql_select_db($gl_dbname, $dbh);
$sql = "select uid from $gl_usertable where LOWER(username) = '"
. strtolower($username) . "'";
$res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
$rv = @mysql_result($res, 0, 0);
$rv = trim($rv);

return (($rv) ? $rv : 1 ); // default 1 => Anonymous
}

function get_gl_sid ($nuke_sid)
{
global $dbh, $gl_dbname, $gl_storytable;
mysql_select_db($gl_dbname, $dbh);
$sql = "select sid from $gl_storytable where nuke_sid = '$nuke_sid'";
$res = mysql_query($sql, $dbh) or die("query failed [$sql]n");

return ( @mysql_result($res, 0, 0) );
}

function get_gl_tid ($nuke_tid, $dbh)
{
global $gl_dbname, $gl_topictable;
$sql = "select tid from $gl_topictable where nuke_tid = '$nuke_tid'";

mysql_select_db($gl_dbname, $dbh);
$res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
$gl_tid = @mysql_result($res, 0,0);

return ($gl_tid) ? $gl_tid : 'General';
}

function aid_to_gl_uid ($aid, $aid_to_username, $gl_users)
{
$rv = 1; // default for maxtinternal.stories.uid
$username = $aid_to_username[strtolower($aid)];
printf("username => %-10s ", $username);
foreach ( $gl_users as $uname => $uid ) {
if ( strtolower($username) == strtolower($uname) ) {
$rv = $uid;
break;
}
}

return $rv;
}

function space_to_underscore ($str)
{
$rv = NULL;
for ( $i = 0; $i 
$char = $str[$i];
if (ord($char) == 32) { $char = '_'; } // space
$rv .= $char;
}
return $rv;
}

function my_array_map ($func, &$ary)
{
settype($ary, "array");
for ($i = 0; $i 
$ary[$i] = $func($ary[$i]);
}
}

function strtolower_wrapper ($str)
{
return strtolower($str);
}

function connect_db ($dbhost, $dbuser, $dbpass)
{
$dbh = mysql_pconnect($dbhost, $dbuser, $dbpass);
if ( !is_resource($dbh) ) {
return new PEAR_Error('DB connection failed');
}

return $dbh;
}

function COM_makesid ()
{
$sid = date("YmdHis");
srand((double)microtime()*1000000);
$sid .= rand(0,999);

return $sid;
}

?>




I would be really really HAPPY if someone could take a pick at it, I am not php guru, but i understand a little bit of it (just a little bit)

I need help........

my msn messenger address : lucas_sxj@hotmail.com
for anyone who would like to get in touch with me and help me. thanks in advance, i appreciate your time and effort.

PostNuke to GeekLog conversion

Posted on: 27/03/04 11:37pm
By: kermit

If you need to do some try on the DB:

that's the new geeklog one


that's the old nuke one


thanks
Stephane

PostNuke to GeekLog conversion

Posted on: 27/03/04 11:38pm
By: Blaine

I suggest using the CODE BB tag so that the forum does not try to interpret any HTML or special characters.

I don't have NUKE installed and can't run the code but I've taken a crack at the section you were talking about and re-wrote the code to prepare the SQL statement.

I'm not sure why the original had a print "$sqln"; when the variable is $sql - probally just some copy/paste. I also noticed the mysql_query had ( ) around the call - not sure why - maybe it was used in a return in another location.

Try this:
foreach ( $nuke_stories as $key => $hash ) {
  // sleep(1) to make sure that a unique $gl_sid is generated
  // quick hack ( not good if there are many records to convert )
  sleep(1);
  $gl_sid = COM_makesid();
  printf("sid => %-20s ", $gl_sid);
  $gl_uid = aid_to_gl_uid($hash['aid'], $aid_to_username, $gl_users);
  printf("uid => %3d ", $gl_uid);
  //$gl_tid = get_gl_tid($hash['topic'], $dbh);
  //printf("tid => %-20sn", $gl_tid);

  $hash['title'] = addslashes($hash['title']);
  $hash['hometext'] = addslashes($hash['hometext']);
  $hash['bodytext'] = addslashes($hash['bodytext']);
  $sql = "INSERT INTO $gl_storytable (sid, nuke_sid, uid, tid, date, title, introtext, bodytext) 
        values ('$gl_sid', '{$hash['sid']}','$gl_uid', '$gl_tid', '{$hash['time']}', '{$hash['title']}', '{$hash['hometext']}', '{$hash['bodytext']}')";

  print "$sql";
  mysql_query($sql, $dbh)  or trigger_error("query failed: [$sql]", E_USER_WARNING);
}



PostNuke to GeekLog conversion

Posted on: 28/03/04 12:10am
By: kermit

I have different error now :


NUKE stories:
sid => 20040328060842303 username => admin uid => 2 INSERT INTO gl_stories (sid, nuke_sid, uid, tid, date, title, introtext, bodytext)
values ('20040328060842303', '22','2', '', '2003-05-01 21:20:15', 'I am back', 'Hi all,

I am back on track for my site.

My new server is online,
and i am running some anti cheats tools.

soon, you will get some details', '')

Warning: query failed: [INSERT INTO gl_stories (sid, nuke_sid, uid, tid, date, title, introtext, bodytext)
values ('20040328060842303', '22','2', '', '2003-05-01 21:20:15', 'I am back', 'Hi all,

I am back on track for my site.

My new server is online,
and i am running some anti cheats tools.

soon, you will get some details', '')] in /tmp/nuke2geek.php on line 89

total comments: 0
Array
(
)
oops, done : o )



PostNuke to GeekLog conversion

Posted on: 28/03/04 12:18am
By: Blaine

I suggest you now try that SQL stmt using phpMyAdmin to assist you troublehooting why its generating a SQL error. You are not seeing the actual SQL error - just that there is one.

PostNuke to GeekLog conversion

Posted on: 28/03/04 12:22am
By: kermit

thanks for this.
i am not too familiar with phpmyadmin (only to create and add and also drop db)
I have sent you a private message

thanks a lot
stephane

PostNuke to GeekLog conversion

Posted on: 28/03/04 12:25am
By: kermit

[QUOTE BY= Blaine] I suggest you now try that SQL stmt using phpMyAdmin to assist you troublehooting why its generating a SQL error. You are not seeing the actual SQL error - just that there is one.[/QUOTE]

can you explain me exactly how do that ?

try that SQL stmt using phpMyAdmin


thanks

PostNuke to GeekLog conversion

Posted on: 28/03/04 12:28am
By: Blaine

Do you have phpMyAdmin installed?

If not -- it's highly recommended that you install this tool if you are doing anything with mysql.

PostNuke to GeekLog conversion

Posted on: 28/03/04 12:30am
By: kermit

Yes I do have phpMyAdmin installed.
but never used it to do such thing.

I only use it to create or drop database.
I am only a user of php/mysql, not a develloper


thanks
Stephane

PostNuke to GeekLog conversion

Posted on: 28/03/04 12:40am
By: Blaine

Ok - well it's quite powerfull. You should start by trying to execute a few simple SQL statments - like a SELECT. Browse one of the tables - and you will see the SQL statement.


I'm suggesting you would enter the SQL statement that your trying to execute in code.

INSERT INTO gl_stories (sid, nuke_sid, uid, tid, date, title, introtext, bodytext)
values ('20040328060842303', '22','2', '', '2003-05-01 21:20:15', 'I am back', 'Hi all, I am back on track for my site.
My new server is online, and i am running some anti cheats tools. soon, you will get some details', '')



If you are not familar with SQL and PHP then developing or debugging a Database migration script and converting a Nuke site to Geeklog is quite a significant undertaking.

Does your gl_stories table have a field called nuke_sid ?
Geeklog by default would not.

PostNuke to GeekLog conversion

Posted on: 28/03/04 12:42am
By: kermit

you are right about nuke_sid:

I run the command into the Query Window and i am getting this:


MySQL said:
#1054 - Unknown column 'nuke_sid' in 'field list'


dude, you are getting me into this stuff, i want to learn it.

PostNuke to GeekLog conversion

Posted on: 28/03/04 12:44am
By: Blaine

Thats why my last note above was:

[QUOTE BY= Blaine] Does your gl_stories table have a field called nuke_sid ?
Geeklog by default would not.[/QUOTE]

PostNuke to GeekLog conversion

Posted on: 28/03/04 12:46am
By: kermit

great, i just fixed something, i have to carry on, i will post my result shortly

PostNuke to GeekLog conversion

Posted on: 28/03/04 01:05am
By: kermit

Blaine,

I don't know how to thank you, the script is now working.
I have learned something today, I have modified the script to import only the stories at the present moment.

and IT WORKS.
So I shall carry on and get the all script working.
Now that I understand it, I will try to get the script done to import the all postnuke.

thanks a lot again
keep upi the good work dude.

Regards
stephane

PostNuke to GeekLog conversion

Posted on: 16/05/04 06:46pm
By: Anonymous

Kermit,

How far have you gotten on this? I have a huge postnuke site that I would like to at least move the Users (and the phpbb forums) to the geeklog site.

Thanks,

Mark

PostNuke to GeekLog conversion

Posted on: 27/07/04 03:18am
By: Anonymous

Hi, I am running into the same problem that Stephane said that she was having at the beggining of the topic forum. I was wondering if anyone came with a solution to his problem. I have an old site in postnuke that I want to convert to geeklog.

This is the problem that Im having:

uid [0]
insert into gl_users (nuke_uid, username, fullname, passwd, email, regdate ) values (0, '', '', '5f4dcc3b5aa765d61d8327deb882cf99', '', '2004-07-27 02:40:07')

Warning: query failed: [insert into gl_users (nuke_uid, username, fullname, passwd, email, regdate ) values (0, '', '', '5f4dcc3b5aa765d61d8327deb882cf99', '', '2004-07-27 02:40:07')] in /var/www/html/sites/geeklog/public_html/postnuke-gl.php on line 82
[ ] EXIST NOT


Any help on this situation will be greatly apreciated.

#!/usr/bin/php -q
 <?php
 
 /**
 * Convert Nuke-type database to GeekLog
 * quick hack
 */
 
 require_once '/var/www/html/sites/geeklog/system/pear/PEAR.php'; // why am i doing this?!
 
 $dbhost = 'localhost';
 $dbuser = 'tester';
 $dbpass = 'test123';
 $gl_dbname = 'cadena'; // new GL
 $nuke_dbname = 'ccnet'; // old Nuke
 
 $gl_usertable = 'gl_users';
 $gl_topictable = 'gl_topics';
 $gl_storytable = 'gl_stories';
 $gl_commenttable = 'gl_comments';
 
 $nuke_usertable = 'nuke_users'; // change this for maxt_man db
 $nuke_topictable = 'nuke_topics'; 
 $nuke_storytable = 'nuke_stories';
 $nuke_commenttable = 'nuke_comments';
 
 
 $dbh = connect_db($dbhost, $dbuser, $dbpass);;
 if ( PEAR::isError($dbh) ) {
 trigger_error($dbh->getMessage(), E_USER_ERROR); 
 } else {
 print "DB connection [ OK ]n";
 } 
 
 
 // CONVERT USERS 
 // get existing GL user names
 mysql_select_db($gl_dbname, $dbh);
 $sql = "select uid, username from $gl_usertable";
 $res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
 $gl_users = array();
 while ( $row = mysql_fetch_assoc($res) ) {
 $gl_users[$row["username"]] = $row["uid"];
 }
 mysql_free_result($res);
 print_r($gl_users);
 
 // now get nuke users
 mysql_select_db($nuke_dbname, $dbh);
 $sql = "select * from $nuke_usertable";
 $res = mysql_query($sql, $dbh) or die("query failed [$sql]n"); 
 $nuke_users = array();
 while ( $row = mysql_fetch_assoc($res) ) {
 $nuke_users[] = $row;
 }
 mysql_free_result($res);
 print_r($nuke_users);
 
 $common_pass = md5("password");
 print "pass = $common_passn"; 
 $regdate = date("Y-m-d H:i:s"); // don't preserve regdate
 
 $uids = array();
 mysql_select_db($gl_dbname, $dbh); // back to GL database
 foreach ( $nuke_users as $key => $hash ) {
 if ( in_array($hash["uname"], array_keys($gl_users)) ) {
 printf("[%-15s] EXISTSn", $hash['uname']);
 // update nuke_uid
 $sql = "update $gl_usertable set nuke_uid = {$hash['uid']} where uid = {$gl_users[$hash['uname']]}"; 
 } else {
 printf("[%-15s] EXIST NOTn", $hash['uname']);
 // insert user
 $sql = "insert into $gl_usertable (nuke_uid, username, fullname, passwd, email, regdate ) values ";
 $sql .= sprintf("(%d, '%s', '%s', '%s', '%s', '%s')",
 $hash['uid'], $hash['uname'], $hash['name'], $common_pass, $hash['email'], $regdate);
 
 
 }
 $uids[] = $gl_users[$hash["uname"]];
 printf("uid [%d]n", $gl_users[$hash["uname"]]); 
 print "$sqln"; 
 ( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING); 
 }
 
 // now cascade to all user* tables
 // usercomment
 // userindex
 // userinfo
 // userprefs
 
 mysql_select_db($gl_dbname, $dbh); //make sure you're back to GL database
 foreach ( $uids as $id ) {
 $sqls = array(); 
 $sqls[] = "replace into usercomment (uid) values ($id)";
 $sqls[] = "replace into userindex (uid) values ($id)";
 $sqls[] = "replace into userinfo (uid) values ($id)";
 $sqls[] = "replace into userprefs (uid) values ($id)"; 
 foreach ($sqls as $statement) {
 ( mysql_query($statement, $dbh) ) or trigger_error("query failed: [$statement]", E_USER_WARNING); 
 }
 }
 
 
 // *** CONVERT TOPICS
 // get existing GL topic ids ( in GL they are varchars )
 mysql_select_db($gl_dbname, $dbh);
 $sql = "select tid from $gl_topictable";
 $res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
 $gl_topics = array();
 while ( $row = mysql_fetch_assoc($res) ) {
 $gl_topics[] = $row["tid"];
 }
 mysql_free_result($res);
 print "GL existing topics:n";
 foreach ( $gl_topics as $key => $topic ) {
  printf("t%2d %sn", ($key + 1), $topic);
 }
 
 // now get nuke topics
 mysql_select_db($nuke_dbname, $dbh);
 $sql = "select * from $nuke_topictable";
 $res = mysql_query($sql, $dbh) or die("query failed [$sql]n"); 
 $nuke_topics = array();
 while ( $row = mysql_fetch_assoc($res) ) {
 $nuke_topics[] = $row;
 }
 mysql_free_result($res);
 print "nNUKE topics:n";
 foreach ( $nuke_topics as $key => $hash ) {
 printf("t%2d %sn", ++$key, strtolower($hash["topicname"]) );
 }
 
 // make comparison case-insensitive
 my_array_map("strtolower_wrapper", $gl_topics);
 print "nGL existing topics:n";
 foreach ( $gl_topics as $key => $topic ) {
 printf("t%2d %sn", ($key + 1), $topic);
 }
 // back to GL database
 mysql_select_db($gl_dbname, $dbh); 
 $imagepath = '/images/topics/';
 $i = 0;
 foreach ( $nuke_topics as $key => $hash ) {
 if ( ! $hash["topicname"] ) continue;
 $topicname = space_to_underscore(strtolower($hash["topicname"]));
 if ( in_array($topicname, $gl_topics) ) {
 printf("%2d [%-20s] EXISTSn", ++$i, $topicname);
 // update nuke_uid
 $sql = "update $gl_topictable set nuke_tid = {$hash['topicid']} where LOWER(tid) = '$topicname'"; 
 } else {
 printf("%2d [%-20s] EXIST NOTn", ++$i, $topicname);
 // insert user
 $sql = "insert into $gl_topictable (tid, nuke_tid, topic, imageurl) values ";
 $sql .= sprintf("('%s', %d, '%s', '%s')",
 $topicname, $hash['topicid'], $hash['topictext'],
 ($hash['topicimage']) ? $imagepath . $hash['topicimage'] : '' );
 
 }
 print "$sqln"; 
 ( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING); 
 }
 
 
 // CONVERT STORIES
 $aid_to_username = array(
 'god' => 'admin',
 'iano' => 'iano',
 'simon' => 'slord'
 );
 // now get nuke stories
 mysql_select_db($nuke_dbname, $dbh);
 $sql = "select * from $nuke_storytable";
 $res = mysql_query($sql, $dbh) or die("query failed [$sql]n"); 
 $nuke_stories = array();
 while ( $row = mysql_fetch_assoc($res) ) {
 $nuke_stories[] = $row;
 }
 mysql_free_result($res);
 print "nNUKE stories:n";
 foreach ( $nuke_stories as $key => $hash ) {
  printf("%3d %3d %-10s %-80sn", ++$key, $hash['sid'], $hash["aid"], $hash['title'] );
 }
 // back to GL database
 mysql_select_db($gl_dbname, $dbh); 
 // get GL users
 $sql = "select username, uid from $gl_usertable";
 $res = mysql_query($sql, $dbh) or die("query failed [$sql]n"); 
 $gl_users = array();
 while ( $row = mysql_fetch_assoc($res) ) {
 $gl_users[$row['username']] = $row['uid'];
 }
 print "nGL users:n";
 foreach ( $gl_users as $uname => $uid ) {
  printf("%-10s %3dn", $uname, $uid );
 }
 foreach ( $nuke_stories as $key => $hash ) {
 // sleep(1) to make sure that a unique $gl_sid is generated
 // quick hack ( not good if there are many records to convert )
 sleep(1); 
 $gl_sid = COM_makesid();
 printf("sid => %-20s ", $gl_sid); 
 $gl_uid = aid_to_gl_uid($hash['aid'], $aid_to_username, $gl_users);
 printf("uid => %3d ", $gl_uid);
 $gl_tid = get_gl_tid($hash['topic'], $dbh);
 printf("tid => %-20sn", $gl_tid);
 
 $sql = "insert into $gl_storytable (sid, nuke_sid, uid, tid, date, title, introtext, bodytext) values ";
 $sql .= sprintf("('%s', %d, %d, '%s', '%s', '%s', '%s', '%s')",
 $gl_sid,
 $hash['sid'],
 $gl_uid,
 $gl_tid,
 $hash['time'],
 addslashes($hash['title']),
 addslashes($hash['hometext']),
 addslashes($hash['bodytext'])
 );
 
 print "$sqln"; 
 ( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING); 
 }
 
 
 // CONVERT COMMENTS 
 // now get nuke comments
 mysql_select_db($nuke_dbname, $dbh);
 $sql = "select * from $nuke_commenttable";
 $res = mysql_query($sql, $dbh) or die("query failed [$sql]n"); 
 $nuke_comments = array();
 while ( $row = mysql_fetch_assoc($res) ) {
 $nuke_comments[] = $row;
 }
 mysql_free_result($res);
 print_r($nuke_comments);
 print("total comments: " . count($nuke_comments) . "n");
 
 // back to GL database
 $comment_count = array();
 mysql_select_db($gl_dbname, $dbh); 
 foreach ( $nuke_comments as $key => $hash ) {
 $gl_sid = get_gl_sid($hash['sid']);
 if ( ! $gl_sid ) continue;
 $gl_uid = get_gl_uid($hash['name']);
 
 printf("sid => %-20s ", $gl_sid); 
 printf("uid => %3d n", $gl_uid);
 
 $comment_count[$gl_sid]++;
 
 $sql = "insert into $gl_commenttable (nuke_cid, sid, date, title, comment, score, reason, uid) values ";
 $sql .= sprintf("(%d, '%s', '%s', '%s', '%s', %d, %d, %d)",
 $hash['tid'],
 $gl_sid,
 $hash['date'],
 addslashes($hash['subject']),
 addslashes($hash['comment']),
 $hash['score'],
 $hash['reason'],
 $gl_uid
 );
 
 print "$sqln"; 
 ( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING); 
 }
 // update stories.comments field in GL database
 print_r($comment_count);
 foreach ( $comment_count as $sid => $count ) {
 $sql = "update $gl_storytable set comments = $count where sid = '$sid'";
 print $sql . "n";
 ( mysql_query($sql, $dbh) ) or trigger_error("query failed: [$sql]", E_USER_WARNING); 
 }
 
 print "oops, done Surprised!)n";
 
 // **************************************** */
 
 
 function get_gl_uid ($username) 
 {
 global $dbh, $gl_dbname, $gl_usertable;
 mysql_select_db($gl_dbname, $dbh); 
 $sql = "select uid from $gl_usertable where LOWER(username) = '"
 . strtolower($username) . "'";
 $res = mysql_query($sql, $dbh) or die("query failed [$sql]n");
 $rv = @mysql_result($res, 0, 0);
 $rv = trim($rv);
 
 return (($rv) ? $rv : 1 ); // default 1 => Anonymous
 }
 
 function get_gl_sid ($nuke_sid)
 {
 global $dbh, $gl_dbname, $gl_storytable;
 mysql_select_db($gl_dbname, $dbh); 
 $sql = "select sid from $gl_storytable where nuke_sid = '$nuke_sid'";
 $res = mysql_query($sql, $dbh) or die("query failed [$sql]n"); 
 
 return ( @mysql_result($res, 0, 0) );
 }
 
 function get_gl_tid ($nuke_tid, $dbh)
 {
 global $gl_dbname, $gl_topictable;
 $sql = "select tid from $gl_topictable where nuke_tid = '$nuke_tid'";
 
 mysql_select_db($gl_dbname, $dbh); 
 $res = mysql_query($sql, $dbh) or die("query failed [$sql]n"); 
 $gl_tid = @mysql_result($res, 0,0); 
 
 return ($gl_tid) ? $gl_tid : 'General';
 }
 
 function aid_to_gl_uid ($aid, $aid_to_username, $gl_users)
 {
 $rv = 1; // default for maxtinternal.stories.uid
 $username = $aid_to_username[strtolower($aid)];
 printf("username => %-10s ", $username);
 foreach ( $gl_users as $uname => $uid ) {
 if ( strtolower($username) == strtolower($uname) ) {
 $rv = $uid;
 break;
 }
 }
 
 return $rv;
 }
 
 function space_to_underscore ($str)
 {
 $rv = NULL;
 for ( $i = 0; $i < strlen($str); $i++ ) {
 $char = $str[$i];
 if (ord($char) == 32) { $char = '_'; } // space 
 $rv .= $char;
 }
 return $rv;
 }
 
 function my_array_map ($func, &$ary)
 {
 settype($ary, "array");
 for ($i = 0; $i < count($ary); $i++) {
 $ary[$i] = $func($ary[$i]); 
 } 
 }
 
 function strtolower_wrapper ($str)
 {
 return strtolower($str); 
 }
 
 function connect_db ($dbhost, $dbuser, $dbpass) 
 {
 $dbh = mysql_pconnect($dbhost, $dbuser, $dbpass);
 if ( !is_resource($dbh) ) {
 return new PEAR_Error('DB connection failed');
 }
 
 return $dbh; 
 }
 
 function COM_makesid () 
 {
 $sid = date("YmdHis");
 srand((double)microtime()*1000000);
 $sid .= rand(0,999);
 
 return $sid;
 }
 
 ?>


PostNuke to GeekLog conversion

Posted on: 27/07/04 09:09am
By: Blaine

Why are those Nuke values 0 or null ?
nuke_uid is 0
username and fullname are ''

PostNuke to GeekLog conversion

Posted on: 27/07/04 11:58am
By: Anonymous

No sure why but in the nuke_user table there is not pn_uid with the value 0 or NULL

PostNuke to GeekLog conversion

Posted on: 27/07/04 12:30pm
By: Anonymous

Here are the 36 field names from a nuke_users table in a postnuke DB. Im not sure if the fact that they have the prefix pn is the problem. Im not even sure now if the script that I got is for postnuke or for phpnuke. Anyway Im still trying to move from postnuke to geeklog but have not been able to do it yet.
pn_uid
pn_name
pn_uname
pn_email
pn_femail
pn_url
pn_user_avatar
pn_user_regdate
pn_user_icq
pn_user_occ
pn_user_from
pn_user_intrest
pn_user_sig
pn_user_viewemail
pn_user_theme
pn_user_aim
pn_user_yim
pn_user_msnm
pn_pass
pn_storynum
pn_umode
pn_uorder
pn_thold
pn_noscore
pn_bio
pn_ublockon
pn_ublock
pn_theme
pn_commentmax
pn_counter
pn_timezone_offset
user_group_cp
user_group_list_cp
user_active_cp
user_lastvisit_cp
user_regdate_cp

PostNuke to GeekLog conversion

Posted on: 20/11/04 12:21pm
By: bigdaddy

Well this thread just died. Has anyone gotten an successful conversation from php-nuke to GL ? If so, do you have a script that working?

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=23799