Drupal is up and running, but how do I import my phpBB database, especially all the users with their passwords. Also, can I import Blogger data too?

Thanks a million!

Comments

axel’s picture

User Feodor from drupal.ru create script for converting phpBB 2.0.10 database to Drupal 4.4. You may look this at http://drupal.ru/node/340
Texts in Russian, but you may see attached file with script below topic - direct link though http://drupal.ru/files/phpbb2drupal_final.sql.gz
You will need replace table prefixes appropriate with your database.
I not tested this script and me not author of this - don't ask me how this work or don't work, but I hope it will useful.

--
Axel,
Russian Drupal Community

iraszl’s picture

thanks a lot. sounds exciting.
Russian is no problem, я говорю по руски. :)

how about blogger? anybody knows a way to import blogger.com data?

Uwe Hermann’s picture

Is this script available from CVS? If no, can you please check it in so that others may find it easier?

TIA, Uwe.
--
My Drupal site: http://www.crazy-hacks.org
Soon to be drupalized: http://www.unmaintained-free-software.org

axel’s picture

Script need some cleanup, I think. Else many unnecessary questions from users will appear.

--
Axel,
Russian Drupal Community

bgolat’s picture

will this work for phpbb 2.0.4 -> drupal 4.5.1?

thanks

yossarian’s picture

you have to mess with the .ru script. I'm doing a phpbb -> drupal conversion tomorrow and will post the complete script I use with instructions.

bgolat’s picture

cool let me know how it goes, its something i want to do soon! thanks

iraszl’s picture

Don't forget to share your experience! I'm so watching this topic, I really want to move my phpbb to Drupal.
---
http://creativebits.org

yossarian’s picture

yeah, I've already converted three sites with phpbb14 and one with phpBB 2.04 postnuke version. Works fine, for the most part. But you have to manually edit you sequnces tables and the import script to reflect your sequences if you are importing into an already existing drupal site.

I'll put instructions in it, but you're on your own after that...

axel’s picture

Updated version of the script for convertation phpBB 2.0.11 to Drupal 4.5.2:

http://drupal.ru/node/576

Author of the script - Alexander Mikhailian

--
Axel,
JabberID: laika@jabber.org
Drupal in Russia

pamphile’s picture

I have a similar PHPBB2Drupal migration script - for users alone.

Just ask at mpamphile # hotmail.com.
I'll make it freely available soon

http://scriptdiary.com

iraszl’s picture

that's cool! let us know!

