Log in

View Full Version : Need Advice on an Import Script


Michael Morris
01-27-2005, 05:55 AM
I am nearing the completion of a script to import a book reviews database into vbulletin, then manipluate those files with custom files.

Anyway, I need to write an import script that will be making many posts in rapid succession as it adds the rows from the old database to the new. However, I've found the script shuts down after 10-14 posts. Is this a security feature, or do I need to insert some kind of delay loop to protect mysql from flood? I've never done this sort of thing before, so help would be appreciated.

Marco van Herwaarden
01-27-2005, 12:07 PM
How are you making the new posts?

Manual SQL INSERT's?

Or are you using some vB functions?

miz
01-27-2005, 03:47 PM
here is some idea that poped up in my mind..

read the tables from old db and save them as .sql
(php will do that for 2mb per file)
now my idea is to read source of phpmyadmin
to see how its load .sql files
and to load it like phpmyadmin does
can be a good way...
its just an idea, and its might be a very bad idea but its also might work.

Michael Morris
01-27-2005, 03:49 PM
I'm letting vbulletin do as much work as possible. I copied the tables from the old database into vbulletin's database temporarily with this query, one at a time.

create table forums.tablecopyinvbulletin select * from olddatabase.tabletocopy

That was done using queries from the mysql prompt and went very smoothly. Using phpmyadmin I inspected the tables to insure their data matched.

Next I've created the permanent tables for the new structure that my new vbulletin integrated program will use. For instance, the first table is "publishers" The lion's share of information on publishers on their old table is the info field. And they have a name. So I've created a "publisher data thread" and, using the post branch of the newreply.php script as a template, I constructed a while loop to read off one row of the old publisher table at a time, put the title and info into the vbulletin database (specificially the publisher data thread) and then adding some information to the cutom tables using custom queries before starting the loop again.

Yes, vbulletin inbuilt functions are being used - specifically all those appearing in that particular program branch - build_new_post key among them.

Luckily I have a local copy of vbulletin set aside specifically for this project so I can truncuate the post, thread and postindex tables and start over as necessary.

here is some idea that poped up in my mind..

read the tables from old db and save them as .sql
(php will do that for 2mb per file)
now my idea is to read source of phpmyadmin
to see how its load .sql files
and to load it like phpmyadmin does
can be a good way...
its just an idea, and its might be a very bad idea but its also might work.

Thanks miz, but I'm already beyond that point using the query given above. What I need to do now is convert and merge the data from the old database into the vbulletin tables and my new custom tables.

miz
01-27-2005, 03:55 PM
so all you need is to match fileds

but you said

I've found the script shuts down after 10-14 posts. Is this a security feature, or do I need to insert some kind of delay loop to protect mysql from flood? I've never done this sort of thing before, so help would be appreciated.

does it not shoutdown with the query
create table forums.tablecopyinvbulletin select * from olddatabase.tabletocopy
??
or im confused..

Michael Morris
01-27-2005, 04:01 PM
It shuts down after I loop through build... wait. :) I think I got it.... buh bye

EDIT: Nope..

This is what I have so far...

<html><body>
<?php
// Reviews db conversion.

$_GET['t'] = 1;
$_GET['f'] = 5;

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once('./includes/functions_newpost.php');
require_once('./includes/functions_editor.php');
require_once('./includes/functions_bigthree.php');

// Rebuild Publisher

$getpublishers = $DB_site->query("
SELECT * FROM d20_publishers");

while ($publisher = $DB_site->fetch_array($getpublishers))
{
$newpost['message'] = $publisher['Info'];
$newpost['title'] = $publisher['publisher'];
$newpost['poststarttime'] = $TIMENOW;
$newpost['posthash'] = $TIMENOW;
$newpost['contactemail'] = $publisher['email'];
$newpost['website'] = $publisher['WWW'];
$newpost['founded'] = $publisher['Founded'];
$newpost['oldid'] = $publisher['ID'];

build_new_post('reply', $foruminfo, $threadinfo, 1, $newpost, $errors);

if (sizeof($errors) > 0)
{
die('Post Error');
}

$DB_site->query("
INSERT INTO " . TABLE_PREFIX . "publisher(publisherid, contactemail, website, founded, oldid)
VALUES ($newpost[postid], '" . addslashes($newpost['contactemail']) . "',
'" . addslashes($newpost['website']) . "', '$newpost[founded]', $newpost[oldid])
");
echo 'Publisher #' . $publisher['id'] . ' added<br />';
}

echo 'Publishers Finished<br /><br /><br />';


?>
</body></html>

Ok, I gave up on calling build new post and ran a query directly against the post table to insert the post. I guess I figure out the problems that causes as I go along.

Marco van Herwaarden
01-27-2005, 08:27 PM
Yes i think you will have much less trouble if you insert direct into the thread/post table.

Michael Morris
01-27-2005, 08:51 PM
Yep - that's what I ended up doing. I'll just have to rebuild the postindex afterward - a macro that can take awhile to run on large boards like EN World though :(