| 1 |
# $Id$
|
| 2 |
#
|
| 3 |
# Written by Feodor (feodor [at] mundo.ru)
|
| 4 |
#
|
| 5 |
# Modified for drupal 4.5.2 and phpbb 2.0.11-2.0.13
|
| 6 |
# by Alexander Mikhailian <mikhailian@altern.org>
|
| 7 |
#
|
| 8 |
# This script makes an assumption that phpbb and drupal tables are kept in
|
| 9 |
# one and the same database. Phpbb tables are expected to have the prefix
|
| 10 |
# phpbb_ and drupal tables are expected to have the prefix drupal_
|
| 11 |
#
|
| 12 |
# If phpBB forum use CP1251 (or another) encoding, the tables must be converted
|
| 13 |
# into UTF8. If version of MySQL less then 4.1 "iconv" command can be used for
|
| 14 |
# convertion of exported tables into UTF8.
|
| 15 |
#
|
| 16 |
# Example:
|
| 17 |
# iconv -fcp1251 -tutf8 < phpbb2.sql > phpbb2_utf-8.sql
|
| 18 |
#
|
| 19 |
# Here is a list of phpbb tables used by script for import into Drupal:
|
| 20 |
#
|
| 21 |
# <*> phpbb_categories
|
| 22 |
# <*> phpbb_forums
|
| 23 |
# <*> phpbb_posts
|
| 24 |
# <*> phpbb_posts_text
|
| 25 |
# <*> phpbb_users
|
| 26 |
# <*> phpbb_vote_desc
|
| 27 |
# <*> phpbb_vote_results
|
| 28 |
#
|
| 29 |
# You should probably edit the two variables below to match your result:
|
| 30 |
|
| 31 |
#
|
| 32 |
# The name of the forums taxanomy as it appears on the site
|
| 33 |
#
|
| 34 |
SELECT @forum_title:='Forums';
|
| 35 |
|
| 36 |
#
|
| 37 |
# Start importing users from this id. Do not forget that uid 1 is always
|
| 38 |
# the Administrator in Drupal. Depending on whether you already created
|
| 39 |
# the Administrator user in Drupal or not, you may want to change this
|
| 40 |
# variable into 2.
|
| 41 |
#
|
| 42 |
SELECT @first_phpbb_user_id:=1; # uid 1 is always an administrator in Drupal
|
| 43 |
|
| 44 |
#
|
| 45 |
# Drupal variables for node counts
|
| 46 |
#
|
| 47 |
SELECT @phpbb_terms:=MAX(forum_id) FROM phpbb_forums;
|
| 48 |
SELECT @phpbb_cat:=MAX(cat_id) FROM phpbb_categories;
|
| 49 |
SELECT @drupal_term_data_tid:=id FROM drupal_sequences WHERE name = 'drupal_term_data_tid';
|
| 50 |
SELECT IF( @drupal_term_data_tid>0, @drupal_term_data_tid, @drupal_term_data_tid:=0);
|
| 51 |
SELECT @drupal_comments_cid:=id FROM drupal_sequences WHERE name = 'drupal_comments_cid';
|
| 52 |
SELECT IF( @drupal_comments_cid>0, @drupal_comments_cid, @drupal_comments_cid:=0);
|
| 53 |
SELECT @drupal_vocabulary_vid:=id FROM drupal_sequences WHERE name = 'drupal_vocabulary_vid';
|
| 54 |
SELECT IF( @drupal_vocabulary_vid>0, @drupal_vocabulary_vid, @drupal_vocabulary_vid:=0);
|
| 55 |
SELECT @drupal_node_nid:=id FROM drupal_sequences WHERE name = 'drupal_node_nid';
|
| 56 |
SELECT IF( @drupal_node_nid>0, @drupal_node_nid, @drupal_node_nid:=0);
|
| 57 |
|
| 58 |
#
|
| 59 |
# Import user forms phpbb_users
|
| 60 |
#
|
| 61 |
INSERT INTO drupal_users (uid,name,pass,mail,mode,sort,threshold,theme,signature,created,changed,status,timezone,language,picture,init,data)
|
| 62 |
SELECT user_id,username,user_password,user_email,0,0,0,'',user_sig,user_regdate,user_lastvisit,1,0,'',user_avatar,user_email,'a:1:{s:5:"roles";a:1:{i:0;s:1:"2";}}'
|
| 63 |
FROM phpbb_users
|
| 64 |
WHERE user_id>=@first_phpbb_user_id;
|
| 65 |
|
| 66 |
#
|
| 67 |
# Create a vocabulary (called "Forum")
|
| 68 |
#
|
| 69 |
DELETE FROM drupal_vocabulary WHERE nodes='forum';
|
| 70 |
INSERT INTO drupal_vocabulary (vid,name,description,help,relations,hierarchy,multiple,required,nodes,weight)
|
| 71 |
SELECT @drupal_vocabulary_vid+1,@forum_title,'','','0','2','0','1','forum','0';
|
| 72 |
|
| 73 |
#
|
| 74 |
# Set up the vocabulary "Forum" as the forum vocabulary
|
| 75 |
#
|
| 76 |
DELETE FROM drupal_variable WHERE name = 'forum_nav_vocabulary';
|
| 77 |
INSERT INTO drupal_variable (name, value) VALUES ('forum_nav_vocabulary', CONCAT('s:1:\"',@drupal_vocabulary_vid+1,'\";'));
|
| 78 |
|
| 79 |
#
|
| 80 |
# The default comment order in phpbb2 is "oldest first"
|
| 81 |
#
|
| 82 |
DELETE FROM drupal_variable WHERE name = 'comment_default_order';
|
| 83 |
INSERT INTO drupal_variable (name, value) VALUES ('comment_default_order', 's:1:\"2\";');
|
| 84 |
|
| 85 |
#
|
| 86 |
# Import categories from phpbb_categories as terms
|
| 87 |
#
|
| 88 |
INSERT INTO drupal_term_data (tid,vid,name,weight)
|
| 89 |
SELECT @drupal_term_data_tid+cat_id,@drupal_vocabulary_vid+1,cat_title,cat_order
|
| 90 |
FROM phpbb_categories;
|
| 91 |
|
| 92 |
#
|
| 93 |
# Import terms from phpbb_forums
|
| 94 |
#
|
| 95 |
INSERT INTO drupal_term_data (tid,vid,name,description,weight)
|
| 96 |
SELECT @drupal_term_data_tid+@phpbb_cat+forum_id,@drupal_vocabulary_vid+1, forum_name,forum_desc,forum_order
|
| 97 |
FROM phpbb_forums;
|
| 98 |
|
| 99 |
ALTER TABLE drupal_term_data ORDER BY tid;
|
| 100 |
|
| 101 |
#
|
| 102 |
# Import forum hierarchy
|
| 103 |
# Drupal allows topics to be created at this level while phpbb2 does not. If you want to disallow topics below
|
| 104 |
# categories, mark them as containers in the forum configuration dialog
|
| 105 |
#
|
| 106 |
INSERT INTO drupal_term_hierarchy (tid,parent)
|
| 107 |
SELECT @drupal_term_data_tid+cat_id,'0'
|
| 108 |
FROM phpbb_categories;
|
| 109 |
|
| 110 |
INSERT INTO drupal_term_hierarchy (tid,parent)
|
| 111 |
SELECT @drupal_term_data_tid+@phpbb_cat+forum_id, @drupal_term_data_tid+cat_id
|
| 112 |
FROM phpbb_forums;
|
| 113 |
|
| 114 |
ALTER TABLE drupal_term_hierarchy ORDER BY tid;
|
| 115 |
|
| 116 |
#
|
| 117 |
# Create temporary tables for sorting topics and comments.
|
| 118 |
#
|
| 119 |
|
| 120 |
DROP TABLE IF EXISTS temp_posts;
|
| 121 |
CREATE TABLE temp_posts (
|
| 122 |
post_id mediumint(8) UNSIGNED NOT NULL auto_increment,
|
| 123 |
topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
| 124 |
forum_id smallint(5) UNSIGNED DEFAULT '0' NOT NULL,
|
| 125 |
poster_id mediumint(8) DEFAULT '0' NOT NULL,
|
| 126 |
post_time int(11) DEFAULT '0' NOT NULL,
|
| 127 |
post_edit_time int(11),
|
| 128 |
post_subject char(512),
|
| 129 |
post_text text,
|
| 130 |
PRIMARY KEY (post_id),
|
| 131 |
KEY forum_id (forum_id),
|
| 132 |
KEY topic_id (topic_id),
|
| 133 |
KEY poster_id (poster_id),
|
| 134 |
KEY post_time (post_time)
|
| 135 |
);
|
| 136 |
DROP TABLE IF EXISTS temp_node;
|
| 137 |
CREATE TABLE temp_node (
|
| 138 |
post_id mediumint(8) UNSIGNED NOT NULL auto_increment,
|
| 139 |
topic_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
|
| 140 |
PRIMARY KEY (post_id),
|
| 141 |
KEY topic_id (topic_id)
|
| 142 |
);
|
| 143 |
|
| 144 |
#
|
| 145 |
# Copy into temporary table topics without comments
|
| 146 |
#
|
| 147 |
INSERT INTO temp_node (post_id,topic_id)
|
| 148 |
SELECT MIN(post_id), topic_id
|
| 149 |
FROM phpbb_posts
|
| 150 |
GROUP BY topic_id;
|
| 151 |
INSERT INTO temp_posts (post_id, topic_id,forum_id,poster_id, post_time,post_edit_time,post_subject,post_text)
|
| 152 |
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,
|
| 153 |
REPLACE(b.post_subject, CONCAT(':',b.bbcode_uid),''), REPLACE(b.post_text, CONCAT(':',b.bbcode_uid),'')
|
| 154 |
FROM phpbb_posts AS a, phpbb_posts_text AS b, temp_node AS c
|
| 155 |
WHERE c.post_id=a.post_id AND c.post_id=b.post_id;
|
| 156 |
|
| 157 |
#
|
| 158 |
# Insert nid and tid from temp_posts into drupal_term_node
|
| 159 |
#
|
| 160 |
INSERT INTO drupal_term_node (nid,tid)
|
| 161 |
SELECT @drupal_node_nid+topic_id,@drupal_term_data_tid+@phpbb_cat+forum_id
|
| 162 |
FROM temp_posts;
|
| 163 |
|
| 164 |
ALTER TABLE drupal_term_node ORDER BY nid;
|
| 165 |
|
| 166 |
#
|
| 167 |
# Insert forum topics from temp_posts into drupal_node
|
| 168 |
#
|
| 169 |
INSERT INTO drupal_node (nid,type,title,uid,created,comment,body,changed)
|
| 170 |
SELECT @drupal_node_nid+topic_id,'forum',post_subject,poster_id,post_time,'2',post_text,
|
| 171 |
IF(post_edit_time<>'NULL',post_edit_time,post_time)
|
| 172 |
FROM temp_posts;
|
| 173 |
|
| 174 |
ALTER TABLE drupal_node ORDER BY nid;
|
| 175 |
|
| 176 |
#
|
| 177 |
# Insert nid into drupal_forum
|
| 178 |
#
|
| 179 |
DELETE FROM drupal_forum;
|
| 180 |
INSERT INTO drupal_forum (nid,tid)
|
| 181 |
SELECT @drupal_node_nid+topic_id,@drupal_term_data_tid+@phpbb_cat+forum_id
|
| 182 |
FROM temp_posts;
|
| 183 |
|
| 184 |
#
|
| 185 |
# Insert comments into drupal_comments for topics from temp_posts
|
| 186 |
#
|
| 187 |
INSERT INTO drupal_comments (nid,uid,subject,comment,hostname,timestamp,users)
|
| 188 |
SELECT @drupal_node_nid+a.topic_id,
|
| 189 |
CASE WHEN a.poster_id='-1' THEN '0' ELSE a.poster_id END,
|
| 190 |
REPLACE(c.post_subject, CONCAT(':',c.bbcode_uid),''),
|
| 191 |
REPLACE(c.post_text, CONCAT(':',c.bbcode_uid),''),
|
| 192 |
CONCAT_WS('.',CONV(SUBSTRING(a.poster_ip,1,2),16,10),
|
| 193 |
CONV(SUBSTRING(a.poster_ip,3,2),16,10),
|
| 194 |
CONV(SUBSTRING(a.poster_ip,5,2),16,10),
|
| 195 |
CONV(SUBSTRING(a.poster_ip,7,2),16,10)),
|
| 196 |
a.post_time,'a:1:{i:0;i:0;}'
|
| 197 |
FROM phpbb_posts AS a LEFT JOIN temp_posts AS b ON a.post_id=b.post_id,phpbb_posts_text AS c
|
| 198 |
WHERE b.post_id IS NULL AND a.post_id=c.post_id;
|
| 199 |
ALTER TABLE drupal_comments ORDER BY cid;
|
| 200 |
|
| 201 |
UPDATE drupal_comments,drupal_node
|
| 202 |
SET drupal_comments.subject=IF(drupal_comments.subject='',
|
| 203 |
CONCAT('Re:',drupal_node.title),drupal_comments.subject)
|
| 204 |
WHERE drupal_comments.nid=drupal_node.nid;
|
| 205 |
|
| 206 |
#
|
| 207 |
# Update thread in drupal_comments
|
| 208 |
#
|
| 209 |
DROP TABLE IF EXISTS drupal_comments_tmp;
|
| 210 |
CREATE TABLE drupal_comments_tmp (
|
| 211 |
cid int(10) NOT NULL default '0',
|
| 212 |
nid int(10) NOT NULL default '0',
|
| 213 |
thread int(10) NOT NULL auto_increment,
|
| 214 |
PRIMARY KEY (nid,thread)
|
| 215 |
);
|
| 216 |
|
| 217 |
INSERT INTO drupal_comments_tmp (cid,nid)
|
| 218 |
SELECT cid,nid
|
| 219 |
FROM drupal_comments
|
| 220 |
WHERE cid>@drupal_comments_cid;
|
| 221 |
|
| 222 |
UPDATE drupal_comments,drupal_comments_tmp
|
| 223 |
SET drupal_comments.thread=CONCAT(CONCAT(REPEAT(9,
|
| 224 |
LEFT(drupal_comments_tmp.thread,LENGTH(drupal_comments_tmp.thread)-1)),
|
| 225 |
RIGHT(drupal_comments_tmp.thread,1)),'/')
|
| 226 |
WHERE drupal_comments.cid=drupal_comments_tmp.cid;
|
| 227 |
|
| 228 |
#
|
| 229 |
# Update drupal_history
|
| 230 |
#
|
| 231 |
#INSERT INTO drupal_history (uid, nid, timestamp)
|
| 232 |
# SELECT a.uid, b.nid, a.timestamp
|
| 233 |
# FROM drupal_users AS a, drupal_node AS b
|
| 234 |
# WHERE a.uid>0 AND b.nid>@drupal_node_nid;
|
| 235 |
|
| 236 |
#
|
| 237 |
# update topic statistics
|
| 238 |
#
|
| 239 |
|
| 240 |
INSERT INTO drupal_node_comment_statistics
|
| 241 |
(nid,last_comment_timestamp,last_comment_name,last_comment_uid,comment_count)
|
| 242 |
SELECT @drupal_node_nid+pt.topic_id, pp.post_time, ppt.post_subject, pp.poster_id,
|
| 243 |
pt.topic_replies
|
| 244 |
FROM drupal_node dn, phpbb_topics pt, phpbb_posts pp, phpbb_posts_text ppt
|
| 245 |
WHERE dn.nid = @drupal_node_nid+pt.topic_id
|
| 246 |
AND pt.topic_last_post_id = pp.post_id
|
| 247 |
AND pp.post_id = ppt.post_id;
|
| 248 |
|
| 249 |
#
|
| 250 |
# Delete all temp tables
|
| 251 |
#
|
| 252 |
DROP TABLE IF EXISTS temp_posts;
|
| 253 |
DROP TABLE IF EXISTS drupal_comments_tmp;
|
| 254 |
DROP TABLE IF EXISTS temp_node;
|
| 255 |
|
| 256 |
#
|
| 257 |
# Update Drupal variables
|
| 258 |
#
|
| 259 |
SELECT @drupal_term_data_tid:=MAX(tid) FROM drupal_term_data;
|
| 260 |
SELECT @drupal_comments_cid:=MAX(cid) FROM drupal_comments;
|
| 261 |
SELECT @drupal_node_nid:=MAX(nid) FROM drupal_node WHERE type = 'forum';
|
| 262 |
SELECT @drupal_users_uid:=MAX(uid) FROM drupal_users;
|
| 263 |
|
| 264 |
DELETE FROM drupal_sequences WHERE name="drupal_term_data_tid";
|
| 265 |
DELETE FROM drupal_sequences WHERE name="drupal_comments_cid";
|
| 266 |
DELETE FROM drupal_sequences WHERE name="drupal_node_nid";
|
| 267 |
DELETE FROM drupal_sequences WHERE name="drupal_users_uid";
|
| 268 |
|
| 269 |
INSERT INTO drupal_sequences (name,id) SELECT "drupal_term_data_tid", @drupal_term_data_tid;
|
| 270 |
INSERT INTO drupal_sequences (name,id) SELECT "drupal_comments_cid",@drupal_comments_cid;
|
| 271 |
INSERT INTO drupal_sequences (name,id) SELECT "drupal_node_nid",@drupal_node_nid;
|
| 272 |
INSERT INTO drupal_sequences (name,id) SELECT "drupal_users_uid",@drupal_users_uid;
|
| 273 |
|
| 274 |
#
|
| 275 |
# this is for porting personal messages to privatemsg drupal module
|
| 276 |
#
|
| 277 |
# phpbb_privmsgs.privmsgs_type has the following codes:
|
| 278 |
# written=1, seen in inbox = 5, read = 0, saved = 3
|
| 279 |
#
|
| 280 |
# attention, drupal_privatemsg limits the title to 64 chars, this is too
|
| 281 |
# little
|
| 282 |
#
|
| 283 |
INSERT INTO drupal_privatemsg ( id, author, recipient,subject,message,
|
| 284 |
timestamp,new,hostname,folder,author_del,recipient_del )
|
| 285 |
SELECT p.privmsgs_id, p.privmsgs_from_userid, p.privmsgs_to_userid,
|
| 286 |
p.privmsgs_subject,pt.privmsgs_text,p.privmsgs_date,
|
| 287 |
IF(p.privmsgs_type = 1 OR p.privmsgs_type = 5, 1, 0),
|
| 288 |
p.privmsgs_ip,0,0,0
|
| 289 |
FROM phpbb_privmsgs p
|
| 290 |
LEFT JOIN (phpbb_privmsgs_text pt) ON p.privmsgs_id=pt.privmsgs_text_id;
|
| 291 |
|
| 292 |
#
|
| 293 |
# converting polls
|
| 294 |
#
|
| 295 |
|
| 296 |
INSERT INTO poll(nid,runtime,polled,active)
|
| 297 |
SELECT pvd.topic_id+41,0,'',0
|
| 298 |
FROM phpbb_vote_desc pvd;
|
| 299 |
|
| 300 |
INSERT INTO poll_choices(nid,chtext,chvotes,chorder)
|
| 301 |
SELECT pvd.topic_id+41,
|
| 302 |
pvr.vote_option_text,
|
| 303 |
pvr.vote_result,
|
| 304 |
vote_option_id # TODO chorder should be autoincremented from 1 every
|
| 305 |
# unique pvd.topic_id;
|
| 306 |
FROM phpbb_vote_results pvr, phpbb_vote_desc pvd
|
| 307 |
WHERE pvr.vote_id=pvd.vote_id;
|
| 308 |
|
| 309 |
UPDATE node n, phpbb_vote_desc pvd SET type='poll'
|
| 310 |
WHERE n.nid=pvd.topic_id+41;
|