no chance for blogger i guess. :(

http://creativebits.raszl.net

akurashy’s picture

I dont understand what they are talking >_<

pamphile’s picture

IF you use the PHP forum PHPBB ( http://phpbb.com) , and want to transport your users to Drupal, we have scripts that will help you do so...

just ask me at mpamphile # hotmail.com

I'll be launching scriptmigration.com soon, and will list the script there.
The script is not grand, but very useful :)

Marcel
http://01wholesale.com

iraszl’s picture

thanks a lot!
---
http://creativebits.org

yossarian’s picture

Worked for me, may not work for you...

I converted postnuke phpbb. this should convert stand alone too, if the table names are the same (think they are).

This assumes that you have installed Drupal on the same database as phpbb and that you are not using any database prefixes.

Please note that you have to manually edit this and cannot run it as a script. Plus, at the end are two hacks for the BB code module and the QUote module.

(I forgot to mention: you migth get some MySQL errors when running parts of this like "duplicate key for blah blah" - but look at your database -it worked! DOn't run the whole script at once, run each piece separately).



# Forums
# Add the phpbb forum topics

#Replace XXX with the vid of the vocabularly you want to create, e.g., on a fresh drupal install, you can use "1" - otherwise, check your sequences table for the next available number

INSERT INTO vocabulary
VALUES (XXX, "Forum", "Topics for forums", "", 0, 1, 0, 1, "forum", -10);


# add the forum head topics by forum categories 
#Replace YYY with the next available term data TID from your sequences table. 
#For a fresh install, you can just delete "+ YYY". Replace XXX with the number you used above.

INSERT INTO term_data (tid, vid, name, description, weight)
   SELECT cat_id + YYY, XXX, cat_title, cat_title, 0 FROM phpbb_categories;



#YYY same number as above or delete

INSERT INTO term_hierarchy (tid, parent)
   SELECT cat_id + YYY, 0 FROM phpbb_categories;

	 
	 
# add the forum specific topics.
#Check your term_data table and find the highest TID number 
#and replace ZZZ with a higher number. 
#Use same XXX as above.

INSERT INTO term_data (tid, vid, name, description, weight)
   SELECT forum_id + ZZZ, XXX, forum_name, forum_desc, 0 FROM phpbb_forums;


INSERT INTO term_hierarchy (tid, parent)
   SELECT forum_id + ZZZ, cat_id + YYY FROM phpbb_forums;

#
# Create temporary tables for sorting topics and comments.
#

DROP TABLE IF EXISTS temp_posts;
CREATE TABLE temp_posts (
   post_id mediumint(8) UNSIGNED NOT NULL auto_increment,
   topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
   forum_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
   poster_id mediumint(8) DEFAULT '0' NOT NULL,
   post_time int(11) DEFAULT '0' NOT NULL,
   post_edit_time int(11),
   post_subject char(120),
   post_text text,
   PRIMARY KEY (post_id),
   KEY forum_id (forum_id),
   KEY topic_id (topic_id),
   KEY poster_id (poster_id),
   KEY post_time (post_time)
);
DROP TABLE IF EXISTS temp_node;
CREATE TABLE temp_node (
   post_id mediumint(8) UNSIGNED NOT NULL auto_increment,
   topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
   PRIMARY KEY (post_id),
   KEY topic_id (topic_id)
);
   
#
# Copy into temporary table topics without comments
#

INSERT INTO temp_node (post_id,topic_id)
	SELECT MIN(post_id), topic_id
	FROM phpbb_posts
	GROUP BY topic_id;
INSERT INTO temp_posts (post_id, topic_id,forum_id,poster_id, post_time,post_edit_time,post_subject,post_text)
	SELECT c.post_id, c.topic_id, a.forum_id, IF(a.poster_id='-1','0',a.poster_id), a.post_time, a.post_edit_time, REPLACE(b.post_subject, CONCAT(':',b.bbcode_uid),''), REPLACE(b.post_text, CONCAT(':',b.bbcode_uid),'')
	FROM phpbb_posts AS a, phpbb_posts_text AS b, temp_node AS c
	WHERE c.post_id=a.post_id AND c.post_id=b.post_id;

#
# Insert nid and tid from temp_posts into term_node
#

#check your node table and find the highest NID 
#and replace WWW with a higher number. 
#USe same ZZZ as above

INSERT INTO term_node (nid,tid)
	SELECT WWW+topic_id,ZZZ+forum_id
	FROM temp_posts;

ALTER TABLE term_node ORDER BY nid;

#
# Insert forum topics from temp_posts into node

#USe same WWW as above


INSERT INTO node (nid,type,title,uid,created,comment,body,changed)
	SELECT WWW+topic_id,'forum',post_subject,poster_id,post_time,'2',post_text,IF(post_edit_time<>'NULL',post_edit_time,post_time)
	FROM temp_posts;

ALTER TABLE node ORDER BY nid;

#
# Insert nid into forum 

#Use same WWW and ZZZ as above

DELETE FROM forum;
INSERT INTO forum (nid,tid)
	SELECT WWW+topic_id,ZZZ+forum_id
	FROM temp_posts;

#
# Insert comments into comments for topics from temp_posts

#Use same WWW as above

INSERT INTO comments (nid,uid,subject,comment,hostname,timestamp,users)
	SELECT WWW+a.topic_id,
	CASE WHEN a.poster_id='-1' THEN '0' ELSE a.poster_id END,
	REPLACE(c.post_subject, CONCAT(':',c.bbcode_uid),''),
	REPLACE(c.post_text, CONCAT(':',c.bbcode_uid),''),
	CONCAT_WS('.',CONV(SUBSTRING(a.poster_ip,1,2),16,10),CONV(SUBSTRING(a.poster_ip,3,2),16,10),CONV(SUBSTRING(a.poster_ip,5,2),16,10),CONV(SUBSTRING(a.poster_ip,7,2),16,10)),
	a.post_time,'a:1:{i:0;i:0;}'
	FROM phpbb_posts AS a LEFT JOIN temp_posts AS b ON a.post_id=b.post_id,phpbb_posts_text AS c
	WHERE b.post_id IS NULL AND a.post_id=c.post_id;
ALTER TABLE comments ORDER BY cid;



UPDATE comments,node
	SET comments.subject=IF(comments.subject='',CONCAT('Re:',node.title),comments.subject)
	WHERE comments.nid=node.nid;
	
DROP TABLE IF EXISTS temp_posts;
DROP TABLE IF EXISTS temp_node;

#replace UUU with number higher than your highest current UID, 
#or delete +UUU if this is fresh install

INSERT INTO users (uid+UUU,name,pass,mail,signature,timestamp,status,init,rid)
	SELECT  user_id,username,user_password,user_email,user_sig,IF(user_session_time='0',user_regdate,user_session_time),'1',user_email,'2'
	FROM phpbb_users;
	WHERE user_id>1




#replace WWW

INSERT INTO node_comment_statistics(
nid,
last_comment_timestamp,
last_comment_name,
last_comment_uid,
comment_count
)
SELECT
t.topic_id + WWW,
t.topic_time,
p.name,
t.topic_poster,
t.topic_replies
FROM phpbb_topics t, users p
WHERE t.topic_poster = p.uid;	

#replace WWW

UPDATE node_comment_statistics n, phpbb_topics z  SET
n.last_comment_timestamp = z.topic_last_post_id

WHERE  n.nid = z.topic_id + WWW AND z.topic_last_post_id != 0;


UPDATE node_comment_statistics n, users z,  phpbb_posts p  SET
n.last_comment_name = z.name, n.last_comment_uid = z.uid 

WHERE  p.post_id = n.last_comment_timestamp and p.poster_id = z.uid;



UPDATE node_comment_statistics n,  phpbb_posts p  SET
n.last_comment_timestamp = p.post_time

WHERE  p.post_id = n.last_comment_timestamp AND n.last_comment_timestamp != 0 ;


#
# Update Drupal variables 

# This may not work and you ahve to update sequnces manually


SELECT @term_data_tid:=MAX(tid) FROM term_data;
SELECT @comments_cid:=MAX(cid) FROM comments;
SELECT @node_nid:=MAX(nid) FROM node WHERE type = 'forum';
SELECT @users_uid:=MAX(uid) FROM users;

UPDATE sequences SET id=@term_data_tid WHERE name='term_data_tid';
UPDATE sequences SET id=@comments_cid WHERE name = 'comments_cid';
UPDATE sequences SET id=@node_nid WHERE name = 'node_nid';
UPDATE sequences SET id=@users_uid WHERE name = 'users_uid';


#Now you have to install the Drupal BB code module AND the Drupal Quote Module, and you have to hack them:

#In the quote module replace function _quote_filter_process($text) with this:


function _quote_filter_process($text) {
  // Quoting with or without specifying the source (code borrowed from bbcode.module)
  // Thanks: function based on code from punbb.org
  if (strpos($text, '[quote') !== false) {
    $text = preg_replace('#\[quote=(?:&quot;|"|\')?(.*?)["\']?(?:&quot;|"|\')?\]#si', '<div class="quote-msg"><div class="quote-author">'.'\\1'." ".t("wrote:").'</div>', $text);
    $text = str_replace('[quote]', '<div class="quote-msg"><div class="quote-author">'.t("Quote:").'</div>', $text);    $text = str_replace('[/quote]', '</div>', $text);
  
$text = preg_replace('#\[quote:(.*?)=(?:&quot;|"|\')?(.*?)["\']?(?:&quot;|"|\')?\]#si', '<div class="quote-msg"><div class="quote-author">'.'\\2'." ".t("wrote:").'</div>', $text);
    $text = str_replace('[quote]', '<div class="quote-msg"><div class="quote-author">'.t("Quote:").'</div>', $text);    $text = preg_replace('#\[/quote:(.*?)\]#', '</div>', $text);
      
    }
  return $text;
}



#In the BB code module, file bb-code-filter.inc, comment out the following lines:

     Quoting with or without specifying the source
    '#\[quote(?::\w+)?\](?:[\r\n])*(.*?)\[/quote(?::\w+)?\]#si'         => '<div class="bb-quote">'.$quote_text.':<div class="bb-quote-body">\\1</div></div>',
    '#\[quote:(.*?)=(?:&quot;|"|\')?(.*?)["\']?(?:&quot;|"|\')?\](?:[\r\n])*(.*?)\[/quote(?::\w+)?\]#si'   => '<div class="bb-quote">'.$quote_user.':<div class="bb-quote-body">\\2</div></div>',

iraszl’s picture

I really appreciate your help, but, I'm afraid I will not be able to use your code. It's way too advanced for my designer brain. :)

I don't want to bother you with millions of questions, just tell me how and where do I run such a script?
---
http://creativebits.org

yossarian’s picture

you can use phpmyadmin.

iraszl’s picture

Jasper, would you be available to do a conversion for me? Please drop me an email to discuss costs. Thanks!
---
http://creativebits.org

irwin’s picture

I've managed to convert a phpBB2 2.0.11 to Drupal CVS using most of the above script, but a few changes were required. For example, the users table didn't import cleanly...

 # User Tables Importing 
 #replace UUU with number higher than your highest current UID,
 #or delete +UUU if this is fresh install
 INSERT INTO users (uid,name,pass,mail,signature,created,status,timezone,init,data)
 SELECT user_id,username,user_password,user_email,user_sig,IF(user_session_time='0',user_regdate,user_session_time),'1',user_timezone,user_email,'a:1:{s:5:"roles";a:1:{s:18:"authenticated user";i:2;}}'
 FROM suikoden.phpbb_users WHERE user_id>1;

Also, after doing this, I had to manually assign every user a role. I suspect that there's a user-role table that one has to set.

This wasn't the only change - I had a board where there were identical numbers for Topic IDs and Forum IDs, and they ended up overwriting each other, so I had to manually ensure they were imported correctly, and so forth. Also, I had to update the sequences table as well because the code section didn't work.

It was actually a bit of work to do it right. Even now I'm afraid there's going to be lingering errors due to database inconsistencies.

-- Irwin

bjorn at bie dot no’s picture

I followed these suggestions to convert from phpBB 2.0.13 to Drupal 4.5.2. Mostly it seems to work fine, but the older topics have all lost their title's (anyone know why).

Note that my forum was first converted from InvisionBoard to phpBB, and then to Drupal - that might have something to do with it? ;)

