jablonka.czprosek.czf

vbtobb

Subversion Repositories:
[/] [trunk/] [convert.py] - Blame information for rev 2

 

Line No. Rev Author Line
12shake#!/usr/bin/python2.4
2# -*- coding: utf8 -*-
3 
4import re
5 
6import os
7import sys
8import MySQLdb
9 
10import md5
11 
12USER_ID_OFFSET=100
13USER_GROUP_ID=2
14USER_PERMISSIONS='00000000006xv1ssxs'
15 
16DB_HOST="localhost"
17DB_NAME="phpbb3"
18DB_USER="root"
19DB_PASS=""
20 
21# escape strings for mysql
22def mysql_escape_string(str):
23 newstr = str.replace('\\', '\\\\')
24 newstr = newstr.replace('\'', '\\\'')
25 return newstr
26 
27# generate bbcode_uid
28def make_uid(timestamp):
29 return "a"+(str(timestamp))[0:7]
30 #return (timestamp, 16, 36)[0, 8]
31 
32# count new user id
33def tuid(origid):
34 global USER_ID_OFFSET
35 return (USER_ID_OFFSET + origid)
36 
37def tpost(orig_post, bbcode_uid):
38 new_post = orig_post.replace('[QUOTE]','[quote:%s]' % bbcode_uid);
39 new_post = new_post.replace('[quote]','[quote:%s]' % bbcode_uid);
40 new_post = new_post.replace('[/QUOTE]','[/quote:%s]' % bbcode_uid);
41 new_post = new_post.replace('[/quote]','[/quote:%s]' % bbcode_uid);
42 new_post = new_post.replace('[CODE]','[code:%s]' % bbcode_uid);
43 new_post = new_post.replace('[code]','[code:%s]' % bbcode_uid);
44 new_post = new_post.replace('[/CODE]','[/code:%s]' % bbcode_uid);
45 new_post = new_post.replace('[/code]','[/code:%s]' % bbcode_uid);
46 new_post = new_post.replace('[url]','[url:%s]' % bbcode_uid);
47 new_post = new_post.replace('[url]','[url:%s]' % bbcode_uid);
48 new_post = new_post.replace('[/url]','[/url:%s]' % bbcode_uid);
49 new_post = new_post.replace('[/url]','[/url:%s]' % bbcode_uid);
50 new_post = new_post.replace('[B]','[b:%s]' % bbcode_uid);
51 new_post = new_post.replace('[b]','[b:%s]' % bbcode_uid);
52 new_post = new_post.replace('[/B]','[/b:%s]' % bbcode_uid);
53 new_post = new_post.replace('[/b]','[/b:%s]' % bbcode_uid);
54 new_post = new_post.replace('[I]','[i:%s]' % bbcode_uid);
55 new_post = new_post.replace('[i]','[i:%s]' % bbcode_uid);
56 new_post = new_post.replace('[/I]','[/i:%s]' % bbcode_uid);
57 new_post = new_post.replace('[/i]','[/i:%s]' % bbcode_uid);
58 new_post = new_post.replace('[U]','[u:%s]' % bbcode_uid);
59 new_post = new_post.replace('[u]','[u:%s]' % bbcode_uid);
60 new_post = new_post.replace('[/U]','[/u:%s]' % bbcode_uid);
61 new_post = new_post.replace('[/u]','[/u:%s]' % bbcode_uid);
62 return new_post
63 
64# counts correct left_id and right_id for all forum items from forum_index
65def updateBTree(parent_id):
66 global forum_index
67 global current_left_id
68 
69 for forum_id in forum_index:
70 if forum_index[forum_id]['parent_id'] == parent_id:
71 forum_index[forum_id]['left_id'] = current_left_id
72 current_left_id += 1
73 updateBTree(forum_id)
74 forum_index[forum_id]['right_id'] = current_left_id
75 current_left_id += 1
76 return
77 
78def generateBTreeUpdates():
79 global forum_index
80 global current_left_id
81 
82 current_left_id = 1
83 updateBTree(0)
84 for forum_id in forum_index:
85 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)
86 return
87 
88def generateForumInserts():
89 global forum_index
90 global db
91 
92 try:
93 c = db.cursor()
94 msg = "SELECT * FROM forum ORDER BY forumid;"
95 c.execute(msg)
96 while (1):
97 row = c.fetchone()
98 if row == None:
99 break
100 forumid = row[0]
101 styleid = row[1]
102 title = row[2]
103 description = row[3]
104 active = row[4]
105 displayorder = row[5]
106 replycount = row[6]
107 lastpost = row[7]
108 lastposter = row[8]
109 threadcount = row[9]
110 allowposting = row[10]
111 cancontainthreads = row[11]
112 daysprune = row[12]
113 newpostemail = row[13]
114 newthreademail = row[14]
115 moderatenew = row[15]
116 moderateattach = row[16]
117 allowbbcode = row[17]
118 allowimages = row[18]
119 allowhtml = row[19]
120 allowsmilies = row[20]
121 allowicons = row[21]
122 parentid = row[22]
123 parentlist = row[23]
124 allowratings = row[24]
125 countposts = row[25]
126 styleoverride = row[26]
127 attachlimit = row[27]
128 
129 phpbb_forum_flags = 32
130 phpbb_display_on_index = 0
131 phpbb_left_id = 0
132 phpbb_right_id = 0
133 if parentid==-1:
134 parentid = 0
135 phpbb_forum_flags = 48
136 
137 forum_index[forumid] = { 'left_id': phpbb_left_id, 'right_id': phpbb_right_id, 'parent_id': parentid }
138 
139 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))
140 print ("INSERT INTO phpbb_acl_groups VALUES (5, %d, 0, 14, 0);" % (forumid))
141 except:
142 print "Error while accessing data: ", sys.exc_info()[0]
143 raise
144 
145def generateTopicInserts():
146 global forum_index
147 global db
148 
149 try:
150 c = db.cursor()
151 msg = "SELECT * FROM thread ORDER BY threadid;"
152 c.execute(msg)
153 while (1):
154 row = c.fetchone()
155 if row == None:
156 break
157 
158 threadid = row[0]
159 title = row[1]
160 lastpost = row[2]
161 forumid = row[3]
162 pollid = row[4]
163 open = row[5]
164 replycount = row[6]
165 postusername = row[7]
166 postuserid = row[8]
167 lastposter = row[9]
168 dateline = row[10]
169 views = row[11]
170 iconid = row[12]
171 notes = row[13]
172 visible = row[14]
173 sticky = row[15]
174 votenum = row[16]
175 votetotal = row[17]
176 attach = row[18]
177 karma = row[19]
178 firstpostid = row[20]
179 
180 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))
181 print ("UPDATE phpbb_forums SET forum_topics = forum_topics+1, forum_topics_real = forum_topics_real+1 WHERE forum_id=%d;" % (forumid))
182 except:
183 print "Error while accessing data: ", sys.exc_info()[0]
184 raise
185 
186def generatePostInserts():
187 global forum_index
188 global db
189 
190 
191 try:
192 c = db.cursor()
193 msg = "SELECT * FROM post ORDER BY postid;"
194 c.execute(msg)
195 while (1):
196 row = c.fetchone()
197 if row == None:
198 break
199 
200 postid = row[0]
201 threadid = row[1]
202 username = row[2]
203 userid = row[3]
204 title = row[4]
205 dateline = row[5]
206 attachmentid = row[6]
207 pagetext = row[7]
208 allowsmilie = row[8]
209 showsignature = row[9]
210 ipaddress = row[10]
211 iconid = row[11]
212 visible = row[12]
213 edituserid = row[13]
214 editdate = row[14]
215 modtype = row[15]
216 moduser = row[16]
217 
218 phpbb_bbcode_uid = make_uid(dateline)
219 phpbb_text = tpost(pagetext, phpbb_bbcode_uid)
220 
221 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))
222 print ("UPDATE phpbb_topics SET topic_replies = topic_replies+1, topic_replies_real = topic_replies_real+1 WHERE topic_id=%d;" % (threadid))
223 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))
224 except:
225 print "Error while accessing data: ", sys.exc_info()[0]
226 raise
227 
228def generateUserInserts():
229 global forum_index
230 global db
231 global USER_GROUP_ID
232 global USER_PERMISSIONS
233 
234 try:
235 c = db.cursor()
236 msg = "SELECT * FROM user ORDER BY userid;"
237 c.execute(msg)
238 while (1):
239 row = c.fetchone()
240 if row == None:
241 break
242 
243 userid = row[0]
244 usergroupid = row[1]
245 username = row[2]
246 password = row[3]
247 email = row[4]
248 styleid = row[5]
249 parentemail = row[6]
250 coppauser = row[7]
251 homepage = row[8]
252 icq = row[9]
253 aim = row[10]
254 yahoo = row[11]
255 signature = row[12]
256 adminemail = row[13]
257 showemail = row[14]
258 invisible = row[15]
259 usertitle = row[16]
260 customtitle = row[17]
261 joindate = row[18]
262 cookieuser = row[19]
263 daysprune = row[20]
264 lastvisit = row[21]
265 lastactivity = row[22]
266 lastpost = row[23]
267 posts = row[24]
268 timezoneoffset = row[25]
269 emailnotification = row[26]
270 ignorelist = row[27]
271 pmfolders = row[28]
272 receivepm = row[29]
273 emailonpm = row[30]
274 karma = row[31]
275 cangivekarma = row[32]
276 showkarma = row[33]
277 latin1 = row[34]
278 perms = row[35]
279 rooms = row[36]
280 reg_time = row[37]
281 ip = row[38]
282 mapperms = row[39]
283 buddylist = row[40]
284 avatarid = row[41]
285 inforum = row[42]
286 options = row[43]
287 birthday = row[44]
288 maxposts = row[45]
289 startofweek = row[46]
290 ipaddress = row[47]
291 referrerid = row[48]
292 pmpopup = row[49]
293 nosessionhash = row[50]
294 
295 phpbb_user_type = 2
296 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)))
297 except:
298 print "Error while accessing data: ", sys.exc_info()[0]
299 raise
300 
301db = MySQLdb.connect(DB_HOST, DB_USER, DB_PASS, DB_NAME)
302#c.execute = "SET NAMES utf-8;"
303 
304current_left_id = 1
305forum_index = dict()
306 
307generateForumInserts()
308generateBTreeUpdates()
309generateTopicInserts()
310generatePostInserts()
311generateUserInserts()
312 
313db.commit()
314db.close()
315 

Powered by WebSVN 2.2.1