Tefra |
03-16-2007 11:22 AM |
Custom Import Script Help
I am not sure if this is the right section to post this but anyway after all it's about importing things to vbulletin
I use a 3rd part software for my site as a portal and cms, not intergraded. I want now to move the news from my cms to vbulletin as topics. I wrote a small script to do this job as i couldn't find an easy way to use impex for this.
This is the table structure of the news
Code:
CREATE TABLE pages (
page_id int(11) unsigned NOT NULL auto_increment,
page_cat varchar(16) default NULL,
page_title varchar(255) default NULL,
page_text text,
page_ownerid int(11) NOT NULL default '0',
page_date int(11) NOT NULL default '0',
page_count mediumint(8) unsigned default '0',
PRIMARY KEY (page_id),
KEY page_cat (page_cat)
) TYPE=MyISAM;
ignore the page_cat, also ignore the page_ownerid as you will see below i assign some values manually.
Now here is the small script i wrote
PHP Code:
$sql = mysql_query("SELECT * FROM $db_pages WHERE page_cat IN ('gnews', 'games', 'drvnews', 'stnews', 'hrdwrnews', 'softnews')");
while ($row = mysql_fetch_array($sql))
{
mysql_query("INSERT INTO vb_post (threadid, parentid, username, userid, title, dateline, pagetext, allowsmilie, showsignature, ipaddress, iconid, visible, attach, infraction, reportthreadid) VALUES
(0, 0, 'Tefra', 1, '".mysql_real_escape_string($row['page_title'])."', '".$row['page_date']."', '".mysql_real_escape_string($row['page_text'])."', 1, 1, '', 0, 1, 0, 0, 0)");
$post_id = mysql_insert_id();
mysql_query("INSERT INTO vb_thread (title, firstpostid, lastpost, forumid, pollid, open, replycount, hiddencount, postusername, postuserid, lastposter, dateline, views, iconid, notes, visible, sticky, votenum, votetotal, attach, similar, deletedcount, lastpostid) VALUES
('".mysql_real_escape_string($row['page_title'])."', $post_id, '".$row['page_date']."', 32, 0, 1, 0, 0, 'Tefra', 1, 'Tefra', '".$row['page_date']."', '".$row['page_count']."', 0, '', 1, 0, 0, 0, 0, '', 0, $post_id)");
$thread_id = mysql_insert_id();
mysql_query("UPDATE vb_post SET threadid=$thread_id WHERE postid=$post_id");
echo "Imported news #".$row['page_id']."<br />";
}
As you can see i assign the topics manually in a new forum section i created manually. They are all topics with one post only.
Now the funny is that after running the necessary maintenance procedures everything looks like it's working great on my localhost.
But my knowledge on vbulletin API isn't great so i would like someone more experienced to tell me if i miss anything, or if there is a better way for this?
|