Hi,

(im brazilian, sorry for any grammar mistake)

Im migrating my site from xoops to drupal, and today ive created a script to migrate the users. This script is at the end of this post. But now id be really gratefull if someone here can help me... im migrating the forum posts (ipb forum, integrated into xoops with koudanshi's plugin) and id love to know how to *programatically* define new terms under the forum vocabulary (the terms would be related to original foruns and forum containers) and use these newly created terms to insert the posts as nodes into drupal. What i need is to know how to create the terms and how to get the ids of these terms, with some sample code if possible... i was looking the taxonomy module but im in a rush and i dont know if i can afford to spend more time to dig the info i need.

Actually, i want to do things this way (programatically creating the terms) to be able to share the script with the community... but im afraid that the time pressure will force me to do this just by hardcoding the terms.

Well, i hope somebody can help me!

That said, here is the script to migrate users from xoops to drupal. you need to export the xoops users table and import it into the drupal database, or just configure the connection where needed to connect with the xoops database (theres only one query to that database anyway).

the script needs the profile module, and erases all fields from the profile_fields and profile_values tables, and all but the first user from drupal users table are overwritten - so please use this only in a fresh install with the needed modules, unless you know what youre doing.

//////////////////////////////////////////////////////////////////////
// xoops configuration
//////////////////////////////////////////////////////////////////////

// xoops table prefix
$xoops_prefix = "portal_";

//////////////////////////////////////////////////////////////////////
// end of xoops config
//////////////////////////////////////////////////////////////////////

include_once 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if (!ini_get('safe_mode')) set_time_limit(240);

// leave the drupal admin alone
db_query("DELETE FROM {users} where uid > 1");
// erase profile module data
db_query("DELETE FROM {profile_values}"); 
db_query("DELETE FROM {profile_fields}");

// insert profile module data
db_query("INSERT INTO {profile_fields} VALUES (1, 'Real name', 'profile_realname', 
        'Your real name.', 'Personal data', '', 'textfield', 0, 0, 1, 3, 0, '');");
db_query("INSERT INTO {profile_fields} VALUES (2, 'old UID', 'profile_olduid', 'Old UID', 
        'Personal data', '', 'textfield', 0, 0, 0, 1, 0, '');");
db_query("INSERT INTO {profile_fields} VALUES (3, 'ICQ', 'profile_icq', 'Your ICQ number.', 
        'Contact info', '', 'textfield', 0, 0, 1, 3, 0, '');");
db_query("INSERT INTO {profile_fields} VALUES (4, 'MSN', 'profile_msn', 'Your MSN email.', 
        'Contact info','', 'textfield', 0, 0, 1, 3, 0, '');");
db_query("INSERT INTO {profile_fields} VALUES (5, 'Yahoo! Messenger', 'profile_yahoo', 
        'Your Yahoo! Messenger user name.', 'Contact info', '', 'textfield', 0, 0, 1, 3, 0, '');");
db_query("INSERT INTO {profile_fields} VALUES (6, 'AIM', 'profile_aim', 'Your AIM user name.', 
        'Contact info', '', 'textfield', 0, 0, 1, 3, 0, '');");
db_query("INSERT INTO {profile_fields} VALUES (7, 'Bio', 'profile_bio', 'Biography.', 
        'Personal data', '', 'textarea', 0, 0, 1, 3, 0, '');");
db_query("INSERT INTO {profile_fields} VALUES (8, 'Interests', 'profile_intrest', 
        'Your interests.', 'Personal data', '', 'textarea', 0, 0, 1, 3, 0, '');");

// ipb allow some freak login names.... leave out accented chars, spaces, 
// special symbols and other hazard things
$nick_in  = array('/[ÂÀÁÄÃâãàáä]/', '/[ÊÈÉËêèéë]/', '/[ÎÍÌÏîíìï]/','/[ÔÕÒÓÖôõòóö]/', '/[ÛÙÚÜûúùü]/', 
    	'/Çç/',	'/ |[^a-z0-9]/');
$nick_out = array('a', 'e', 'i', 'o', 'u', 'c', '');

// get the xoops users
$result = db_query("SELECT uid, name, uname, email, user_regdate, pass, last_login,
	user_icq, user_aim, user_yim, user_msnm, bio, user_intrest, user_sig FROM ".$xoops_prefix."users;");
while($res = db_fetch_object($result)){
    $users[$user_count++] = array(
		"uid" => $res->uid,
    	"name" => preg_replace($nick_in, $nick_out, strtolower($res->uname)),
    	"mail" => $res->email,
    	"created" => $res->user_regdate,
    	"access" => $res->last_login,
    	"pass" => $res->pass,
    	"cname" => $res->name,
    	"icq" => $res->user_icq,
    	"aim" => $res->user_aim,
    	"yahoo" => $res->user_yim,
    	"msn" => $res->user_msnm,
    	"bio" => $res->bio,
    	"signature" => $res->user_sig,
    	"interesses" => $res->user_intrest);
}
echo "theres $user_count xoops users<br>";
echo "migrating users...<br>";

// insert all users
for ($j = 1; $j <= $user_count; $j++) {
	if (!db_query("INSERT INTO {users} (uid, name, mail, status, created, access, pass, signature) 
    	    	VALUES (%d, '%s', '%s', %d, %d, %d, %d, '%s')", 
		$j+1, $users[$j]["name"], $users[$j]["mail"], 1, $users[$j]["created"], $users[$j]["access"], 
    	    	$users[$j]["pass"], $users[$j]["signature"])) {
		echo "error inserting user ".($j+1)." - ". $users[$j]["name"]."<br>";
		$probuser++;
	}
	
	// store the old id (to allow easy migration from another xoops modules) and other fields
	// from xoops profiles 
	db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 1, $j+1, 
    	    	$users[$j]["cname"]);
	db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 2, $j+1, 
    	    	$users[$j]["uid"]);
	db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 3, $j+1, 
    	    	$users[$j]["icq"]);
	db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 4, $j+1, 
    	    	$users[$j]["msn"]);
	db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 5, $j+1, 
    	    	$users[$j]["yahoo"]);
	db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 6, $j+1, 
    	    	$users[$j]["aim"]);
	db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 7, $j+1, 
    	    	$users[$j]["bio"]);
	db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", 8, $j+1, 
    	    	$users[$j]["intrest"]);
}
echo ($user_count-$probuser)." users inserted at drupal tables<br>";
db_query("UPDATE {sequences} SET id = %d WHERE name = 'users_uid'", $i);
echo "sequence numbers updated</br>";

Comments

mauriciomedeiros’s picture

Ive managed to migrate the foruns, but with the relations xoops forum id -> taxonomy forum term hardcoded. But, hey, its working. Ill try to migrate some other modules too, and i want to know if theres a place more apropriated to put the scripts :-)

Mauricio

PS: if someone could help me with the taxonomy question, ill still be gratefull :-)

spankee’s picture

I altered it a bit and it is now almost working for me.
I had some trouble with the real names, but I changed "cname" to "Uname" and it worked.
Another problem is with the passwords not transferring. Some do not transfer and others transfer only the first few digits.

Now that most of the information has been transferred the passwords should not be too difficult to do manually.
Thanks!

int’s picture

[Script] Convert Xoops 2.2.X to Drupal 5.X
http://drupal.org/node/167541

Marco Sousa
https://www.gaap.dev