phpuser’s picture

can Irwin or anybody help in starting to use drupal.
I have to use it along with cms..

phpuser’s picture

i need somebody's help to use drupal urgently!!
can u suggest some steps for it

thava’s picture

Hi there

I have try to convert my phpbb databse to drupal, i can't get it work?
can anyone of you help me?

i am running phpBB 2.0.10 and drupal v. 4.5.2

let me know how to do that? or if you could do it for me, then it will be cool?
my email and msn: thava(at)sabanathan(dot)dk

thank you
/ Thava

phpuser’s picture

pls tell me the steps to use drupal

pamphile’s picture

really nice hack !

Merlin Senger’s picture

Hi, I want to import phpbb data to an existing installation of Drupal 4.6.2. I started to hack the database a little bit, but the topic does not appear and I hope that someone here knows why:

- I added a new record to "node", excactly like an existing forum topic but (of course) with a different "nid" (35 instead of 28). q=node/35 now shows the new topic.

- I added (35,1) to "forum" because I saw that (28,1) was in there

- I added (35,1) to "term_node". After that on q=node/35 there appeared (as expected) the message "posted in Forum X".

q=node/35 works now. q=taxonomy/term/1 shows all topic's teasers (including the new one) but q=forum/1 shows the topic list without my new topic.

Any ideas, what to do?
Thanks in advance.

