vbtobb |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/usr/bin/python2.4
# -*- coding: utf8 -*-
import re
import os
import sys
import MySQLdb
import md5
USER_ID_OFFSET=100
USER_GROUP_ID=2
USER_PERMISSIONS='00000000006xv1ssxs'
DB_HOST="localhost"
DB_NAME="phpbb3"
DB_USER="root"
DB_PASS=""
# escape strings for mysql
def mysql_escape_string(str):
newstr = str.replace('\\', '\\\\')
newstr = newstr.replace('\'', '\\\'')
return newstr
# generate bbcode_uid
def make_uid(timestamp):
return "a"+(str(timestamp))[0:7]
#return (timestamp, 16, 36)[0, 8]
# count new user id
def tuid(origid):
global USER_ID_OFFSET
return (USER_ID_OFFSET + origid)
def tpost(orig_post, bbcode_uid):
new_post = orig_post.replace('[QUOTE]','[quote:%s]' % bbcode_uid);
new_post = new_post.replace('[quote]','[quote:%s]' % bbcode_uid);
new_post = new_post.replace('[/QUOTE]','[/quote:%s]' % bbcode_uid);
new_post = new_post.replace('[/quote]','[/quote:%s]' % bbcode_uid);
new_post = new_post.replace('[CODE]','[code:%s]' % bbcode_uid);
new_post = new_post.replace('[code]','[code:%s]' % bbcode_uid);
new_post = new_post.replace('[/CODE]','[/code:%s]' % bbcode_uid);
new_post = new_post.replace('[/code]','[/code:%s]' % bbcode_uid);
new_post = new_post.replace('[url]','[url:%s]' % bbcode_uid);
new_post = new_post.replace('[url]','[url:%s]' % bbcode_uid);
new_post = new_post.replace('[/url]','[/url:%s]' % bbcode_uid);
new_post = new_post.replace('[/url]','[/url:%s]' % bbcode_uid);
new_post = new_post.replace('[B]','[b:%s]' % bbcode_uid);
new_post = new_post.replace('[b]','[b:%s]' % bbcode_uid);
new_post = new_post.replace('[/B]','[/b:%s]' % bbcode_uid);
new_post = new_post.replace('[/b]','[/b:%s]' % bbcode_uid);
new_post = new_post.replace('[I]','[i:%s]' % bbcode_uid);
new_post = new_post.replace('[i]','[i:%s]' % bbcode_uid);
new_post = new_post.replace('[/I]','[/i:%s]' % bbcode_uid);
new_post = new_post.replace('[/i]','[/i:%s]' % bbcode_uid);
new_post = new_post.replace('[U]','[u:%s]' % bbcode_uid);
new_post = new_post.replace('[u]','[u:%s]' % bbcode_uid);
new_post = new_post.replace('[/U]','[/u:%s]' % bbcode_uid);
new_post = new_post.replace('[/u]','[/u:%s]' % bbcode_uid);
return new_post
# counts correct left_id and right_id for all forum items from forum_index
def updateBTree(parent_id):
global forum_index
global current_left_id
for forum_id in forum_index:
if forum_index[forum_id]['parent_id'] == parent_id:
forum_index[forum_id]['left_id'] = current_left_id
current_left_id += 1
updateBTree(forum_id)
forum_index[forum_id]['right_id'] = current_left_id
current_left_id += 1
return
def generateBTreeUpdates():
global forum_index
global current_left_id
current_left_id = 1
updateBTree(0)
for forum_id in forum_index:
print "UPDATE phpbb_forums SET left_id=%d, right_id=%d WHERE forum_id=%d;" % (forum_index[forum_id]['left_id'], forum_index[forum_id]['right_id'], forum_id)
return
def generateForumInserts():
global forum_index
global db
try:
c = db.cursor()
msg = "SELECT * FROM forum ORDER BY forumid;"
c.execute(msg)
while (1):
row = c.fetchone()
if row == None:
break
forumid = row[0]
styleid = row[1]
title = row[2]
description = row[3]
active = row[4]
displayorder = row[5]
replycount = row[6]
lastpost = row[7]
lastposter = row[8]
threadcount = row[9]
allowposting = row[10]
cancontainthreads = row[11]
daysprune = row[12]
newpostemail = row[13]
newthreademail = row[14]
moderatenew = row[15]
moderateattach = row[16]
allowbbcode = row[17]
allowimages = row[18]
allowhtml = row[19]
allowsmilies = row[20]
allowicons = row[21]
parentid = row[22]
parentlist = row[23]
allowratings = row[24]
countposts = row[25]
styleoverride = row[26]
attachlimit = row[27]
phpbb_forum_flags = 32
phpbb_display_on_index = 0
phpbb_left_id = 0
phpbb_right_id = 0
if parentid==-1:
parentid = 0
phpbb_forum_flags = 48
forum_index[forumid] = { 'left_id': phpbb_left_id, 'right_id': phpbb_right_id, 'parent_id': parentid }
print ("INSERT INTO phpbb_forums SET forum_id=%d, parent_id=%d, left_id=%d, right_id=%d, forum_parents='', forum_name='%s', forum_desc='%s', forum_rules='', forum_type=%d, forum_flags=%d, display_on_index=%d;" % (forumid, parentid, phpbb_left_id, phpbb_right_id, mysql_escape_string(title), mysql_escape_string(description), cancontainthreads, phpbb_forum_flags, phpbb_display_on_index))
print ("INSERT INTO phpbb_acl_groups VALUES (5, %d, 0, 14, 0);" % (forumid))
except:
print "Error while accessing data: ", sys.exc_info()[0]
raise
def generateTopicInserts():
global forum_index
global db
try:
c = db.cursor()
msg = "SELECT * FROM thread ORDER BY threadid;"
c.execute(msg)
while (1):
row = c.fetchone()
if row == None:
break
threadid = row[0]
title = row[1]
lastpost = row[2]
forumid = row[3]
pollid = row[4]
open = row[5]
replycount = row[6]
postusername = row[7]
postuserid = row[8]
lastposter = row[9]
dateline = row[10]
views = row[11]
iconid = row[12]
notes = row[13]
visible = row[14]
sticky = row[15]
votenum = row[16]
votetotal = row[17]
attach = row[18]
karma = row[19]
firstpostid = row[20]
print ("INSERT INTO phpbb_topics SET topic_id=%d, forum_id=%d, topic_title='%s', topic_poster=%d, topic_time=%d, topic_first_post_id=%d, topic_first_poster_name='%s', topic_last_poster_name='%s', topic_last_post_time=%d;" % (threadid, forumid, mysql_escape_string(title), tuid(postuserid), dateline, firstpostid, mysql_escape_string(postusername), mysql_escape_string(lastposter), lastpost))
print ("UPDATE phpbb_forums SET forum_topics = forum_topics+1, forum_topics_real = forum_topics_real+1 WHERE forum_id=%d;" % (forumid))
except:
print "Error while accessing data: ", sys.exc_info()[0]
raise
def generatePostInserts():
global forum_index
global db
try:
c = db.cursor()
msg = "SELECT * FROM post ORDER BY postid;"
c.execute(msg)
while (1):
row = c.fetchone()
if row == None:
break
postid = row[0]
threadid = row[1]
username = row[2]
userid = row[3]
title = row[4]
dateline = row[5]
attachmentid = row[6]
pagetext = row[7]
allowsmilie = row[8]
showsignature = row[9]
ipaddress = row[10]
iconid = row[11]
visible = row[12]
edituserid = row[13]
editdate = row[14]
modtype = row[15]
moduser = row[16]
phpbb_bbcode_uid = make_uid(dateline)
phpbb_text = tpost(pagetext, phpbb_bbcode_uid)
print ("INSERT INTO phpbb_posts SET post_id=%d, topic_id=%d, forum_id=(SELECT forum_id FROM phpbb_topics WHERE topic_id=%d), poster_id=%d, post_time=%d, post_username='%s', post_subject='%s', post_text='%s', post_checksum='%s', bbcode_uid='%s', post_edit_time=%d;" % (postid, threadid, threadid, tuid(userid), dateline, mysql_escape_string(username), mysql_escape_string(title), mysql_escape_string(phpbb_text), mysql_escape_string(md5.new(phpbb_text).hexdigest()), phpbb_bbcode_uid, editdate))
print ("UPDATE phpbb_topics SET topic_replies = topic_replies+1, topic_replies_real = topic_replies_real+1 WHERE topic_id=%d;" % (threadid))
print ("UPDATE phpbb_forums SET forum_posts = forum_posts+1, forum_last_post_id=%d, forum_last_post_subject='%s', forum_last_post_time=%d, forum_last_poster_name='%s' WHERE forum_id=(SELECT forum_id FROM phpbb_topics WHERE topic_id=%d);" % (postid, mysql_escape_string(title), dateline, mysql_escape_string(username), threadid))
except:
print "Error while accessing data: ", sys.exc_info()[0]
raise
def generateUserInserts():
global forum_index
global db
global USER_GROUP_ID
global USER_PERMISSIONS
try:
c = db.cursor()
msg = "SELECT * FROM user ORDER BY userid;"
c.execute(msg)
while (1):
row = c.fetchone()
if row == None:
break
userid = row[0]
usergroupid = row[1]
username = row[2]
password = row[3]
email = row[4]
styleid = row[5]
parentemail = row[6]
coppauser = row[7]
homepage = row[8]
icq = row[9]
aim = row[10]
yahoo = row[11]
signature = row[12]
adminemail = row[13]
showemail = row[14]
invisible = row[15]
usertitle = row[16]
customtitle = row[17]
joindate = row[18]
cookieuser = row[19]
daysprune = row[20]
lastvisit = row[21]
lastactivity = row[22]
lastpost = row[23]
posts = row[24]
timezoneoffset = row[25]
emailnotification = row[26]
ignorelist = row[27]
pmfolders = row[28]
receivepm = row[29]
emailonpm = row[30]
karma = row[31]
cangivekarma = row[32]
showkarma = row[33]
latin1 = row[34]
perms = row[35]
rooms = row[36]
reg_time = row[37]
ip = row[38]
mapperms = row[39]
buddylist = row[40]
avatarid = row[41]
inforum = row[42]
options = row[43]
birthday = row[44]
maxposts = row[45]
startofweek = row[46]
ipaddress = row[47]
referrerid = row[48]
pmpopup = row[49]
nosessionhash = row[50]
phpbb_user_type = 2
print ("INSERT INTO phpbb_users SET user_id=%d, user_type=%d, group_id=%d, user_permissions='%s', username='%s', username_clean='%s';" % (tuid(userid), phpbb_user_type, USER_GROUP_ID, USER_PERMISSIONS, mysql_escape_string(username), mysql_escape_string(username)))
except:
print "Error while accessing data: ", sys.exc_info()[0]
raise
db = MySQLdb.connect(DB_HOST, DB_USER, DB_PASS, DB_NAME)
#c.execute = "SET NAMES utf-8;"
current_left_id = 1
forum_index = dict()
generateForumInserts()
generateBTreeUpdates()
generateTopicInserts()
generatePostInserts()
generateUserInserts()
db.commit()
db.close()