forked from phpbb/phpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_convert.php
More file actions
2089 lines (1745 loc) · 61.4 KB
/
Copy pathinstall_convert.php
File metadata and controls
2089 lines (1745 loc) · 61.4 KB
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
/**
*
* @package install
* @copyright (c) 2006 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
*/
if (!defined('IN_INSTALL'))
{
// Someone has tried to access the file direct. This is not a good idea, so exit
exit;
}
if (!empty($setmodules))
{
$module[] = array(
'module_type' => 'install',
'module_title' => 'CONVERT',
'module_filename' => substr(basename(__FILE__), 0, -strlen($phpEx)-1),
'module_order' => 20,
'module_subs' => '',
'module_stages' => array('INTRO', 'SETTINGS', 'IN_PROGRESS', 'FINAL'),
'module_reqs' => ''
);
}
/**
* Class holding all convertor-specific details.
* @package install
*/
class convert
{
var $options = array();
var $convertor_tag = '';
var $src_dbms = '';
var $src_dbhost = '';
var $src_dbport = '';
var $src_dbuser = '';
var $src_dbpasswd = '';
var $src_dbname = '';
var $src_table_prefix = '';
var $convertor_data = array();
var $tables = array();
var $config_schema = array();
var $convertor = array();
var $src_truncate_statement = 'DELETE FROM ';
var $truncate_statement = 'DELETE FROM ';
var $fulltext_search;
// Batch size, can be adjusted by the conversion file
// For big boards a value of 6000 seems to be optimal
var $batch_size = 2000;
// Number of rows to be inserted at once (extended insert) if supported
// For installations having enough memory a value of 60 may be good.
var $num_wait_rows = 20;
// Mysqls internal recoding engine messing up with our (better) functions? We at least support more encodings than mysql so should use it in favor.
var $mysql_convert = false;
var $p_master;
function convert(&$p_master)
{
$this->p_master = &$p_master;
}
}
/**
* Convert class for conversions
* @package install
*/
class install_convert extends module
{
/**
* Variables used while converting, they are accessible from the global variable $convert
*/
function install_convert(&$p_master)
{
$this->p_master = &$p_master;
}
function main($mode, $sub)
{
global $lang, $template, $phpbb_root_path, $phpEx, $cache, $config, $language, $table_prefix;
global $convert;
$this->tpl_name = 'install_convert';
$this->mode = $mode;
$convert = new convert($this->p_master);
switch ($sub)
{
case 'intro':
// Try opening config file
// @todo If phpBB is not installed, we need to do a cut-down installation here
// For now, we redirect to the installation script instead
if (@file_exists($phpbb_root_path . 'config.' . $phpEx))
{
include($phpbb_root_path . 'config.' . $phpEx);
}
if (!defined('PHPBB_INSTALLED'))
{
$template->assign_vars(array(
'S_NOT_INSTALLED' => true,
'TITLE' => $lang['BOARD_NOT_INSTALLED'],
'BODY' => sprintf($lang['BOARD_NOT_INSTALLED_EXPLAIN'], append_sid($phpbb_root_path . 'install/index.' . $phpEx, 'mode=install&language=' . $language)),
));
return;
}
require($phpbb_root_path . 'config.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
$db = new $sql_db();
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
unset($dbpasswd);
// We need to fill the config to let internal functions correctly work
$config = new phpbb_config_db($db, new phpbb_cache_driver_null, CONFIG_TABLE);
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
// Detect if there is already a conversion in progress at this point and offer to resume
// It's quite possible that the user will get disconnected during a large conversion so they need to be able to resume it
$new_conversion = request_var('new_conv', 0);
if ($new_conversion)
{
$config['convert_progress'] = '';
$config['convert_db_server'] = '';
$config['convert_db_user'] = '';
$db->sql_query('DELETE FROM ' . CONFIG_TABLE . "
WHERE config_name = 'convert_progress'
OR config_name = 'convert_db_server'
OR config_name = 'convert_db_user'"
);
}
// Let's see if there is a conversion in the works...
$options = array();
if (!empty($config['convert_progress']) && !empty($config['convert_db_server']) && !empty($config['convert_db_user']) && !empty($config['convert_options']))
{
$options = unserialize($config['convert_progress']);
$options = array_merge($options, unserialize($config['convert_db_server']), unserialize($config['convert_db_user']), unserialize($config['convert_options']));
}
// This information should have already been checked once, but do it again for safety
if (!empty($options) && !empty($options['tag']) &&
isset($options['dbms']) &&
isset($options['dbhost']) &&
isset($options['dbport']) &&
isset($options['dbuser']) &&
isset($options['dbpasswd']) &&
isset($options['dbname']) &&
isset($options['table_prefix']))
{
$this->page_title = $lang['CONTINUE_CONVERT'];
$template->assign_vars(array(
'TITLE' => $lang['CONTINUE_CONVERT'],
'BODY' => $lang['CONTINUE_CONVERT_BODY'],
'L_NEW' => $lang['CONVERT_NEW_CONVERSION'],
'L_CONTINUE' => $lang['CONTINUE_OLD_CONVERSION'],
'S_CONTINUE' => true,
'U_NEW_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=intro&new_conv=1&language=$language",
'U_CONTINUE_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag={$options['tag']}{$options['step']}&language=$language",
));
return;
}
$this->list_convertors($sub);
break;
case 'settings':
$this->get_convert_settings($sub);
break;
case 'in_progress':
$this->convert_data($sub);
break;
case 'final':
$this->page_title = $lang['CONVERT_COMPLETE'];
$template->assign_vars(array(
'TITLE' => $lang['CONVERT_COMPLETE'],
'BODY' => $lang['CONVERT_COMPLETE_EXPLAIN'],
));
// If we reached this step (conversion completed) we want to purge the cache and log the user out.
// This is for making sure the session get not screwed due to the 3.0.x users table being completely new.
$cache->purge();
require($phpbb_root_path . 'config.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
$db = new $sql_db();
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
unset($dbpasswd);
$sql = 'SELECT config_value
FROM ' . CONFIG_TABLE . '
WHERE config_name = \'search_type\'';
$result = $db->sql_query($sql);
if ($db->sql_fetchfield('config_value') != 'fulltext_mysql')
{
$template->assign_vars(array(
'S_ERROR_BOX' => true,
'ERROR_TITLE' => $lang['SEARCH_INDEX_UNCONVERTED'],
'ERROR_MSG' => $lang['SEARCH_INDEX_UNCONVERTED_EXPLAIN'],
));
}
switch ($db->sql_layer)
{
case 'sqlite':
case 'firebird':
$db->sql_query('DELETE FROM ' . SESSIONS_KEYS_TABLE);
$db->sql_query('DELETE FROM ' . SESSIONS_TABLE);
break;
default:
$db->sql_query('TRUNCATE TABLE ' . SESSIONS_KEYS_TABLE);
$db->sql_query('TRUNCATE TABLE ' . SESSIONS_TABLE);
break;
}
break;
}
}
/**
* Generate a list of all available conversion modules
*/
function list_convertors($sub)
{
global $lang, $language, $template, $phpbb_root_path, $phpEx;
$this->page_title = $lang['SUB_INTRO'];
$template->assign_vars(array(
'TITLE' => $lang['CONVERT_INTRO'],
'BODY' => $lang['CONVERT_INTRO_BODY'],
'L_AUTHOR' => $lang['AUTHOR'],
'L_AVAILABLE_CONVERTORS' => $lang['AVAILABLE_CONVERTORS'],
'L_CONVERT' => $lang['CONVERT'],
'L_NO_CONVERTORS' => $lang['NO_CONVERTORS'],
'L_OPTIONS' => $lang['CONVERT_OPTIONS'],
'L_SOFTWARE' => $lang['SOFTWARE'],
'L_VERSION' => $lang['VERSION'],
'S_LIST' => true,
));
$convertors = $sort = array();
$get_info = true;
$handle = @opendir('./convertors/');
if (!$handle)
{
$this->error('Unable to access the convertors directory', __LINE__, __FILE__);
}
while ($entry = readdir($handle))
{
if (preg_match('/^convert_([a-z0-9_]+).' . $phpEx . '$/i', $entry, $m))
{
include('./convertors/' . $entry);
if (isset($convertor_data))
{
$sort[strtolower($convertor_data['forum_name'])] = sizeof($convertors);
$convertors[] = array(
'tag' => $m[1],
'forum_name' => $convertor_data['forum_name'],
'version' => $convertor_data['version'],
'dbms' => $convertor_data['dbms'],
'dbhost' => $convertor_data['dbhost'],
'dbport' => $convertor_data['dbport'],
'dbuser' => $convertor_data['dbuser'],
'dbpasswd' => $convertor_data['dbpasswd'],
'dbname' => $convertor_data['dbname'],
'table_prefix' => $convertor_data['table_prefix'],
'author' => $convertor_data['author']
);
}
unset($convertor_data);
}
}
closedir($handle);
@ksort($sort);
foreach ($sort as $void => $index)
{
$template->assign_block_vars('convertors', array(
'AUTHOR' => $convertors[$index]['author'],
'SOFTWARE' => $convertors[$index]['forum_name'],
'VERSION' => $convertors[$index]['version'],
'U_CONVERT' => $this->p_master->module_url . "?mode={$this->mode}&language=$language&sub=settings&tag=" . $convertors[$index]['tag'],
));
}
}
/**
*/
function get_convert_settings($sub)
{
global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache;
require($phpbb_root_path . 'config.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
$db = new $sql_db();
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
unset($dbpasswd);
$this->page_title = $lang['STAGE_SETTINGS'];
// We need to fill the config to let internal functions correctly work
$config = new phpbb_config_db($db, new phpbb_cache_driver_null, CONFIG_TABLE);
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
$convertor_tag = request_var('tag', '');
if (empty($convertor_tag))
{
$this->p_master->error($lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__);
}
$get_info = true;
// check security implications of direct inclusion
$convertor_tag = basename($convertor_tag);
if (!file_exists('./convertors/convert_' . $convertor_tag . '.' . $phpEx))
{
$this->p_master->error($lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__);
}
include('./convertors/convert_' . $convertor_tag . '.' . $phpEx);
// The test_file is a file that should be present in the location of the old board.
if (!isset($test_file))
{
$this->p_master->error($lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__);
}
$submit = (isset($_POST['submit'])) ? true : false;
$src_dbms = request_var('src_dbms', $convertor_data['dbms']);
$src_dbhost = request_var('src_dbhost', $convertor_data['dbhost']);
$src_dbport = request_var('src_dbport', $convertor_data['dbport']);
$src_dbuser = request_var('src_dbuser', $convertor_data['dbuser']);
$src_dbpasswd = request_var('src_dbpasswd', $convertor_data['dbpasswd']);
$src_dbname = request_var('src_dbname', $convertor_data['dbname']);
$src_table_prefix = request_var('src_table_prefix', $convertor_data['table_prefix']);
$forum_path = request_var('forum_path', $convertor_data['forum_path']);
$refresh = request_var('refresh', 1);
// Default URL of the old board
// @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it?
// -> We should convert old urls to the new relative urls format
// $src_url = request_var('src_url', 'Not in use at the moment');
// strip trailing slash from old forum path
$forum_path = (strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/') ? substr($forum_path, 0, -1) : $forum_path;
$error = array();
if ($submit)
{
if (!@file_exists('./../' . $forum_path . '/' . $test_file))
{
$error[] = sprintf($lang['COULD_NOT_FIND_PATH'], $forum_path);
}
$connect_test = false;
$available_dbms = get_available_dbms(false, true, true);
if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE'])
{
$error['db'][] = $lang['INST_ERR_NO_DB'];
$connect_test = false;
}
else
{
$connect_test = connect_check_db(true, $error, $available_dbms[$src_dbms], $src_table_prefix, $src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, true, ($src_dbms == $dbms) ? false : true, false);
}
// The forum prefix of the old and the new forum can only be the same if two different databases are used.
if ($src_table_prefix == $table_prefix && $src_dbms == $dbms && $src_dbhost == $dbhost && $src_dbport == $dbport && $src_dbname == $dbname)
{
$error[] = sprintf($lang['TABLE_PREFIX_SAME'], $src_table_prefix);
}
// Check table prefix
if (!sizeof($error))
{
// initiate database connection to old db if old and new db differ
global $src_db, $same_db;
$src_db = $same_db = false;
if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser)
{
$sql_db = 'dbal_' . $src_dbms;
$src_db = new $sql_db();
$src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true);
$same_db = false;
}
else
{
$src_db = $db;
$same_db = true;
}
$src_db->sql_return_on_error(true);
$db->sql_return_on_error(true);
// Try to select one row from the first table to see if the prefix is OK
$result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1);
if (!$result)
{
$prefixes = array();
$tables_existing = get_tables($src_db);
$tables_existing = array_map('strtolower', $tables_existing);
foreach ($tables_existing as $table_name)
{
compare_table($tables, $table_name, $prefixes);
}
unset($tables_existing);
foreach ($prefixes as $prefix => $count)
{
if ($count >= sizeof($tables))
{
$possible_prefix = $prefix;
break;
}
}
$msg = '';
if (!empty($convertor_data['table_prefix']))
{
$msg .= sprintf($lang['DEFAULT_PREFIX_IS'], $convertor_data['forum_name'], $convertor_data['table_prefix']);
}
if (!empty($possible_prefix))
{
$msg .= '<br />';
$msg .= ($possible_prefix == '*') ? $lang['BLANK_PREFIX_FOUND'] : sprintf($lang['PREFIX_FOUND'], $possible_prefix);
$src_table_prefix = ($possible_prefix == '*') ? '' : $possible_prefix;
}
$error[] = $msg;
}
$src_db->sql_freeresult($result);
$src_db->sql_return_on_error(false);
}
if (!sizeof($error))
{
// Save convertor Status
set_config('convert_progress', serialize(array(
'step' => '',
'table_prefix' => $src_table_prefix,
'tag' => $convertor_tag,
)), true);
set_config('convert_db_server', serialize(array(
'dbms' => $src_dbms,
'dbhost' => $src_dbhost,
'dbport' => $src_dbport,
'dbname' => $src_dbname,
)), true);
set_config('convert_db_user', serialize(array(
'dbuser' => $src_dbuser,
'dbpasswd' => $src_dbpasswd,
)), true);
// Save options
set_config('convert_options', serialize(array('forum_path' => './../' . $forum_path, 'refresh' => $refresh)), true);
$template->assign_block_vars('checks', array(
'TITLE' => $lang['VERIFY_OPTIONS'],
'RESULT' => $lang['CONVERT_SETTINGS_VERIFIED'],
));
$template->assign_vars(array(
'L_SUBMIT' => $lang['BEGIN_CONVERT'],
// 'S_HIDDEN' => $s_hidden_fields,
'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag=$convertor_tag&language=$language",
));
return;
}
else
{
$template->assign_block_vars('checks', array(
'TITLE' => $lang['VERIFY_OPTIONS'],
'RESULT' => '<b style="color:red">' . implode('<br />', $error) . '</b>',
));
}
} // end submit
foreach ($this->convert_options as $config_key => $vars)
{
if (!is_array($vars) && strpos($config_key, 'legend') === false)
{
continue;
}
if (strpos($config_key, 'legend') !== false)
{
$template->assign_block_vars('options', array(
'S_LEGEND' => true,
'LEGEND' => $lang[$vars])
);
continue;
}
$options = isset($vars['options']) ? $vars['options'] : '';
$template->assign_block_vars('options', array(
'KEY' => $config_key,
'TITLE' => $lang[$vars['lang']],
'S_EXPLAIN' => $vars['explain'],
'S_LEGEND' => false,
'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '',
'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $$config_key, $options),
)
);
}
$template->assign_vars(array(
'TITLE' => $lang['STAGE_SETTINGS'],
'BODY' => $lang['CONV_OPTIONS_BODY'],
'L_SUBMIT' => $lang['BEGIN_CONVERT'],
'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=settings&tag=$convertor_tag&language=$language",
));
}
/**
* The function which does the actual work (or dispatches it to the relevant places)
*/
function convert_data($sub)
{
global $template, $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache, $auth;
global $convert, $convert_row, $message_parser, $skip_rows, $language;
global $request;
require($phpbb_root_path . 'config.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/functions_convert.' . $phpEx);
$db = new $sql_db();
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true);
unset($dbpasswd);
// We need to fill the config to let internal functions correctly work
$config = new phpbb_config_db($db, new phpbb_cache_driver_null, CONFIG_TABLE);
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
// Override a couple of config variables for the duration
$config['max_quote_depth'] = 0;
// @todo Need to confirm that max post length in source is <= max post length in destination or there may be interesting formatting issues
$config['max_post_chars'] = $config['min_post_chars'] = 0;
// Set up a user as well. We _should_ have enough of a database here at this point to do this
// and it helps for any core code we call
$user->session_begin();
$user->page = $user->extract_current_page($phpbb_root_path);
// This is a little bit of a fudge, but it allows the language entries to be available to the
// core code without us loading them again
$user->lang = &$lang;
$this->page_title = $user->lang['STAGE_IN_PROGRESS'];
$convert->options = array();
if (isset($config['convert_progress']))
{
$convert->options = unserialize($config['convert_progress']);
$convert->options = array_merge($convert->options, unserialize($config['convert_db_server']), unserialize($config['convert_db_user']), unserialize($config['convert_options']));
}
// This information should have already been checked once, but do it again for safety
if (empty($convert->options) || empty($convert->options['tag']) ||
!isset($convert->options['dbms']) ||
!isset($convert->options['dbhost']) ||
!isset($convert->options['dbport']) ||
!isset($convert->options['dbuser']) ||
!isset($convert->options['dbpasswd']) ||
!isset($convert->options['dbname']) ||
!isset($convert->options['table_prefix']))
{
$this->p_master->error($user->lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__);
}
// Make some short variables accessible, for easier referencing
$convert->convertor_tag = basename($convert->options['tag']);
$convert->src_dbms = $convert->options['dbms'];
$convert->src_dbhost = $convert->options['dbhost'];
$convert->src_dbport = $convert->options['dbport'];
$convert->src_dbuser = $convert->options['dbuser'];
$convert->src_dbpasswd = $convert->options['dbpasswd'];
$convert->src_dbname = $convert->options['dbname'];
$convert->src_table_prefix = $convert->options['table_prefix'];
// initiate database connection to old db if old and new db differ
global $src_db, $same_db;
$src_db = $same_db = null;
if ($convert->src_dbms != $dbms || $convert->src_dbhost != $dbhost || $convert->src_dbport != $dbport || $convert->src_dbname != $dbname || $convert->src_dbuser != $dbuser)
{
if ($convert->src_dbms != $dbms)
{
require($phpbb_root_path . 'includes/db/' . $convert->src_dbms . '.' . $phpEx);
}
$sql_db = 'dbal_' . $convert->src_dbms;
$src_db = new $sql_db();
$src_db->sql_connect($convert->src_dbhost, $convert->src_dbuser, htmlspecialchars_decode($convert->src_dbpasswd), $convert->src_dbname, $convert->src_dbport, false, true);
$same_db = false;
}
else
{
$src_db = $db;
$same_db = true;
}
$convert->mysql_convert = false;
switch ($src_db->sql_layer)
{
case 'sqlite':
case 'firebird':
$convert->src_truncate_statement = 'DELETE FROM ';
break;
// Thanks MySQL, for silently converting...
case 'mysql':
case 'mysql4':
if (version_compare($src_db->sql_server_info(true, false), '4.1.3', '>='))
{
$convert->mysql_convert = true;
}
$convert->src_truncate_statement = 'TRUNCATE TABLE ';
break;
case 'mysqli':
$convert->mysql_convert = true;
$convert->src_truncate_statement = 'TRUNCATE TABLE ';
break;
default:
$convert->src_truncate_statement = 'TRUNCATE TABLE ';
break;
}
if ($convert->mysql_convert && !$same_db)
{
$src_db->sql_query("SET NAMES 'binary'");
}
switch ($db->sql_layer)
{
case 'sqlite':
case 'firebird':
$convert->truncate_statement = 'DELETE FROM ';
break;
default:
$convert->truncate_statement = 'TRUNCATE TABLE ';
break;
}
$get_info = false;
// check security implications of direct inclusion
if (!file_exists('./convertors/convert_' . $convert->convertor_tag . '.' . $phpEx))
{
$this->p_master->error($user->lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__);
}
if (file_exists('./convertors/functions_' . $convert->convertor_tag . '.' . $phpEx))
{
include('./convertors/functions_' . $convert->convertor_tag . '.' . $phpEx);
}
$get_info = true;
include('./convertors/convert_' . $convert->convertor_tag . '.' . $phpEx);
// Map some variables...
$convert->convertor_data = $convertor_data;
$convert->tables = $tables;
$convert->config_schema = $config_schema;
// Now include the real data
$get_info = false;
include('./convertors/convert_' . $convert->convertor_tag . '.' . $phpEx);
$convert->convertor_data = $convertor_data;
$convert->tables = $tables;
$convert->config_schema = $config_schema;
$convert->convertor = $convertor;
// The test_file is a file that should be present in the location of the old board.
if (!file_exists($convert->options['forum_path'] . '/' . $test_file))
{
$this->p_master->error(sprintf($user->lang['COULD_NOT_FIND_PATH'], $convert->options['forum_path']), __LINE__, __FILE__);
}
$search_type = $config['search_type'];
// For conversions we are a bit less strict and set to a search backend we know exist...
if (!class_exists($search_type))
{
$search_type = 'phpbb_search_fulltext_native';
set_config('search_type', $search_type);
}
if (!class_exists($search_type))
{
trigger_error('NO_SUCH_SEARCH_MODULE');
}
$error = false;
$convert->fulltext_search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
if ($error)
{
trigger_error($error);
}
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
$message_parser = new parse_message();
$jump = request_var('jump', 0);
$final_jump = request_var('final_jump', 0);
$sync_batch = request_var('sync_batch', -1);
$last_statement = request_var('last', 0);
// We are running sync...
if ($sync_batch >= 0)
{
$this->sync_forums($sync_batch);
return;
}
if ($jump)
{
$this->jump($jump, $last_statement);
return;
}
if ($final_jump)
{
$this->final_jump($final_jump);
return;
}
$current_table = request_var('current_table', 0);
$old_current_table = min(-1, $current_table - 1);
$skip_rows = request_var('skip_rows', 0);
if (!$current_table && !$skip_rows)
{
if (!$request->variable('confirm', false))
{
// If avatars / ranks / smilies folders are specified make sure they are writable
$bad_folders = array();
$local_paths = array(
'avatar_path' => path($config['avatar_path']),
'avatar_gallery_path' => path($config['avatar_gallery_path']),
'icons_path' => path($config['icons_path']),
'ranks_path' => path($config['ranks_path']),
'smilies_path' => path($config['smilies_path'])
);
foreach ($local_paths as $folder => $local_path)
{
if (isset($convert->convertor[$folder]))
{
if (empty($convert->convertor['test_file']))
{
// test_file is mandantory at the moment so this should never be reached, but just in case...
$this->p_master->error($user->lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__);
}
if (!$local_path || !phpbb_is_writable($phpbb_root_path . $local_path))
{
if (!$local_path)
{
$bad_folders[] = sprintf($user->lang['CONFIG_PHPBB_EMPTY'], $folder);
}
else
{
$bad_folders[] = $local_path;
}
}
}
}
if (sizeof($bad_folders))
{
$msg = (sizeof($bad_folders) == 1) ? $user->lang['MAKE_FOLDER_WRITABLE'] : $user->lang['MAKE_FOLDERS_WRITABLE'];
sort($bad_folders);
$this->p_master->error(sprintf($msg, implode('<br />', $bad_folders)), __LINE__, __FILE__, true);
$template->assign_vars(array(
'L_SUBMIT' => $user->lang['INSTALL_TEST'],
'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag={$convert->convertor_tag}&language=$language",
));
return;
}
// Grab all the tables used in convertor
$missing_tables = $tables_list = $aliases = array();
foreach ($convert->convertor['schema'] as $schema)
{
// Skip those not used (because of addons/plugins not detected)
if (!$schema['target'])
{
continue;
}
foreach ($schema as $key => $val)
{
// we're dealing with an array like:
// array('forum_status', 'forums.forum_status', 'is_item_locked')
if (is_int($key) && !empty($val[1]))
{
$temp_data = $val[1];
if (!is_array($temp_data))
{
$temp_data = array($temp_data);
}
foreach ($temp_data as $val)
{
if (preg_match('/([a-z0-9_]+)\.([a-z0-9_]+)\)* ?A?S? ?([a-z0-9_]*?)\.?([a-z0-9_]*)$/i', $val, $m))
{
$table = $convert->src_table_prefix . $m[1];
$tables_list[$table] = $table;
if (!empty($m[3]))
{
$aliases[] = $convert->src_table_prefix . $m[3];
}
}
}
}
// 'left_join' => 'topics LEFT JOIN vote_desc ON topics.topic_id = vote_desc.topic_id AND topics.topic_vote = 1'
else if ($key == 'left_join')
{
// Convert the value if it wasn't an array already.
if (!is_array($val))
{
$val = array($val);
}
for ($j = 0; $j < sizeof($val); ++$j)
{
if (preg_match('/LEFT JOIN ([a-z0-9_]+) AS ([a-z0-9_]+)/i', $val[$j], $m))
{
$table = $convert->src_table_prefix . $m[1];
$tables_list[$table] = $table;
if (!empty($m[2]))
{
$aliases[] = $convert->src_table_prefix . $m[2];
}
}
}
}
}
}
// Remove aliased tables from $tables_list
foreach ($aliases as $alias)
{
unset($tables_list[$alias]);
}
// Check if the tables that we need exist
$src_db->sql_return_on_error(true);
foreach ($tables_list as $table => $null)
{
$sql = 'SELECT 1 FROM ' . $table;
$_result = $src_db->sql_query_limit($sql, 1);
if (!$_result)
{
$missing_tables[] = $table;
}
$src_db->sql_freeresult($_result);
}
$src_db->sql_return_on_error(false);
// Throw an error if some tables are missing
// We used to do some guessing here, but since we have a suggestion of possible values earlier, I don't see it adding anything here to do it again
if (sizeof($missing_tables) == sizeof($tables_list))
{
$this->p_master->error($user->lang['NO_TABLES_FOUND'] . ' ' . $user->lang['CHECK_TABLE_PREFIX'], __LINE__, __FILE__);
}
else if (sizeof($missing_tables))
{
$this->p_master->error(sprintf($user->lang['TABLES_MISSING'], implode($user->lang['COMMA_SEPARATOR'], $missing_tables)) . '<br /><br />' . $user->lang['CHECK_TABLE_PREFIX'], __LINE__, __FILE__);
}
$url = $this->save_convert_progress('&confirm=1');
$msg = $user->lang['PRE_CONVERT_COMPLETE'];
if ($convert->convertor_data['author_notes'])
{
$msg .= '</p><p>' . sprintf($user->lang['AUTHOR_NOTES'], $convert->convertor_data['author_notes']);
}
$template->assign_vars(array(
'L_SUBMIT' => $user->lang['CONTINUE_CONVERT'],
'L_MESSAGE' => $msg,
'U_ACTION' => $url,
));
return;
} // if (!$request->variable('confirm', false)))
$template->assign_block_vars('checks', array(
'S_LEGEND' => true,
'LEGEND' => $user->lang['STARTING_CONVERT'],
));
// Convert the config table and load the settings of the old board
if (!empty($convert->config_schema))
{
restore_config($convert->config_schema);
// Override a couple of config variables for the duration
$config['max_quote_depth'] = 0;
// @todo Need to confirm that max post length in source is <= max post length in destination or there may be interesting formatting issues
$config['max_post_chars'] = $config['min_post_chars'] = 0;
}
$template->assign_block_vars('checks', array(
'TITLE' => $user->lang['CONFIG_CONVERT'],
'RESULT' => $user->lang['DONE'],
));
// Now process queries and execute functions that have to be executed prior to the conversion
if (!empty($convert->convertor['execute_first']))
{
eval($convert->convertor['execute_first']);
}
if (!empty($convert->convertor['query_first']))
{
if (!is_array($convert->convertor['query_first']))
{
$convert->convertor['query_first'] = array('target', array($convert->convertor['query_first']));
}
else if (!is_array($convert->convertor['query_first'][0]))
{
$convert->convertor['query_first'] = array(array($convert->convertor['query_first'][0], $convert->convertor['query_first'][1]));
}
foreach ($convert->convertor['query_first'] as $query_first)
{
if ($query_first[0] == 'src')
{
if ($convert->mysql_convert && $same_db)
{