Merlin

beginner’s picture

The latest version of the migration script is now stored in cvs. See here for details:
http://drupal.org/node/24637

--
http://www.reuniting.info/
Healing with Sexual Relationships.

manofsteel’s picture

Is anyone still interested in this? I have run the script just fine for my own PHPBB system. Thanks to the creator of that script. I did run into a few problems that I was able to fix. Let me know if you want more details. I could also probably post my own version with the fixes which ran through with no errors and did the job. Note that I am using Drupal 4.6.3 and PHPBB 2.0.15

Anonymous’s picture

Yes, I am still interested in this.

I am coming out of postnuke PNphpBB and I am ready to make the jump intro drupal. I see all the scripts here to do it, but is there any one that I should try first?

fuzzie’s picture

This is great...just trying to get my users, and I am getting this:
#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '+100,name,pass,mail,signature,created,status,timezone,init,data

Any ideas?

hadishon’s picture

Has this script been updated to convert to 4.7? If not, I would greatly appreciate it.

Otherwise, I was thinking I would have to install older versions of drupal, convert, then update.

hadishon’s picture

I attempted to modify the script to work with 4.7. It seems as though the users migrate successfully. The containers to the forums appear to be made correctly as well as the top level forums.

The problem is that all the forum posts are scattered about, duplicated, combined and just plain strange.

