-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathImpExDatabase_350.php
579 lines (538 loc) · 23.8 KB
/
ImpExDatabase_350.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
<?php
/*======================================================================*\
|| ####################################################################
|| # vBulletin Impex
|| # ----------------------------------------------------------------
|| # All PHP code in this file is Copyright 2000-2014 vBulletin Solutions Inc.
|| # This code is made available under the Modified BSD License -- see license.txt
|| # http://www.vbulletin.com
|| ####################################################################
\*======================================================================*/
/**
* The database proxy object.
*
* This handles interaction with the different types of database.
*
* @package ImpEx
*
*/
if (!class_exists('ImpExDatabaseCore')) { die('Direct class access violation'); }
class ImpExDatabase extends ImpExDatabaseCore
{
/**
* Class version
*
* This will allow the checking for inter-operability of class version in different
* versions of ImpEx
*
* @var string
*/
var $_version = '0.0.1';
var $_customernumber = '[#]customernumber[#]';
/**
* Constructor
*
* Empty
*
*/
function ImpExDatabase()
{
}
// Overridden to maintain salt and password details
function import_vb3_user(&$Db_object, &$databasetype, &$tableprefix)
{
switch ($databasetype)
{
// MySQL database
case 'mysql':
{
// TODO: Still need to check and see if all the current usersnames being imported are unique
if(strtolower($this->get_value('mandatory', 'username')) == 'admin')
{
$this->set_value('mandatory', 'username', 'admin_old');
}
// Auto email associate
if ($this->_auto_email_associate)
{
// Do a search for the email address to find the user to match this imported one to :
$email_match = $Db_object->query_first("SELECT userid FROM " . $tableprefix . "user WHERE email='". addslashes($this->get_value('mandatory', 'email')) . "'");
if ($email_match)
{
if($this->associate_user($Db_object, $databasetype, $tableprefix, $this->get_value('mandatory', 'importuserid'), $email_match["userid"]))
{
// We matched the email address and associated propperly
$result['automerge'] = true;
$result['userid'] = $email_match["userid"];
return $result;
}
else
{
// Hmmm found the email but didn't associate !!
}
}
else
{
// There is no email to match with, so return nothing and let the user import normally.
}
}
// Auto userid associate
if ($this->_auto_userid_associate)
{
// Do a search for the email address to find the user to match this imported one to :
$userid_match = $Db_object->query_first("SELECT userid FROM {$tableprefix}userid WHERE userid=". intval($this->get_value('mandatory', 'importuserid')));
if ($userid_match)
{
if($this->associate_user($Db_object, $databasetype, $tableprefix, $this->get_value('mandatory', 'importuserid'), $userid_match["userid"]))
{
// We matched the email address and associated propperly
$result['automerge'] = true;
$result['userid'] = $userid_match["userid"];
return $result;
}
else
{
// Hmmm found the email but didn't associate !!
return 0;
}
}
else
{
// There is no email to match with, so return nothing and let the user import normally.
}
}
// If there is a dupe username pre_pend "imported_"
$double_name = $Db_object->query("SELECT username FROM " . $tableprefix . "user WHERE username='". addslashes($this->get_value('mandatory', 'username')) . "'");
if($Db_object->num_rows($double_name))
{
$this->set_value('mandatory', 'username', 'imported_' . $this->get_value('mandatory', 'username'));
}
$sql = "
INSERT INTO " . $tableprefix . "user
(
username, email, usergroupid,
importuserid, password, salt,
passworddate, options, homepage,
posts, joindate, icq,
daysprune, aim, membergroupids,
displaygroupid, styleid, parentemail,
yahoo, showvbcode, usertitle,
customtitle, lastvisit, lastactivity,
lastpost, reputation, reputationlevelid,
timezoneoffset, pmpopup, avatarid,
avatarrevision, birthday, birthday_search, maxposts,
startofweek, ipaddress, referrerid,
languageid, msn, emailstamp,
threadedmode, pmtotal, pmunread,
autosubscribe, profilepicrevision
)
VALUES
(
'" . addslashes($this->get_value('mandatory', 'username')) . "',
'" . addslashes($this->get_value('mandatory', 'email')) . "',
'" . $this->get_value('mandatory', 'usergroupid') . "',
'" . $this->get_value('mandatory', 'importuserid') . "',
'" . addslashes($this->get_value('nonmandatory', 'password')) . "',
'" . addslashes($this->get_value('nonmandatory', 'salt')) . "',
'" . $this->get_value('nonmandatory', 'passworddate') . "',
'" . $this->get_value('nonmandatory', 'options') . "',
'" . addslashes($this->get_value('nonmandatory', 'homepage')) . "',
'" . $this->get_value('nonmandatory', 'posts') . "',
'" . $this->get_value('nonmandatory', 'joindate') . "',
'" . addslashes($this->get_value('nonmandatory', 'icq')) . "',
'" . $this->get_value('nonmandatory', 'daysprune') . "',
'" . addslashes($this->get_value('nonmandatory', 'aim')) . "',
'" . $this->get_value('nonmandatory', 'membergroupids') . "',
'" . $this->get_value('nonmandatory', 'displaygroupid') . "',
'" . $this->get_value('nonmandatory', 'styleid') . "',
'" . addslashes($this->get_value('nonmandatory', 'parentemail')) . "',
'" . addslashes($this->get_value('nonmandatory', 'yahoo')) . "',
'" . $this->get_value('nonmandatory', 'showvbcode') . "',
'" . addslashes($this->get_value('nonmandatory', 'usertitle')) . "',
'" . addslashes($this->get_value('nonmandatory', 'customtitle')) . "',
'" . $this->get_value('nonmandatory', 'lastvisit') . "',
'" . $this->get_value('nonmandatory', 'lastactivity') . "',
'" . $this->get_value('nonmandatory', 'lastpost') . "',
'" . $this->get_value('nonmandatory', 'reputation') . "',
'" . $this->get_value('nonmandatory', 'reputationlevelid') . "',
'" . $this->get_value('nonmandatory', 'timezoneoffset') . "',
'" . $this->get_value('nonmandatory', 'pmpopup') . "',
'" . $this->get_value('nonmandatory', 'avatarid') . "',
'" . $this->get_value('nonmandatory', 'avatarrevision') . "',
'" . $this->get_value('nonmandatory', 'birthday') . "',
'" . $this->get_value('nonmandatory', 'birthday_search') . "',
'" . $this->get_value('nonmandatory', 'maxposts') . "',
'" . $this->get_value('nonmandatory', 'startofweek') . "',
'" . $this->get_value('nonmandatory', 'ipaddress') . "',
'" . $this->get_value('nonmandatory', 'referrerid') . "',
'" . $this->get_value('nonmandatory', 'languageid') . "',
'" . addslashes($this->get_value('nonmandatory', 'msn')) . "',
'" . $this->get_value('nonmandatory', 'emailstamp') . "',
'" . $this->get_value('nonmandatory', 'threadedmode') . "',
'" . $this->get_value('nonmandatory', 'pmtotal') . "',
'" . $this->get_value('nonmandatory', 'pmunread') . "',
'" . $this->get_value('nonmandatory', 'autosubscribe') . "',
'" . $this->get_value('nonmandatory', 'profilepicrevision') . "'
)
";
$userdone = $Db_object->query($sql);
$userid = $Db_object->insert_id();
if ($userdone)
{
$exists = $Db_object->query_first("SELECT userid FROM " . $tableprefix . "usertextfield WHERE userid = $userid");
if (!$exists)
{
if (!$Db_object->query("INSERT INTO " . $tableprefix . "usertextfield (userid) VALUES ($userid)"))
{
$this->_failedon = "usertextfield fill";
return false;
}
if (!$Db_object->query("INSERT INTO " . $tableprefix . "userfield (userid) VALUES ($userid)"))
{
$this->_failedon = "userfield fill";
return false;
}
}
if ($this->_has_default_values)
{
foreach ($this->get_default_values() as $key => $value)
{
if ($key != 'signature')
{
if (!$this->import_user_field_value($Db_object, $databasetype, $tableprefix, $key, $value, $userid))
{
$this->_failedon = "import_user_field_value - $key - $value - $userid";
return false;
}
}
}
}
if (array_key_exists('signature',$this->_default_values))
{
if (!$Db_object->query("UPDATE " . $tableprefix . "usertextfield SET signature='" . addslashes($this->_default_values['signature']) . "' WHERE userid='" . $userid ."'"))
{
$this->_failedon = "usertextfield SET signature";
return false;
}
}
}
else
{
return false;
}
return $userid;
}
// Postgres database
case 'postgresql':
{
return false;
}
// other
default:
{
return false;
}
}
}
function zuul($dana){ return "There are nospoon importers only zuul"; }
function import_forum(&$Db_object, &$databasetype, &$tableprefix)
{
switch ($databasetype)
{
// MySQL database
case 'mysql':
{
// Catch the legacy importers that haven't been
// updated
if (!$this->get_value('mandatory', 'options'))
{
$this->set_value('mandatory', 'options', $this->_default_forum_permissions);
}
$result = $Db_object->query("
INSERT INTO " . $tableprefix . "forum
(
styleid, title, options,
displayorder, parentid, importforumid,
importcategoryid, description, replycount,
lastpost, lastposter, lastthread,
lastthreadid, lasticonid, threadcount,
daysprune, newpostemail, newthreademail,
parentlist, password, link, childlist,
title_clean, description_clean
)
VALUES
(
'" . $this->get_value('mandatory', 'styleid') . "',
'" . addslashes($this->get_value('mandatory', 'title')) . "',
" . $this->get_value('mandatory', 'options') . ",
'" . $this->get_value('mandatory', 'displayorder') . "',
'" . $this->get_value('mandatory', 'parentid') . "',
'" . $this->get_value('mandatory', 'importforumid') . "',
'" . $this->get_value('mandatory', 'importcategoryid') . "',
'" . addslashes($this->get_value('nonmandatory', 'description')) . "',
'" . $this->get_value('nonmandatory', 'replycount') . "',
'" . $this->get_value('nonmandatory', 'lastpost') . "',
'" . addslashes($this->get_value('nonmandatory', 'lastposter')) . "',
'" . $this->get_value('nonmandatory', 'lastthread') . "',
'" . $this->get_value('nonmandatory', 'lastthreadid') . "',
'" . $this->get_value('nonmandatory', 'lasticonid') . "',
'" . $this->get_value('nonmandatory', 'threadcount') . "',
'" . $this->get_value('nonmandatory', 'daysprune') . "',
'" . $this->get_value('nonmandatory', 'newpostemail') . "',
'" . $this->get_value('nonmandatory', 'newthreademail') . "',
'" . $this->get_value('nonmandatory', 'parentlist') . "',
'" . $this->get_value('nonmandatory', 'password') . "',
'" . $this->get_value('nonmandatory', 'link') . "',
'" . $this->get_value('nonmandatory', 'childlist') . "',
'" . addslashes($this->get_value('mandatory', 'title')) . "',
'" . addslashes($this->get_value('nonmandatory', 'description')) . "'
)
");
$forumid = $Db_object->insert_id($result);
if ($result)
{
$Db_object->query("UPDATE {$tableprefix}forum SET parentlist='$forumid,-1' WHERE forumid='$forumid'");
if ($Db_object->affected_rows())
{
return $forumid;
}
else
{
return false;
}
}
else
{
return false;
}
}
// Postgres database
case 'postgresql':
{
return false;
}
// other
default:
{
return false;
}
}
}
function import_thread(&$Db_object, &$databasetype, &$tableprefix)
{
switch ($databasetype)
{
// MySQL database
case 'mysql':
{
$Db_object->query("
INSERT INTO " . $tableprefix . "thread
(
forumid, title, importforumid,
importthreadid, firstpostid, lastpost,
pollid, open, replycount,
postusername, postuserid, lastposter,
dateline, views, iconid,
notes, visible, sticky,
votenum, votetotal, attach, similar,
hiddencount
)
VALUES
(
'" . $this->get_value('mandatory', 'forumid') . "',
'" . addslashes($this->get_value('mandatory', 'title')) . "',
'" . $this->get_value('mandatory', 'importforumid') . "',
'" . $this->get_value('mandatory', 'importthreadid') . "',
'" . $this->get_value('nonmandatory', 'firstpostid') . "',
'" . addslashes($this->get_value('nonmandatory', 'lastpost')) . "',
'" . $this->get_value('nonmandatory', 'pollid') . "',
'" . $this->get_value('nonmandatory', 'open') . "',
'" . $this->get_value('nonmandatory', 'replycount') . "',
'" . addslashes($this->get_value('nonmandatory', 'postusername')) . "',
'" . $this->get_value('nonmandatory', 'postuserid') . "',
'" . addslashes($this->get_value('nonmandatory', 'lastposter')) . "',
'" . $this->get_value('nonmandatory', 'dateline') . "',
'" . $this->get_value('nonmandatory', 'views') . "',
'" . $this->get_value('nonmandatory', 'iconid') . "',
'" . addslashes($this->get_value('nonmandatory', 'notes')) . "',
'" . $this->get_value('nonmandatory', 'visible') . "',
'" . $this->get_value('nonmandatory', 'sticky') . "',
'" . $this->get_value('nonmandatory', 'votenum') . "',
'" . $this->get_value('nonmandatory', 'votetotal') . "',
'" . addslashes($this->get_value('nonmandatory', 'attach')) . "',
'" . addslashes($this->get_value('nonmandatory', 'similar')) . "',
'" . $this->get_value('nonmandatory', 'hiddencount') . "'
)
");
if ($Db_object->affected_rows())
{
return $Db_object->insert_id();
}
else
{
return false;
}
}
// Postgres database
case 'postgresql':
{
return false;
}
// other
default:
{
return false;
}
}
}
/**
* Imports a usergroup
*
* @param object databaseobject The database that the function is going to interact with.
* @param string mixed The type of database 'mysql', 'postgresql', etc
* @param string mixed The prefix to the table name i.e. 'vb3_'
*
* @return insert_id
*/
function import_user_group(&$Db_object, &$databasetype, &$tableprefix)
{
switch ($databasetype)
{
case 'mysql':
{
$Db_object->query("
INSERT INTO " . $tableprefix . "usergroup
(
importusergroupid, title, description,
usertitle, passwordexpires, passwordhistory,
pmquota, pmsendmax,
opentag, closetag, canoverride,
ispublicgroup, forumpermissions, pmpermissions,
calendarpermissions, wolpermissions, adminpermissions,
genericpermissions, genericoptions, attachlimit,
avatarmaxwidth, avatarmaxheight, avatarmaxsize,
profilepicmaxwidth, profilepicmaxheight, profilepicmaxsize
)
VALUES
(
'" . $this->get_value('mandatory', 'importusergroupid') . "',
'" . addslashes($this->get_value('nonmandatory','title')) . "',
'" . addslashes($this->get_value('nonmandatory','description')) . "',
'" . addslashes($this->get_value('nonmandatory','usertitle')) . "',
'" . $this->get_value('nonmandatory','passwordexpires') . "',
'" . $this->get_value('nonmandatory','passwordhistory') . "',
'" . $this->get_value('nonmandatory','pmquota') . "',
'" . $this->get_value('nonmandatory','pmsendmax') . "',
'" . addslashes($this->get_value('nonmandatory','opentag')) . "',
'" . addslashes($this->get_value('nonmandatory','closetag')) . "',
'" . $this->get_value('nonmandatory','canoverride') . "',
'" . $this->get_value('nonmandatory','ispublicgroup') . "',
'" . $this->get_value('nonmandatory','forumpermissions') . "',
'" . $this->get_value('nonmandatory','pmpermissions') . "',
'" . $this->get_value('nonmandatory','calendarpermissions') . "',
'" . $this->get_value('nonmandatory','wolpermissions') . "',
'" . $this->get_value('nonmandatory','adminpermissions') . "',
'" . $this->get_value('nonmandatory','genericpermissions') . "',
'" . $this->get_value('nonmandatory','genericoptions') . "',
'" . $this->get_value('nonmandatory','attachlimit') . "',
'" . $this->get_value('nonmandatory','avatarmaxwidth') . "',
'" . $this->get_value('nonmandatory','avatarmaxheight') . "',
'" . $this->get_value('nonmandatory','avatarmaxsize') . "',
'" . $this->get_value('nonmandatory','profilepicmaxwidth') . "',
'" . $this->get_value('nonmandatory','profilepicmaxheight') . "',
'" . $this->get_value('nonmandatory','profilepicmaxsize') . "'
)
");
if ($Db_object->affected_rows())
{
return $Db_object->insert_id();
}
else
{
return false;
}
}
// Postgres database
case 'postgresql':
{
return false;
}
// other
default:
{
return false;
}
}
}
function import_usergroup(&$Db_object, &$databasetype, &$tableprefix)
{
switch ($databasetype)
{
case 'mysql':
{
$Db_object->query("
INSERT INTO " . $tableprefix . "usergroup
(
importusergroupid, title, description,
usertitle, passwordexpires, passwordhistory,
pmquota, pmsendmax,
opentag, closetag, canoverride,
ispublicgroup, forumpermissions, pmpermissions,
calendarpermissions, wolpermissions, adminpermissions,
genericpermissions, genericoptions, attachlimit,
avatarmaxwidth, avatarmaxheight, avatarmaxsize,
profilepicmaxwidth, profilepicmaxheight, profilepicmaxsize
)
VALUES
(
'" . $this->get_value('mandatory', 'importusergroupid') . "',
'" . addslashes($this->get_value('nonmandatory','title')) . "',
'" . addslashes($this->get_value('nonmandatory','description')) . "',
'" . addslashes($this->get_value('nonmandatory','usertitle')) . "',
'" . $this->get_value('nonmandatory','passwordexpires') . "',
'" . $this->get_value('nonmandatory','passwordhistory') . "',
'" . $this->get_value('nonmandatory','pmquota') . "',
'" . $this->get_value('nonmandatory','pmsendmax') . "',
'" . addslashes($this->get_value('nonmandatory','opentag')) . "',
'" . addslashes($this->get_value('nonmandatory','closetag')) . "',
'" . $this->get_value('nonmandatory','canoverride') . "',
'" . $this->get_value('nonmandatory','ispublicgroup') . "',
'" . $this->get_value('nonmandatory','forumpermissions') . "',
'" . $this->get_value('nonmandatory','pmpermissions') . "',
'" . $this->get_value('nonmandatory','calendarpermissions') . "',
'" . $this->get_value('nonmandatory','wolpermissions') . "',
'" . $this->get_value('nonmandatory','adminpermissions') . "',
'" . $this->get_value('nonmandatory','genericpermissions') . "',
'" . $this->get_value('nonmandatory','genericoptions') . "',
'" . $this->get_value('nonmandatory','attachlimit') . "',
'" . $this->get_value('nonmandatory','avatarmaxwidth') . "',
'" . $this->get_value('nonmandatory','avatarmaxheight') . "',
'" . $this->get_value('nonmandatory','avatarmaxsize') . "',
'" . $this->get_value('nonmandatory','profilepicmaxwidth') . "',
'" . $this->get_value('nonmandatory','profilepicmaxheight') . "',
'" . $this->get_value('nonmandatory','profilepicmaxsize') . "'
)
");
if ($Db_object->affected_rows())
{
return $Db_object->insert_id();
}
else
{
return false;
}
}
// Postgres database
case 'postgresql':
{
return false;
}
// other
default:
{
return false;
}
}
}
}
/*======================================================================*/
?>