-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBMove.php
228 lines (211 loc) · 6.59 KB
/
DBMove.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?
// Dedicated for babot.net old version.
//
// This version is for testing. Not for actual migration
//
$DROP = 'YES';
require("DBSchema.php");
$oldDB = 'homepage';
$newDB = 'apfsds';
$IP = 'localhost';
$ID = 'homepage';
$PWD= 'bhdmzx53';
$DEBUG = false;
DBClose();
DBConnect();
function newDB()
{
DBClose();
debug("Close DB");
$link = mysql_connect($GLOBALS['IP'], $GLOBALS['ID'], $GLOBALS['PWD']) or die ("Cannot connect DB");
debug("Switch to newDB");
mysql_select_db($GLOBALS['newDB'], $link) or die("Cannot Select ".$GLOBALS['newDB']);
$GLOBALS['_link'] = $link;
$GLOBALS['db_conn'] = true;
return $link;
}
function oldDB()
{
DBClose();
debug("Close DB");
$link = mysql_connect($GLOBALS['IP'], $GLOBALS['ID'], $GLOBALS['PWD']) or die ("Cannot connect DB");
debug("Switch to oldDB(".$GLOBALS['oldDB'].")");
mysql_select_db($GLOBALS['oldDB'], $link) or die("Cannot Select ".$GLOBALS['oldDB']);
$GLOBALS['_link'] = $link;
$GLOBALS['db_conn'] = true;
return $link;
}
// migrate USERS, BBS, BBS_ARTICLE, BBS_CONTENT, BBS_COMMENT into the new DB
oldDB();
$rs = DBQ("select * from USERS");
newDB();
while ($r = mysql_fetch_assoc($rs))
{
DBQ("INSERT INTO USERS VALUES('".sqlSafe($r['id'])."', '".sqlSafe($r['password'])."', ".
$r['permission'].", ".$r['level'].", ".
$r['experience'].",".$r['money'].", ".
"'".sqlSafe($r['playingas'])."', '".sqlSafe($r['realname'])."', null, ".
$r['sex'].", '".sqlSafe($r['birth'])."', '".sqlSafe($r['telephone'])."', ".
"'".sqlSafe($r['cellular'])."', '".sqlSafe($r['address'])."', ".
"'".sqlSafe($r['job'])."', '".sqlSafe($r['email'])."', '".sqlSafe($r['comment'])."', ".
"null , '".sqlSafe($r['lastlogdate'])."', '".sqlSafe($r['lastlogip'])."', ".
"'".sqlSafe($r['undefined'])."')");
}
mysql_free_result($rs);
oldDB();
$rs = DBQ("select * from BBS");
// dealt as a tag. moves into 'default' Blog
newDB();
while ($r = mysql_fetch_assoc($rs))
{
if (substr($r['id'],0,2)=='NN')
continue;
if ($r['id']=='guestbook')
continue;
DBQ("INSERT INTO BlogTag values(".
"'default', null, ".
"'".sqlSafe($r['id'])."', ".
"0, ".
"0, ".
$r['permission_read'].", ".
$r['permission_write'].")");
}
mysql_free_result($rs);
oldDB();
$rs = DBQ("select * from BBS_ARTICLE order by id ASC");
while ($r = mysql_fetch_assoc($rs))
{
if (substr($r['bbs_id'],0,2)=='NN')
continue;
if ($r['bbs_id']=='guestbook')
continue;
$rs2 = DBQ("select content from BBS_CONTENT where bbs_id='".$r['bbs_id']."' ".
"and id=".$r['id']." order by sequence ASC");
$content = '';
while ($r2 = mysql_fetch_row($rs2))
$content=$content.$r2[0];
// print "<HR>".html2text($content)."<HR>".html2text(sqlSafe($content))."<HR>";
mysql_free_result($rs2);
newDB();
$rs3 = DBQ("select tagID from BlogTag where tagTitle='".$r['bbs_id']."'");
$rtag = mysql_fetch_row($rs3);
$tagID = $rtag[0];
mysql_free_result($rs3);
DBQ("INSERT INTO BlogArticle values(".
"'default', ".
$r['id'].", ".
(($r['thread']!=null)?$r['thread']:"null").", ".
"'".sqlSafe($r['title'])."', ".
(($r['writer']!=null)?"'".sqlSafe($r['writer'])."', ":"null, ").
(($r['guestinfo']!=null)?"'".sqlSafe($r['guestinfo'])."', ":"null, ").
"'', '', ".
(($r['guestpassword']!=null)?"'".sqlSafe($r['guestpassword'])."', ":"null, ").
"'".sqlSafe($r['createon'])."', ".
(($r['modified']!=null)?"'".sqlSafe($r['modified'])."', ":"null, ").
"'".sqlSafe($r['ip'])."', ".
$r['html'].", ".
$r['hit'].", ".
(($r['filename']!=null)?"1, ":"0, ").
"0, ".
"'".sqlSafe($content)."', null, null, null, 0)");
if ($r['filename']!=null)
DBQ("INSERT INTO BlogArticleAttached values (".
"'default', ".
$r['id'].", ".
"0, ".
"'".sqlSafe($r['filename'])."', ".
"'".sqlSafe($r['filemime'])."')");
DBQ("INSERT INTO BlogTagArticleAssoc values (".
"'default', ".
"$tagID, ".
$r['id'].")");
oldDB();
$rsc = DBQ("select * from BBS_COMMENT where bbs_id='".$r['bbs_id']."'and ".
"id = ".$r['id']." order by sequence ASC");
newDB();
$commentContent='';
$lastWriter=''; $lastGuestInfo=''; $lastCreateOn=''; $lastIP='';
while ($rc = mysql_fetch_assoc($rsc))
{
if ($commentContent!='' && $rc['continued']==0)
{
DBQ("INSERT INTO BlogComment values (".
"'default', ".
$r['id'].", ".
"null, ".
"null, ".
(($lastWriter!=null)?
("'".sqlSafe($lastWriter)."', null, null, null, null, "):
("null, '".sqlSafe($lastGuestInfo)."', '', '', '', ")
).
"'".sqlSafe($lastIP)."', ".
"'".sqlSafe($lastCreateOn)."', ".
"null, ".
"'".sqlSafe($commentContent)."', ".
"0)");
$commentContent='';
}
$commentContent=$commentContent.$rc['content'];
$lastWriter=$rc['writer']; $lastGuestInfo=$rc['guestinfo'];
$lastCreateOn=$rc['createon']; $lastIP=$rc['ip'];
}
if ($commentContent!='')
DBQ("INSERT INTO BlogComment values (".
"'default', ".
$r['id'].", ".
"null, ".
"null, ".
(($lastWriter!=null)?
("'".sqlSafe($lastWriter)."', null, null, null, null, "):
("null, '".sqlSafe($lastGuestInfo)."', '', '', '', ")
).
"'".sqlSafe($lastIP)."', ".
"'".sqlSafe($lastCreateOn)."', ".
"null, ".
"'".sqlSafe($commentContent)."', ".
"0)");
mysql_free_result($rsc);
oldDB();
}
mysql_free_result($rs);
$DEBUG = true;
oldDB();
$rs = DBQ("select * from STATUS");
newDB();
while ($r = mysql_fetch_row($rs))
DBQ("INSERT INTO STATUS values (".($r[0]+1).")");
mysql_free_result($rs);
oldDB();
$rs = DBQ("select * from STATUS_DEF");
newDB();
while ($r = mysql_fetch_assoc($rs))
DBQ("INSERT INTO STATUS_DEF values (".
(($r['id']+0)+1).',\''.sqlSafe($r['description']).'\',\''.sqlSafe($r['icon']).'\')');
mysql_free_result($rs);
oldDB();
$rs = DBQ("select * from MEMO order by createon");
newDB();
while ($r=mysql_fetch_assoc($rs))
DBQ("INSERT INTO MEMO values (".
$r['id'].', null, \''.sqlSafe($r['content']).'\', \''.sqlSafe($r['ip']).'\',\''.sqlSafe($r['createon']).'\')');
mysql_free_result($rs);
oldDB();
$rs = DBQ("select * from IPSTAT");
newDB();
while ($r=mysql_fetch_row($rs))
DBQ("INSERT INTO IPSTAT values ('".sqlSafe($r[0])."','".sqlSafe($r[1])."','".sqlSafe($r[2])."','".sqlSafe($r[3])."','".sqlSafe($r[4])."','".sqlSafe($r[5]).
"','".sqlSafe($r[6])."',".$r[7].",".$r[8].",".$r[9].",".$r[10].",".$r[11].",'".sqlSafe($r[12])."')");
mysql_free_result($rs);
oldDB();
$rs = DBQ("select * from COUNTER");
newDB();
while ($r=mysql_fetch_row($rs))
DBQ("INSERT INTO COUNTER values ('".sqlSafe($r[0])."',".$r[1].",'".sqlSafe($r[2])."')");
mysql_free_result($rs);
oldDB();
$rs = DBQ("select * from ORACLE");
newDB();
while ($r=mysql_fetch_row($rs))
DBQ("INSERT INTO ORACLE values (null, '".sqlSafe($r[0])."','".sqlSafe($r[1])."','".sqlSafe($r[2])."', ".$r[3].")");
mysql_free_result($rs);
?>