If anyone can help me find the problem in the script that I missed while trying to convert it to 4.7, I would greatly appreciate it. Here is what I used:

<?php
#
# Written by Feodor (feodor [at] mundo.ru)
#
# Modified for drupal 4.5.2 and phpbb 2.0.11-2.0.13
# by Alexander Mikhailian <mikhailian@altern.org>
#
# This script makes an assumption that phpbb and drupal tables are kept in
# one and the same database. Phpbb tables are expected to have the prefix
# phpbb_ and drupal tables are expected to have the prefix 
#
# If phpBB forum use CP1251 (or another) encoding, the tables must be converted
# into UTF8. If version of MySQL less then 4.1 "iconv" command can be used for
# convertion of exported tables into UTF8.
#
# Example:
# iconv -fcp1251 -tutf8 < phpbb2.sql > phpbb2_utf-8.sql
#
# Here is a list of phpbb tables used by script for import into Drupal:
#
# <*> phpbb_categories
# <*> phpbb_forums
# <*> phpbb_posts
# <*> phpbb_posts_text
# <*> phpbb_users
# <*> phpbb_vote_desc
# <*> phpbb_vote_results
#
# You should probably edit the two variables below to match your result:

#
# The name of the forums taxanomy as it appears on the site
#
SELECT @forum_title:='Forums';


# Start importing users from this id. Do not forget that uid 1 is always 
# the Administrator in Drupal. Depending on whether you already created
# the Administrator user in Drupal or not, you may want to change this
# variable into 2.
#
SELECT @first_phpbb_user_id:=6; # uid 1 is always an administrator in Drupal

#
# Drupal variables for node counts
#
SELECT @phpbb_terms:=MAX(forum_id) FROM phpbb_forums;
SELECT @phpbb_cat:=MAX(cat_id) FROM phpbb_categories;
SELECT @term_data_tid:=id FROM sequences WHERE name = 'term_data_tid';
  SELECT IF( @term_data_tid>0,  @term_data_tid, @term_data_tid:=0);
SELECT @comments_cid:=id FROM sequences WHERE name = 'comments_cid';
  SELECT IF( @comments_cid>0,  @comments_cid, @comments_cid:=0);
SELECT @vocabulary_vid:=id FROM sequences WHERE name = 'vocabulary_vid';
  SELECT IF( @vocabulary_vid>0,  @vocabulary_vid, @vocabulary_vid:=0);
SELECT @node_nid:=id FROM sequences WHERE name = 'node_nid';
  SELECT IF( @node_nid>0,  @node_nid, @node_nid:=0);

#
# Import user forms phpbb_users
#
INSERT INTO users (uid,name,pass,mail,mode,sort,threshold,theme,signature,created,status,timezone,language,picture,init,data)
  SELECT  

user_id,username,user_password,user_email,0,0,0,'',user_sig,user_regdate,1,0,'',user_avatar,user_email,'a:1:{s:5:"roles";a:1:{i:0;s:1:"2";}}'
  FROM phpbb_users
  WHERE user_id>=@first_phpbb_user_id;

#
# Create a vocabulary (called "Forum")
#
DELETE FROM vocabulary WHERE module='forum';
INSERT INTO vocabulary (vid,name,description,help,relations,hierarchy,multiple,required,module,weight)
  SELECT @vocabulary_vid+1,@forum_title,'','','0','2','0','1','forum','0';


# Set up the vocabulary "Forum" as the forum vocabulary

