/
VB3or4xExporter.class.php
2225 lines (2033 loc) · 70.8 KB
/
VB3or4xExporter.class.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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace wcf\system\exporter;
use wbb\data\board\Board;
use wbb\data\board\BoardCache;
use wcf\data\like\Like;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\user\group\UserGroup;
use wcf\data\user\option\UserOption;
use wcf\system\database\exception\DatabaseException;
use wcf\system\importer\ImportHandler;
use wcf\system\request\LinkHandler;
use wcf\system\Regex;
use wcf\system\WCF;
use wcf\util\ArrayUtil;
use wcf\util\DateUtil;
use wcf\util\FileUtil;
use wcf\util\MessageUtil;
use wcf\util\StringUtil;
use wcf\util\UserRegistrationUtil;
use wcf\util\UserUtil;
/**
* Exporter for vBulletin 3.8.x - vBulletin 4.2.x
*
* @author Tim Duesterhus
* @copyright 2001-2018 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf.exporter
* @subpackage system.exporter
* @category Community Framework
*/
class VB3or4xExporter extends AbstractExporter {
const FORUMOPTIONS_ACTIVE = 1;
const FORUMOPTIONS_ALLOWPOSTING = 2;
const FORUMOPTIONS_CANCONTAINTHREADS = 4;
const FORUMOPTIONS_MODERATENEWPOST = 8;
const FORUMOPTIONS_MODERATENEWTHREAD = 16;
const FORUMOPTIONS_MODERATEATTACH = 32;
const FORUMOPTIONS_ALLOWBBCODE = 64;
const FORUMOPTIONS_ALLOWIMAGES = 128;
const FORUMOPTIONS_ALLOWHTML = 256;
const FORUMOPTIONS_ALLOWSMILIES = 512;
const FORUMOPTIONS_ALLOWICONS = 1024;
const FORUMOPTIONS_ALLOWRATINGS = 2048;
const FORUMOPTIONS_COUNTPOSTS = 4096;
const FORUMOPTIONS_CANHAVEPASSWORD = 8192;
const FORUMOPTIONS_INDEXPOSTS = 16384;
const FORUMOPTIONS_STYLEOVERRIDE = 32768;
const FORUMOPTIONS_SHOWONFORUMJUMP = 65536;
const FORUMOPTIONS_PREFIXREQUIRED = 131072;
const FORUMPERMISSIONS_CANVIEW = 1;
const FORUMPERMISSIONS_CANVIEWTHREADS = 524288;
const FORUMPERMISSIONS_CANVIEWOTHERS = 2;
const FORUMPERMISSIONS_CANSEARCH = 4;
const FORUMPERMISSIONS_CANEMAIL = 8;
const FORUMPERMISSIONS_CANPOSTNEW = 16;
const FORUMPERMISSIONS_CANREPLYOWN = 32;
const FORUMPERMISSIONS_CANREPLYOTHERS = 64;
const FORUMPERMISSIONS_CANEDITPOST = 128;
const FORUMPERMISSIONS_CANDELETEPOST = 256;
const FORUMPERMISSIONS_CANDELETETHREAD = 512;
const FORUMPERMISSIONS_CANOPENCLOSE = 1024;
const FORUMPERMISSIONS_CANMOVE = 2048;
const FORUMPERMISSIONS_CANGETATTACHMENT = 4096;
const FORUMPERMISSIONS_CANPOSTATTACHMENT = 8192;
const FORUMPERMISSIONS_CANPOSTPOLL = 16384;
const FORUMPERMISSIONS_CANVOTE = 32768;
const FORUMPERMISSIONS_CANTHREADRATE = 65536;
const FORUMPERMISSIONS_FOLLOWFORUMMODERATION = 131072;
const FORUMPERMISSIONS_CANSEEDELNOTICE = 262144;
const FORUMPERMISSIONS_CANTAGOWN = 1048576;
const FORUMPERMISSIONS_CANTAGOTHERS = 2097152;
const FORUMPERMISSIONS_CANDELETETAGOWN = 4194304;
const FORUMPERMISSIONS_CANSEETHUMBNAILS = 8388608;
const ATTACHFILE_DATABASE = 0;
const ATTACHFILE_FILESYSTEM = 1;
const ATTACHFILE_FILESYSTEM_SUBFOLDER = 2;
const GALLERY_DATABASE = 'db';
const GALLERY_FILESYSTEM = 'fs';
const GALLERY_FILESYSTEM_DIRECT_THUMBS = 'fs_directthumb';
/**
* board cache
* @var array
*/
protected $boardCache = [];
/**
* @inheritDoc
*/
protected $methods = [
'com.woltlab.wcf.user' => 'Users',
'com.woltlab.wcf.user.group' => 'UserGroups',
'com.woltlab.wcf.user.rank' => 'UserRanks',
'com.woltlab.wcf.user.follower' => 'Followers',
'com.woltlab.wcf.user.comment' => 'GuestbookEntries',
'com.woltlab.wcf.user.comment.response' => 'GuestbookResponses',
'com.woltlab.wcf.user.avatar' => 'UserAvatars',
'com.woltlab.wcf.user.option' => 'UserOptions',
'com.woltlab.wcf.conversation.label' => 'ConversationFolders',
'com.woltlab.wcf.conversation' => 'Conversations',
'com.woltlab.wcf.conversation.message' => 'ConversationMessages',
'com.woltlab.wcf.conversation.user' => 'ConversationUsers',
'com.woltlab.wcf.conversation.attachment' => 'ConversationAttachments',
'com.woltlab.wbb.board' => 'Boards',
'com.woltlab.wbb.thread' => 'Threads',
'com.woltlab.wbb.post' => 'Posts',
'com.woltlab.wbb.attachment' => 'PostAttachments',
'com.woltlab.wbb.watchedThread' => 'WatchedThreads',
'com.woltlab.wbb.poll' => 'Polls',
'com.woltlab.wbb.poll.option' => 'PollOptions',
'com.woltlab.wbb.poll.option.vote' => 'PollOptionVotes',
'com.woltlab.wbb.like' => 'Likes',
'com.woltlab.wcf.label' => 'Labels',
'com.woltlab.wbb.acl' => 'ACLs',
'com.woltlab.wcf.smiley.category' => 'SmileyCategories',
'com.woltlab.wcf.smiley' => 'Smilies',
'com.woltlab.gallery.album' => 'GalleryAlbums',
'com.woltlab.gallery.image' => 'GalleryImages',
'com.woltlab.gallery.image.comment' => 'GalleryComments',
'com.woltlab.calendar.category' => 'CalendarCategories',
'com.woltlab.calendar.event' => 'CalendarEvents',
'com.woltlab.calendar.event.date' => 'CalendarEventDates',
'com.woltlab.blog.entry' => 'BlogEntries',
'com.woltlab.blog.entry.comment' => 'BlogComments',
'com.woltlab.blog.entry.attachment' => 'BlogAttachments',
];
/**
* @inheritDoc
*/
protected $limits = [
'com.woltlab.wcf.user' => 100,
'com.woltlab.wcf.user.avatar' => 100,
'com.woltlab.wcf.conversation.attachment' => 100,
'com.woltlab.wbb.thread' => 200,
'com.woltlab.wbb.attachment' => 100,
'com.woltlab.wbb.acl' => 50
];
/**
* @inheritDoc
*/
public function getSupportedData() {
return [
'com.woltlab.wcf.user' => [
'com.woltlab.wcf.user.group',
'com.woltlab.wcf.user.avatar',
'com.woltlab.wcf.user.option',
'com.woltlab.wcf.user.comment',
'com.woltlab.wcf.user.follower',
'com.woltlab.wcf.user.rank'
],
'com.woltlab.wbb.board' => [
'com.woltlab.wbb.acl',
'com.woltlab.wbb.attachment',
'com.woltlab.wbb.poll',
'com.woltlab.wbb.watchedThread',
'com.woltlab.wbb.like',
'com.woltlab.wcf.label'
],
'com.woltlab.wcf.conversation' => [
'com.woltlab.wcf.conversation.label'
],
'com.woltlab.gallery.image' => [
'com.woltlab.gallery.album',
'com.woltlab.gallery.image.comment'
],
'com.woltlab.calendar.event' => [
'com.woltlab.calendar.category'
],
'com.woltlab.blog.entry' => [
'com.woltlab.blog.entry.attachment',
'com.woltlab.blog.entry.comment'
],
'com.woltlab.wcf.smiley' => []
];
}
/**
* @inheritDoc
*/
public function validateDatabaseAccess() {
parent::validateDatabaseAccess();
$templateversion = $this->readOption('templateversion');
if (version_compare($templateversion, '3.8.0', '<')) throw new DatabaseException('Cannot import less than vB 3.8.x', $this->database);
if (version_compare($templateversion, '4.3.0 alpha 1', '>=')) throw new DatabaseException('Cannot import greater than vB 4.2.x', $this->database);
}
/**
* @inheritDoc
*/
public function validateFileAccess() {
if (in_array('com.woltlab.wcf.smiley', $this->selectedData)) {
if (empty($this->fileSystemPath) || !@file_exists($this->fileSystemPath . 'includes/version_vbulletin.php')) return false;
}
if (in_array('com.woltlab.wbb.attachment', $this->selectedData) || in_array('com.woltlab.blog.entry.attachment', $this->selectedData)) {
if ($this->readOption('attachfile') != self::ATTACHFILE_DATABASE) {
$path = $this->readOption('attachpath');
if (!StringUtil::startsWith($path, '/')) $path = realpath($this->fileSystemPath.$path);
if (!is_dir($path)) return false;
}
}
if (in_array('com.woltlab.wcf.user.avatar', $this->selectedData)) {
if ($this->readOption('usefileavatar')) {
$path = $this->readOption('avatarpath');
if (!StringUtil::startsWith($path, '/')) $path = realpath($this->fileSystemPath.$path);
if (!is_dir($path)) return false;
}
}
return true;
}
/**
* @inheritDoc
*/
public function getQueue() {
$queue = [];
// user
if (in_array('com.woltlab.wcf.user', $this->selectedData)) {
if (in_array('com.woltlab.wcf.user.group', $this->selectedData)) {
$queue[] = 'com.woltlab.wcf.user.group';
if (in_array('com.woltlab.wcf.user.rank', $this->selectedData)) $queue[] = 'com.woltlab.wcf.user.rank';
}
if (in_array('com.woltlab.wcf.user.option', $this->selectedData)) $queue[] = 'com.woltlab.wcf.user.option';
$queue[] = 'com.woltlab.wcf.user';
if (in_array('com.woltlab.wcf.user.avatar', $this->selectedData)) $queue[] = 'com.woltlab.wcf.user.avatar';
if (in_array('com.woltlab.wcf.user.comment', $this->selectedData)) {
$queue[] = 'com.woltlab.wcf.user.comment';
}
if (in_array('com.woltlab.wcf.user.follower', $this->selectedData)) $queue[] = 'com.woltlab.wcf.user.follower';
// conversation
if (in_array('com.woltlab.wcf.conversation', $this->selectedData)) {
if (in_array('com.woltlab.wcf.conversation.label', $this->selectedData)) $queue[] = 'com.woltlab.wcf.conversation.label';
$queue[] = 'com.woltlab.wcf.conversation';
$queue[] = 'com.woltlab.wcf.conversation.message';
$queue[] = 'com.woltlab.wcf.conversation.user';
}
}
// board
if (in_array('com.woltlab.wbb.board', $this->selectedData)) {
$queue[] = 'com.woltlab.wbb.board';
if (in_array('com.woltlab.wcf.label', $this->selectedData)) $queue[] = 'com.woltlab.wcf.label';
$queue[] = 'com.woltlab.wbb.thread';
$queue[] = 'com.woltlab.wbb.post';
if (in_array('com.woltlab.wbb.acl', $this->selectedData)) $queue[] = 'com.woltlab.wbb.acl';
if (in_array('com.woltlab.wbb.attachment', $this->selectedData)) $queue[] = 'com.woltlab.wbb.attachment';
if (in_array('com.woltlab.wbb.watchedThread', $this->selectedData)) $queue[] = 'com.woltlab.wbb.watchedThread';
if (in_array('com.woltlab.wbb.poll', $this->selectedData)) {
$queue[] = 'com.woltlab.wbb.poll';
$queue[] = 'com.woltlab.wbb.poll.option';
$queue[] = 'com.woltlab.wbb.poll.option.vote';
}
if (in_array('com.woltlab.wbb.like', $this->selectedData)) $queue[] = 'com.woltlab.wbb.like';
}
// smiley
if (in_array('com.woltlab.wcf.smiley', $this->selectedData)) {
$queue[] = 'com.woltlab.wcf.smiley.category';
$queue[] = 'com.woltlab.wcf.smiley';
}
// gallery
if (in_array('com.woltlab.gallery.image', $this->selectedData)) {
if (in_array('com.woltlab.gallery.album', $this->selectedData)) $queue[] = 'com.woltlab.gallery.album';
$queue[] = 'com.woltlab.gallery.image';
if (in_array('com.woltlab.gallery.image.comment', $this->selectedData)) $queue[] = 'com.woltlab.gallery.image.comment';
}
// calendar
if (in_array('com.woltlab.calendar.event', $this->selectedData)) {
if (in_array('com.woltlab.calendar.category', $this->selectedData)) $queue[] = 'com.woltlab.calendar.category';
$queue[] = 'com.woltlab.calendar.event';
}
// blog
if (in_array('com.woltlab.blog.entry', $this->selectedData)) {
$queue[] = 'com.woltlab.blog.entry';
if (in_array('com.woltlab.blog.entry.attachment', $this->selectedData)) $queue[] = 'com.woltlab.blog.entry.attachment';
if (in_array('com.woltlab.blog.entry.comment', $this->selectedData)) $queue[] = 'com.woltlab.blog.entry.comment';
}
return $queue;
}
/**
* Counts user groups.
*/
public function countUserGroups() {
$sql = "SELECT COUNT(*) AS count
FROM ".$this->databasePrefix."usergroup";
$statement = $this->database->prepareStatement($sql);
$statement->execute();
$row = $statement->fetchArray();
return $row['count'];
}
/**
* Exports user groups.
*
* @param integer $offset
* @param integer $limit
*/
public function exportUserGroups($offset, $limit) {
$sql = "SELECT *
FROM ".$this->databasePrefix."usergroup
ORDER BY usergroupid";
$statement = $this->database->prepareStatement($sql, $limit, $offset);
$statement->execute();
while ($row = $statement->fetchArray()) {
switch ($row['usergroupid']) {
case 1:
$groupType = UserGroup::GUESTS;
break;
case 2:
$groupType = UserGroup::USERS;
break;
default:
$groupType = UserGroup::OTHER;
break;
}
ImportHandler::getInstance()->getImporter('com.woltlab.wcf.user.group')->import($row['usergroupid'], [
'groupName' => $row['title'],
'groupDescription' => $row['description'],
'groupType' => $groupType,
'userOnlineMarking' => $row['opentag'].'%s'.$row['closetag']
]);
}
}
/**
* Counts users.
*/
public function countUsers() {
return $this->__getMaxID($this->databasePrefix."user", 'userid');
}
/**
* Exports users.
*
* @param integer $offset
* @param integer $limit
*/
public function exportUsers($offset, $limit) {
// cache user options
$userOptions = [];
$sql = "SELECT *
FROM ".$this->databasePrefix."profilefield";
$statement = $this->database->prepareStatement($sql);
$statement->execute();
while ($row = $statement->fetchArray()) {
if ($row['type'] == 'select_multiple' || $row['type'] == 'checkbox') {
$row['data'] = @unserialize($row['data']);
}
$userOptions[] = $row;
}
// prepare password update
$sql = "UPDATE wcf".WCF_N."_user
SET password = ?
WHERE userID = ?";
$passwordUpdateStatement = WCF::getDB()->prepareStatement($sql);
// get users
$sql = "SELECT userfield.*, user_table.*, textfield.*, useractivation.type AS activationType, useractivation.emailchange, userban.liftdate, userban.reason AS banReason
FROM ".$this->databasePrefix."user user_table
LEFT JOIN ".$this->databasePrefix."usertextfield textfield
ON user_table.userid = textfield.userid
LEFT JOIN ".$this->databasePrefix."useractivation useractivation
ON user_table.userid = useractivation.userid
LEFT JOIN ".$this->databasePrefix."userban userban
ON user_table.userid = userban.userid
LEFT JOIN ".$this->databasePrefix."userfield userfield
ON userfield.userid = user_table.userid
WHERE user_table.userid BETWEEN ? AND ?
ORDER BY user_table.userid";
$statement = $this->database->prepareStatement($sql);
$statement->execute([$offset + 1, $offset + $limit]);
while ($row = $statement->fetchArray()) {
$data = [
'username' => StringUtil::decodeHTML($row['username']),
'password' => '',
'email' => StringUtil::decodeHTML($row['email']),
'registrationDate' => $row['joindate'],
'banned' => $row['liftdate'] !== null && $row['liftdate'] == 0 ? 1 : 0,
'banReason' => StringUtil::decodeHTML($row['banReason']),
'activationCode' => $row['activationType'] !== null && $row['activationType'] == 0 && $row['emailchange'] == 0 ? UserRegistrationUtil::getActivationCode() : 0, // vB's codes are strings
'oldUsername' => '',
'registrationIpAddress' => UserUtil::convertIPv4To6($row['ipaddress']), // TODO: check whether this is the registration IP
'signature' => self::fixBBCodes($row['signature']),
'userTitle' => ($row['customtitle'] != 0) ? StringUtil::decodeHTML($row['usertitle']) : '',
'lastActivityTime' => $row['lastactivity']
];
$options = [];
if ($row['birthday']) {
$options['birthday'] = self::convertBirthday($row['birthday']);
}
$additionalData = [
'groupIDs' => explode(',', $row['membergroupids'].','.$row['usergroupid']),
'options' => $options
];
// handle user options
foreach ($userOptions as $userOption) {
$optionID = $userOption['profilefieldid'];
if (isset($row['field'.$optionID])) {
$userOptionValue = $row['field'.$optionID];
if ($userOptionValue && ($userOption['type'] == 'select_multiple' || $userOption['type'] == 'checkbox')) {
if (is_array($userOption['data'])) {
$newUserOptionValue = '';
foreach ($userOption['data'] as $key => $value) {
if ($userOptionValue & pow(2, $key)) {
if (!empty($newUserOptionValue)) $newUserOptionValue .= "\n";
$newUserOptionValue .= $value;
}
}
$userOptionValue = $newUserOptionValue;
}
}
$additionalData['options'][$optionID] = $userOptionValue;
}
}
// import user
$newUserID = ImportHandler::getInstance()->getImporter('com.woltlab.wcf.user')->import($row['userid'], $data, $additionalData);
// update password hash
if ($newUserID) {
$passwordUpdateStatement->execute(['vb3:'.$row['password'].':'.$row['salt'], $newUserID]);
}
}
}
/**
* Counts user ranks.
*/
public function countUserRanks() {
$sql = "SELECT
(
SELECT COUNT(*)
FROM ".$this->databasePrefix."usertitle
)
+
(
SELECT COUNT(*)
FROM ".$this->databasePrefix."usergroup
WHERE usergroupid NOT IN(?, ?)
AND usertitle <> ?
) AS count";
$statement = $this->database->prepareStatement($sql);
$statement->execute([1, 2, '']);
$row = $statement->fetchArray();
return $row['count'];
}
/**
* Exports user ranks.
*
* @param integer $offset
* @param integer $limit
*/
public function exportUserRanks($offset, $limit) {
$sql = "(
SELECT usertitleid, 2 AS groupID, minposts, title
FROM ".$this->databasePrefix."usertitle
)
UNION
(
SELECT ('g-' || usergroupid) AS usertitleid, usergroupid AS groupID, 0 AS minposts, usertitle AS title
FROM ".$this->databasePrefix."usergroup
WHERE usergroupid NOT IN(?, ?)
AND usertitle <> ?
)
ORDER BY usertitleid";
$statement = $this->database->prepareStatement($sql, $limit, $offset);
$statement->execute([1, 2, '']);
while ($row = $statement->fetchArray()) {
ImportHandler::getInstance()->getImporter('com.woltlab.wcf.user.rank')->import($row['usertitleid'], [
'groupID' => $row['groupID'],
'requiredPoints' => $row['minposts'] * 5,
'rankTitle' => StringUtil::decodeHTML($row['title'])
]);
}
}
/**
* Counts followers.
*/
public function countFollowers() {
$sql = "SELECT COUNT(*) AS count
FROM ".$this->databasePrefix."usertextfield
WHERE buddylist <> ?";
$statement = $this->database->prepareStatement($sql);
$statement->execute(['']);
$row = $statement->fetchArray();
return $row['count'];
}
/**
* Exports followers.
*
* @param integer $offset
* @param integer $limit
*/
public function exportFollowers($offset, $limit) {
$sql = "SELECT userid, buddylist
FROM ".$this->databasePrefix."usertextfield
WHERE buddylist <> ?
ORDER BY userid";
$statement = $this->database->prepareStatement($sql, $limit, $offset);
$statement->execute(['']);
while ($row = $statement->fetchArray()) {
$buddies = array_unique(ArrayUtil::toIntegerArray(explode(' ', $row['buddylist'])));
foreach ($buddies as $buddy) {
ImportHandler::getInstance()->getImporter('com.woltlab.wcf.user.follower')->import(0, [
'userID' => $row['userid'],
'followUserID' => $buddy
]);
}
}
}
/**
* Counts guestbook entries.
*/
public function countGuestbookEntries() {
return $this->__getMaxID($this->databasePrefix."visitormessage", 'vmid');
}
/**
* Exports guestbook entries.
*
* @param integer $offset
* @param integer $limit
*/
public function exportGuestbookEntries($offset, $limit) {
$sql = "SELECT *
FROM ".$this->databasePrefix."visitormessage
WHERE vmid BETWEEN ? AND ?
ORDER BY vmid";
$statement = $this->database->prepareStatement($sql);
$statement->execute([$offset + 1, $offset + $limit]);
while ($row = $statement->fetchArray()) {
ImportHandler::getInstance()->getImporter('com.woltlab.wcf.user.comment')->import($row['vmid'], [
'objectID' => $row['userid'],
'userID' => $row['postuserid'],
'username' => StringUtil::decodeHTML($row['postusername']),
'message' => StringUtil::decodeHTML($row['pagetext']),
'time' => $row['dateline']
]);
}
}
/**
* Counts user avatars.
*/
public function countUserAvatars() {
$sql = "SELECT COUNT(*) AS count
FROM ".$this->databasePrefix."customavatar";
$statement = $this->database->prepareStatement($sql);
$statement->execute();
$row = $statement->fetchArray();
return $row['count'];
}
/**
* Exports user avatars.
*
* @param integer $offset
* @param integer $limit
* @throws \Exception
*/
public function exportUserAvatars($offset, $limit) {
$sql = "SELECT customavatar.*, user.avatarrevision
FROM ".$this->databasePrefix."customavatar customavatar
LEFT JOIN ".$this->databasePrefix."user user
ON user.userid = customavatar.userid
ORDER BY customavatar.userid";
$statement = $this->database->prepareStatement($sql, $limit, $offset);
$statement->execute();
while ($row = $statement->fetchArray()) {
$file = null;
try {
if ($this->readOption('usefileavatar')) {
$file = $this->readOption('avatarpath');
if (!StringUtil::startsWith($file, '/')) $file = realpath($this->fileSystemPath.$file);
$file = FileUtil::addTrailingSlash($file).'avatar'.$row['userid'].'_'.$row['avatarrevision'].'.gif';
}
else {
$file = FileUtil::getTemporaryFilename('avatar_');
file_put_contents($file, $row['filedata']);
}
ImportHandler::getInstance()->getImporter('com.woltlab.wcf.user.avatar')->import($row['userid'], [
'avatarName' => StringUtil::decodeHTML($row['filename']),
'avatarExtension' => pathinfo($row['filename'], PATHINFO_EXTENSION),
'width' => $row['width'],
'height' => $row['height'],
'userID' => $row['userid']
], ['fileLocation' => $file]);
if (!$this->readOption('usefileavatar')) unlink($file);
}
catch (\Exception $e) {
if (!$this->readOption('usefileavatar') && $file) @unlink($file);
throw $e;
}
}
}
/**
* Counts user options.
*/
public function countUserOptions() {
$sql = "SELECT COUNT(*) AS count
FROM ".$this->databasePrefix."profilefield";
$statement = $this->database->prepareStatement($sql);
$statement->execute();
$row = $statement->fetchArray();
return ($row['count'] ? 1 : 0);
}
/**
* Exports user options.
*
* @param integer $offset
* @param integer $limit
*/
public function exportUserOptions(/** @noinspection PhpUnusedParameterInspection */$offset, $limit) {
$sql = "SELECT *
FROM ".$this->databasePrefix."profilefield";
$statement = $this->database->prepareStatement($sql);
$statement->execute();
while ($row = $statement->fetchArray()) {
$editable = 0;
switch ($row['editable']) {
case 0:
$editable = UserOption::EDITABILITY_ADMINISTRATOR;
break;
case 1:
case 2:
$editable = UserOption::EDITABILITY_ALL;
break;
}
$visible = UserOption::VISIBILITY_ALL;
if ($row['hidden']) {
$visible = UserOption::VISIBILITY_ADMINISTRATOR;
}
// get select options
$selectOptions = [];
if ($row['type'] == 'radio' || $row['type'] == 'select' || $row['type'] == 'select_multiple' || $row['type'] == 'checkbox') {
$selectOptions = @unserialize($row['data']);
if (!is_array($selectOptions)) {
$selectOptions = @unserialize(mb_convert_encoding($row['data'], 'ISO-8859-1', 'UTF-8'));
if (!is_array($selectOptions)) continue;
$selectOptions = array_map(function ($item) {
return mb_convert_encoding($item, 'UTF-8', 'ISO-8859-1');
}, $selectOptions);
}
}
// get option type
$optionType = 'text';
switch ($row['type']) {
case 'textarea':
$optionType = 'textarea';
break;
case 'radio':
$optionType = 'radioButton';
break;
case 'select':
$optionType = 'select';
break;
case 'select_multiple':
case 'checkbox':
$optionType = 'multiSelect';
break;
}
// get default value
$defaultValue = '';
switch ($row['type']) {
case 'input':
case 'textarea':
$defaultValue = $row['data'];
break;
case 'radio':
case 'select':
if ($row['def']) {
// use first radio option
$defaultValue = reset($selectOptions);
}
break;
}
// get required status
$required = $askDuringRegistration = 0;
switch ($row['required']) {
case 1:
case 3:
$required = 1;
break;
case 2:
$askDuringRegistration = 1;
break;
}
// get field name
$fieldName = 'field'.$row['profilefieldid'];
$sql = "SELECT text
FROM ".$this->databasePrefix."phrase
WHERE languageid = ?
AND varname = ?";
$statement2 = $this->database->prepareStatement($sql);
$statement2->execute([0, 'field'.$row['profilefieldid'].'_title']);
$row2 = $statement2->fetchArray();
if ($row2 !== false) {
$fieldName = $row2['text'];
}
ImportHandler::getInstance()->getImporter('com.woltlab.wcf.user.option')->import($row['profilefieldid'], [
'categoryName' => 'profile.personal',
'optionType' => $optionType,
'defaultValue' => $defaultValue,
'validationPattern' => $row['regex'],
'selectOptions' => implode("\n", $selectOptions),
'required' => $required,
'askDuringRegistration' => $askDuringRegistration,
'searchable' => $row['searchable'],
'editable' => $editable,
'visible' => $visible,
'showOrder' => $row['displayorder']
], ['name' => $fieldName]);
}
}
/**
* Counts conversation folders.
*/
public function countConversationFolders() {
$sql = "SELECT COUNT(*) AS count
FROM ".$this->databasePrefix."usertextfield
WHERE pmfolders IS NOT NULL
AND pmfolders <> ?";
$statement = $this->database->prepareStatement($sql);
$statement->execute(['']);
$row = $statement->fetchArray();
return $row['count'];
}
/**
* Exports conversation folders.
*
* @param integer $offset
* @param integer $limit
*/
public function exportConversationFolders($offset, $limit) {
$sql = "SELECT userid, pmfolders
FROM ".$this->databasePrefix."usertextfield
WHERE pmfolders IS NOT NULL
AND pmfolders <> ?
ORDER BY userid";
$statement = $this->database->prepareStatement($sql, $limit, $offset);
$statement->execute(['']);
while ($row = $statement->fetchArray()) {
$convert = false;
// vBulletin relies on undefined behaviour by default, we cannot know in which
// encoding the data was saved
$pmfolders = @unserialize($row['pmfolders']);
if (!is_array($pmfolders)) {
// try to convert it to the most common encoding
$convert = true;
$pmfolders = @unserialize(mb_convert_encoding($row['pmfolders'], 'ISO-8859-1', 'UTF-8'));
// still unparseable
if (!is_array($pmfolders)) continue;
}
foreach ($pmfolders as $key => $val) {
// convert back to utf-8
if ($convert) $val = mb_convert_encoding($val, 'UTF-8', 'ISO-8859-1');
ImportHandler::getInstance()->getImporter('com.woltlab.wcf.conversation.label')->import($row['userid'].'-'.$key, [
'userID' => $row['userid'],
'label' => mb_substr($val, 0, 80)
]);
}
}
}
/**
* Creates a conversation id out of the old parentpmid and the participants.
*
* This ensures that only the actual receivers of a pm are able to see it
* after import, while minimizing the number of conversations.
*
* @param integer $parentpmid
* @param integer[] $participants
* @return string
*/
private function getConversationID($parentpmid, array $participants) {
$conversationID = $parentpmid;
$participants = array_unique($participants);
sort($participants);
$conversationID .= '-'.implode(',', $participants);
return StringUtil::getHash($conversationID);
}
/**
* Counts conversations.
*/
public function countConversations() {
return $this->__getMaxID($this->databasePrefix."pm", 'pmid');
}
/**
* Exports conversations.
*
* @param integer $offset
* @param integer $limit
*/
public function exportConversations($offset, $limit) {
$sql = "SELECT pm.*, text.*,
(
SELECT GROUP_CONCAT(pm2.userid)
FROM ".$this->databasePrefix."pm pm2
WHERE pm.pmtextid = pm2.pmtextid
) AS participants
FROM ".$this->databasePrefix."pm pm
INNER JOIN ".$this->databasePrefix."pmtext text
ON pm.pmtextid = text.pmtextid
WHERE pm.pmid BETWEEN ? AND ?
ORDER BY pm.pmid";
$statement = $this->database->prepareStatement($sql);
$statement->execute([$offset + 1, $offset + $limit]);
while ($row = $statement->fetchArray()) {
$participants = explode(',', $row['participants']);
$participants[] = $row['fromuserid'];
$conversationID = $this->getConversationID($row['parentpmid'] ?: $row['pmid'], $participants);
if (ImportHandler::getInstance()->getNewID('com.woltlab.wcf.conversation', $conversationID) !== null) continue;
ImportHandler::getInstance()->getImporter('com.woltlab.wcf.conversation')->import($conversationID, [
'subject' => StringUtil::decodeHTML($row['title']),
'time' => $row['dateline'],
'userID' => $row['fromuserid'],
'username' => StringUtil::decodeHTML($row['fromusername']),
'isDraft' => 0
]);
}
}
/**
* Counts conversation messages.
*/
public function countConversationMessages() {
return $this->__getMaxID($this->databasePrefix."pmtext", 'pmtextid');
}
/**
* Exports conversation messages.
*
* @param integer $offset
* @param integer $limit
*/
public function exportConversationMessages($offset, $limit) {
$sql = "SELECT pmtext.*,
(
".$this->database->handleLimitParameter("SELECT IF(pm.parentpmid = 0, pm.pmid, pm.parentpmid) FROM ".$this->databasePrefix."pm pm WHERE pmtext.pmtextid = pm.pmtextid", 1)."
) AS conversationID,
(
SELECT GROUP_CONCAT(pm.userid)
FROM ".$this->databasePrefix."pm pm
WHERE pmtext.pmtextid = pm.pmtextid
) AS participants
FROM ".$this->databasePrefix."pmtext pmtext
WHERE pmtext.pmtextid BETWEEN ? AND ?
ORDER BY pmtext.pmtextid";
$statement = $this->database->prepareStatement($sql);
$statement->execute([$offset + 1, $offset + $limit]);
while ($row = $statement->fetchArray()) {
$participants = explode(',', $row['participants']);
$participants[] = $row['fromuserid'];
$conversationID = $this->getConversationID($row['conversationID'], $participants);
ImportHandler::getInstance()->getImporter('com.woltlab.wcf.conversation.message')->import($row['pmtextid'], [
'conversationID' => $conversationID,
'userID' => $row['fromuserid'],
'username' => StringUtil::decodeHTML($row['fromusername']),
'message' => self::fixBBCodes($row['message']),
'time' => $row['dateline']
]);
}
}
/**
* Counts conversation recipients.
*/
public function countConversationUsers() {
$sql = "SELECT COUNT(*) AS count
FROM ".$this->databasePrefix."pm";
$statement = $this->database->prepareStatement($sql);
$statement->execute();
$row = $statement->fetchArray();
return $row['count'];
}
/**
* Exports conversation recipients.
*
* @param integer $offset
* @param integer $limit
*/
public function exportConversationUsers($offset, $limit) {
$sql = "SELECT pm.*, user.username, pmtext.touserarray, pmtext.dateline, pmtext.fromuserid,
(
SELECT GROUP_CONCAT(pm2.userid)
FROM ".$this->databasePrefix."pm pm2
WHERE pm.pmtextid = pm2.pmtextid
) AS participants
FROM ".$this->databasePrefix."pm pm
INNER JOIN ".$this->databasePrefix."user user
ON pm.userid = user.userid
INNER JOIN ".$this->databasePrefix."pmtext pmtext
ON pmtext.pmtextid = pm.pmtextid
ORDER BY pm.pmid";
$statement = $this->database->prepareStatement($sql, $limit, $offset);
$statement->execute();
while ($row = $statement->fetchArray()) {
$participants = explode(',', $row['participants']);
$participants[] = $row['fromuserid'];
$conversationID = $this->getConversationID($row['parentpmid'] ?: $row['pmid'], $participants);
// vBulletin relies on undefined behaviour by default, we cannot know in which
// encoding the data was saved
// this may cause some hidden participants to become visible
$recipients = @unserialize($row['touserarray']);
if (!is_array($recipients)) $recipients = [];
ImportHandler::getInstance()->getImporter('com.woltlab.wcf.conversation.user')->import(0, [
'conversationID' => $conversationID,
'participantID' => $row['userid'],
'username' => StringUtil::decodeHTML($row['username'] ?: ''),
'hideConversation' => 0, // there is no trash
'isInvisible' => (isset($recipients['bcc']) && isset($recipients['bcc'][$row['userid']])) ? 1 : 0,
'lastVisitTime' => $row['messageread'] ? $row['dateline'] : 0
], ['labelIDs' => ($row['folderid'] > 0) ? [$row['userid'].'-'.$row['folderid']] : []]);
}
}
/**
* Counts boards.
*/
public function countBoards() {
$sql = "SELECT COUNT(*) AS count
FROM ".$this->databasePrefix."forum";
$statement = $this->database->prepareStatement($sql);
$statement->execute();
$row = $statement->fetchArray();
return ($row['count'] ? 1 : 0);
}
/**
* Exports boards.
*
* @param integer $offset
* @param integer $limit
*/
public function exportBoards(/** @noinspection PhpUnusedParameterInspection */$offset, $limit) {