DELETE FROM variable WHERE name = 'forum_nav_vocabulary';
INSERT INTO variable (name, value) VALUES ('forum_nav_vocabulary', CONCAT('s:1:\"',@vocabulary_vid+1,'\";'));

#
# The default comment order in phpbb2 is "oldest first"
#
DELETE FROM variable WHERE name = 'comment_default_order';
INSERT INTO variable (name, value) VALUES ('comment_default_order', 's:1:\"2\";');

#
# Import categories from phpbb_categories as terms
#
INSERT INTO term_data (tid,vid,name,weight)
  SELECT @term_data_tid+cat_id,@vocabulary_vid+1,cat_title,cat_order
  FROM phpbb_categories;
  
#
# Import terms from phpbb_forums
#  
INSERT INTO term_data (tid,vid,name,description,weight)
  SELECT @term_data_tid+@phpbb_cat+forum_id,@vocabulary_vid+1, forum_name,forum_desc,forum_order
  FROM phpbb_forums;

ALTER TABLE term_data ORDER BY tid;


# Import forum hierarchy 
# Drupal allows topics to be created at this level while phpbb2 does not. If you want to disallow topics below
# categories, mark them as containers in the forum configuration dialog
#
INSERT INTO term_hierarchy (tid,parent)
  SELECT @term_data_tid+cat_id,'0'
  FROM phpbb_categories;

INSERT INTO term_hierarchy (tid,parent)
  SELECT @term_data_tid+@phpbb_cat+forum_id, @term_data_tid+cat_id
  FROM phpbb_forums;
  
ALTER TABLE term_hierarchy ORDER BY tid;

#
# Create temporary tables for sorting topics and comments.
#

DROP TABLE IF EXISTS temp_posts;
CREATE TABLE temp_posts (
   post_id mediumint(8) UNSIGNED NOT NULL auto_increment,
   topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
   forum_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
   poster_id mediumint(8) DEFAULT '0' NOT NULL,
   post_time int(11) DEFAULT '0' NOT NULL,
   post_edit_time int(11),
   post_subject char(512),
   post_text text,
   PRIMARY KEY (post_id),
   KEY forum_id (forum_id),
   KEY topic_id (topic_id),
   KEY poster_id (poster_id),
   KEY post_time (post_time)
);
DROP TABLE IF EXISTS temp_node;
CREATE TABLE temp_node (
   post_id mediumint(8) UNSIGNED NOT NULL auto_increment,
   topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
   PRIMARY KEY (post_id),
   KEY topic_id (topic_id)
);
   

# Copy into temporary table topics without comments

INSERT INTO temp_node (post_id,topic_id)
  SELECT MIN(post_id), topic_id
  FROM phpbb_posts
  GROUP BY topic_id;
INSERT INTO temp_posts (post_id, topic_id,forum_id,poster_id, post_time,post_edit_time,post_subject,post_text)
  SELECT c.post_id, c.topic_id, a.forum_id, IF(a.poster_id='-1','0',a.poster_id), a.post_time, a.post_edit_time, 
  REPLACE(b.post_subject, CONCAT(':',b.bbcode_uid),''), REPLACE(b.post_text, CONCAT(':',b.bbcode_uid),'')
  FROM phpbb_posts AS a, phpbb_posts_text AS b, temp_node AS c
  WHERE c.post_id=a.post_id AND c.post_id=b.post_id;

#
# Insert nid and tid from temp_posts into term_node
#
INSERT INTO term_node (nid,tid)
  SELECT @node_nid+topic_id,@term_data_tid+@phpbb_cat+forum_id
  FROM temp_posts;

ALTER TABLE term_node ORDER BY nid;

#
# Insert forum topics from temp_posts into node
#
INSERT INTO node (nid,type,title,uid,created,comment,changed)
  SELECT @node_nid+topic_id,'forum',post_subject,poster_id,post_time,'2',
  IF(post_edit_time<>'NULL',post_edit_time,post_time)
  FROM temp_posts;

ALTER TABLE node ORDER BY nid;

#
# Insert forum topics from temp_posts into node_revisions
#
INSERT INTO node_revisions (nid,title,uid,body)
  SELECT @node_nid+topic_id,post_subject,poster_id,post_text
  FROM temp_posts;

ALTER TABLE node_revisions ORDER BY nid;

#
# Insert nid into forum 
#
DELETE FROM forum;
INSERT INTO forum (nid,tid)
  SELECT @node_nid+topic_id,@term_data_tid+@phpbb_cat+forum_id
  FROM temp_posts;

#
# Insert comments into comments for topics from temp_posts
#
INSERT INTO comments (nid,uid,subject,comment,hostname,timestamp,users)
  SELECT @node_nid+a.topic_id,
  CASE WHEN a.poster_id='-1' THEN '0' ELSE a.poster_id END,
  REPLACE(c.post_subject, CONCAT(':',c.bbcode_uid),''),
  REPLACE(c.post_text, CONCAT(':',c.bbcode_uid),''),
  CONCAT_WS('.',CONV(SUBSTRING(a.poster_ip,1,2),16,10),
    CONV(SUBSTRING(a.poster_ip,3,2),16,10),
    CONV(SUBSTRING(a.poster_ip,5,2),16,10),
    CONV(SUBSTRING(a.poster_ip,7,2),16,10)),
  a.post_time,'a:1:{i:0;i:0;}'
  FROM phpbb_posts AS a LEFT JOIN temp_posts AS b ON a.post_id=b.post_id,phpbb_posts_text AS c
  WHERE b.post_id IS NULL AND a.post_id=c.post_id;
ALTER TABLE comments ORDER BY cid;

UPDATE comments,node
  SET comments.subject=IF(comments.subject='',
    CONCAT('Re:',node.title),comments.subject)
  WHERE comments.nid=node.nid;
  
#
# Update thread in comments
#
DROP TABLE IF EXISTS comments_tmp;
CREATE TABLE comments_tmp (
   cid int(10) NOT NULL default '0',
    nid int(10) NOT NULL default '0',
    thread int(10) NOT NULL  auto_increment,
    PRIMARY KEY  (nid,thread)
    );
    
INSERT INTO comments_tmp (cid,nid)
  SELECT cid,nid
  FROM comments
  WHERE cid>@comments_cid;

UPDATE comments,comments_tmp 
  SET comments.thread=CONCAT(CONCAT(REPEAT(9,
    LEFT(comments_tmp.thread,LENGTH(comments_tmp.thread)-1)),
    RIGHT(comments_tmp.thread,1)),'/') 
  WHERE comments.cid=comments_tmp.cid;

#
# Update history
#
#INSERT INTO history (uid, nid, timestamp)
#  SELECT a.uid, b.nid, a.timestamp
#  FROM users AS a, node AS b
#  WHERE a.uid>0 AND b.nid>@node_nid;

#
# update topic statistics 
#

INSERT INTO node_comment_statistics 
  (nid,last_comment_timestamp,last_comment_name,last_comment_uid,comment_count)
  SELECT @node_nid+pt.topic_id, pp.post_time, ppt.post_subject, pp.poster_id, 
    pt.topic_replies
  FROM node dn, phpbb_topics pt, phpbb_posts pp, phpbb_posts_text ppt
  WHERE dn.nid = @node_nid+pt.topic_id 
    AND pt.topic_last_post_id = pp.post_id 
    AND pp.post_id = ppt.post_id;

#
# Delete all temp tables
#
DROP TABLE IF EXISTS temp_posts;
DROP TABLE IF EXISTS comments_tmp;
DROP TABLE IF EXISTS temp_node;
?>

(edit) I added the php code tags to add color to help people find the problems. This is NOT a php code! It is a MySQL script.

tomamic’s picture

I noticed you forgot setting the revision id (vid) in node_revisions. You can get the latest vid in the same way you get the latest nid. Then you have to add the topic_id to it (as you do for nid).

This is the way I modified the script, and it worked fine. I would like to share my code, but probably posting here is not the best choice. Is there a better place? Moreover, 4.7 is still a beta, and I'm not sure the db won't change again.

Ciao. Mic

hadishon’s picture

Could you send me a copy of your script?

michael at activefarming.com

I think the correct place for the code to reside for a tool is here: http://drupal.org/node/24637

I think an admin would need to put it there though unless you ad it as a comment.

2 of my Drupal sites:
Small Farm Resource Center
Israel Travel Center

terbaik’s picture

thanks you for sharing, I am new user drupal for news media