/
database_update.php
3481 lines (2949 loc) · 96.8 KB
/
database_update.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
/**
*
* @package install
* @version $Id$
* @copyright (c) 2006 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
$updates_to_version = '3.0.7-dev';
// Enter any version to update from to test updates. The version within the db will not be updated.
$debug_from_version = false;
// Which oldest version does this updater support?
$oldest_from_version = '3.0.0';
// Return if we "just include it" to find out for which version the database update is responsible for
if (defined('IN_PHPBB') && defined('IN_INSTALL'))
{
return;
}
/**
*/
define('IN_PHPBB', true);
define('IN_INSTALL', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
// Report all errors, except notices and deprecation messages
if (!defined('E_DEPRECATED'))
{
define('E_DEPRECATED', 8192);
}
//error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
error_reporting(E_ALL);
@set_time_limit(0);
// Include essential scripts
include($phpbb_root_path . 'config.' . $phpEx);
if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
{
die("Please read: <a href='../docs/INSTALL.html'>INSTALL.html</a> before attempting to update.");
}
// Load Extensions
if (!empty($load_extensions) && function_exists('dl'))
{
$load_extensions = explode(',', $load_extensions);
foreach ($load_extensions as $extension)
{
@dl(trim($extension));
}
}
// Include files
require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
require($phpbb_root_path . 'includes/cache.' . $phpEx);
require($phpbb_root_path . 'includes/template.' . $phpEx);
require($phpbb_root_path . 'includes/session.' . $phpEx);
require($phpbb_root_path . 'includes/auth.' . $phpEx);
require($phpbb_root_path . 'includes/functions.' . $phpEx);
if (file_exists($phpbb_root_path . 'includes/functions_content.' . $phpEx))
{
require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
}
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
require($phpbb_root_path . 'includes/constants.' . $phpEx);
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
// If we are on PHP >= 6.0.0 we do not need some code
if (version_compare(PHP_VERSION, '6.0.0-dev', '>='))
{
/**
* @ignore
*/
define('STRIP', false);
}
else
{
@set_magic_quotes_runtime(0);
define('STRIP', (get_magic_quotes_gpc()) ? true : false);
}
$user = new user();
$cache = new cache();
$db = new $sql_db();
// Add own hook handler, if present. :o
if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))
{
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
foreach ($cache->obtain_hooks() as $hook)
{
@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
}
}
else
{
$phpbb_hook = false;
}
// Connect to DB
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
// We do not need this any longer, unset for safety purposes
unset($dbpasswd);
$user->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
$sql = "SELECT config_value
FROM " . CONFIG_TABLE . "
WHERE config_name = 'default_lang'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$language = basename(request_var('language', ''));
if (!$language)
{
$language = $row['config_value'];
}
if (!file_exists($phpbb_root_path . 'language/' . $language))
{
die('No language found!');
}
// And finally, load the relevant language files
include($phpbb_root_path . 'language/' . $language . '/common.' . $phpEx);
include($phpbb_root_path . 'language/' . $language . '/acp/common.' . $phpEx);
include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
// Set PHP error handler to ours
//set_error_handler('msg_handler');
// Define some variables for the database update
$inline_update = (request_var('type', 0)) ? true : false;
// To let set_config() calls succeed, we need to make the config array available globally
$config = array();
$sql = 'SELECT *
FROM ' . CONFIG_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$config[$row['config_name']] = $row['config_value'];
}
$db->sql_freeresult($result);
// We do not include DB Tools here, because we can not be sure the file is up-to-date ;)
// Instead, this file defines a clean db_tools version (we are also not able to provide a different file, else the database update will not work standalone)
$db_tools = new updater_db_tools($db, true);
$database_update_info = database_update_info();
$error_ary = array();
$errored = false;
header('Content-type: text/html; charset=UTF-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $lang['DIRECTION']; ?>" lang="<?php echo $lang['USER_LANG']; ?>" xml:lang="<?php echo $lang['USER_LANG']; ?>">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-language" content="<?php echo $lang['USER_LANG']; ?>" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="imagetoolbar" content="no" />
<title><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></title>
<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrap">
<div id="page-header"> </div>
<div id="page-body">
<div id="acp">
<div class="panel">
<span class="corners-top"><span></span></span>
<div id="content">
<div id="main" class="install-body">
<h1><?php echo $lang['UPDATING_TO_LATEST_STABLE']; ?></h1>
<br />
<p><?php echo $lang['DATABASE_TYPE']; ?> :: <strong><?php echo $db->sql_layer; ?></strong><br />
<?php
if ($debug_from_version !== false)
{
$config['version'] = $debug_from_version;
}
echo $lang['PREVIOUS_VERSION'] . ' :: <strong>' . $config['version'] . '</strong><br />';
echo $lang['UPDATED_VERSION'] . ' :: <strong>' . $updates_to_version . '</strong></p>';
$current_version = str_replace('rc', 'RC', strtolower($config['version']));
$latest_version = str_replace('rc', 'RC', strtolower($updates_to_version));
$orig_version = $config['version'];
// Fill DB version
if (empty($config['dbms_version']))
{
set_config('dbms_version', $db->sql_server_info(true));
}
// Firebird update from Firebord 2.0 to 2.1+ required?
if ($db->sql_layer == 'firebird')
{
// We do not trust any PHP5 function enabled, we will simply test for a function new in 2.1
$db->sql_return_on_error(true);
$sql = 'SELECT 1 FROM RDB$DATABASE
WHERE BIN_AND(10, 1) = 0';
$result = $db->sql_query($sql);
if (!$result || $db->sql_error_triggered)
{
echo '<br /><br />';
echo '<h1>' . $lang['ERROR'] . '</h1><br />';
echo '<p>' . $lang['FIREBIRD_DBMS_UPDATE_REQUIRED'] . '</p>';
_print_footer();
exit_handler();
exit;
}
$db->sql_freeresult($result);
$db->sql_return_on_error(false);
}
// MySQL update from MySQL 3.x/4.x to > 4.1.x required?
if ($db->sql_layer == 'mysql' || $db->sql_layer == 'mysql4' || $db->sql_layer == 'mysqli')
{
// Verify by fetching column... if the column type matches the new type we update dbms_version...
$sql = "SHOW COLUMNS FROM " . CONFIG_TABLE;
$result = $db->sql_query($sql);
$column_type = '';
while ($row = $db->sql_fetchrow($result))
{
$field = strtolower($row['Field']);
if ($field == 'config_value')
{
$column_type = strtolower($row['Type']);
break;
}
}
$db->sql_freeresult($result);
// If column type is blob, but mysql version says we are on > 4.1.3, then the schema needs an update
if (strpos($column_type, 'blob') !== false && version_compare($db->sql_server_info(true), '4.1.3', '>='))
{
echo '<br /><br />';
echo '<h1>' . $lang['ERROR'] . '</h1><br />';
echo '<p>' . sprintf($lang['MYSQL_SCHEMA_UPDATE_REQUIRED'], $config['dbms_version'], $db->sql_server_info(true)) . '</p>';
_print_footer();
exit_handler();
exit;
}
}
// Now check if the user wants to update from a version we no longer support updates from
if (version_compare($current_version, $oldest_from_version, '<'))
{
echo '<br /><br /><h1>' . $lang['ERROR'] . '</h1><br />';
echo '<p>' . sprintf($lang['DB_UPDATE_NOT_SUPPORTED'], $oldest_from_version, $current_version) . '</p>';
_print_footer();
exit_handler();
exit;
}
// If the latest version and the current version are 'unequal', we will update the version_update_from, else we do not update anything.
if ($inline_update)
{
if ($current_version !== $latest_version)
{
set_config('version_update_from', $orig_version);
}
}
else
{
// If not called from the update script, we will actually remove the traces
$db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'");
}
// Schema updates
?>
<br /><br />
<h1><?php echo $lang['UPDATE_DATABASE_SCHEMA']; ?></h1>
<br />
<p><?php echo $lang['PROGRESS']; ?> :: <strong>
<?php
flush();
// We go through the schema changes from the lowest to the highest version
// We try to also include versions 'in-between'...
$no_updates = true;
$versions = array_keys($database_update_info);
for ($i = 0; $i < sizeof($versions); $i++)
{
$version = $versions[$i];
$schema_changes = $database_update_info[$version];
$next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
// If the installed version to be updated to is < than the current version, and if the current version is >= as the version to be updated to next, we will skip the process
if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
{
continue;
}
if (!sizeof($schema_changes))
{
continue;
}
$no_updates = false;
// We run one index after the other... to be consistent with schema changes...
foreach ($schema_changes as $key => $changes)
{
$statements = $db_tools->perform_schema_changes(array($key => $changes));
foreach ($statements as $sql)
{
_sql($sql, $errored, $error_ary);
}
}
}
_write_result($no_updates, $errored, $error_ary);
// Data updates
$error_ary = array();
$errored = $no_updates = false;
?>
<br /><br />
<h1><?php echo $lang['UPDATING_DATA']; ?></h1>
<br />
<p><?php echo $lang['PROGRESS']; ?> :: <strong>
<?php
flush();
$no_updates = true;
$versions = array_keys($database_update_info);
// some code magic
for ($i = 0; $i < sizeof($versions); $i++)
{
$version = $versions[$i];
$next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
// If the installed version to be updated to is < than the current version, and if the current version is >= as the version to be updated to next, we will skip the process
if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
{
continue;
}
change_database_data($no_updates, $version);
}
_write_result($no_updates, $errored, $error_ary);
$error_ary = array();
$errored = $no_updates = false;
?>
<br /><br />
<h1><?php echo $lang['UPDATE_VERSION_OPTIMIZE']; ?></h1>
<br />
<p><?php echo $lang['PROGRESS']; ?> :: <strong>
<?php
flush();
if ($debug_from_version === false)
{
// update the version
$sql = "UPDATE " . CONFIG_TABLE . "
SET config_value = '$updates_to_version'
WHERE config_name = 'version'";
_sql($sql, $errored, $error_ary);
}
// Reset permissions
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_permissions = '',
user_perm_from = 0";
_sql($sql, $errored, $error_ary);
// Update the dbms version if everything is ok...
set_config('dbms_version', $db->sql_server_info(true));
/* Optimize/vacuum analyze the tables where appropriate
// this should be done for each version in future along with
// the version number update
switch ($db->sql_layer)
{
case 'mysql':
case 'mysqli':
case 'mysql4':
$sql = 'OPTIMIZE TABLE ' . $table_prefix . 'auth_access, ' . $table_prefix . 'banlist, ' . $table_prefix . 'categories, ' . $table_prefix . 'config, ' . $table_prefix . 'disallow, ' . $table_prefix . 'forum_prune, ' . $table_prefix . 'forums, ' . $table_prefix . 'groups, ' . $table_prefix . 'posts, ' . $table_prefix . 'posts_text, ' . $table_prefix . 'privmsgs, ' . $table_prefix . 'privmsgs_text, ' . $table_prefix . 'ranks, ' . $table_prefix . 'search_results, ' . $table_prefix . 'search_wordlist, ' . $table_prefix . 'search_wordmatch, ' . $table_prefix . 'sessions_keys' . $table_prefix . 'smilies, ' . $table_prefix . 'themes, ' . $table_prefix . 'themes_name, ' . $table_prefix . 'topics, ' . $table_prefix . 'topics_watch, ' . $table_prefix . 'user_group, ' . $table_prefix . 'users, ' . $table_prefix . 'vote_desc, ' . $table_prefix . 'vote_results, ' . $table_prefix . 'vote_voters, ' . $table_prefix . 'words';
_sql($sql, $errored, $error_ary);
break;
case 'postgresql':
_sql("VACUUM ANALYZE", $errored, $error_ary);
break;
}
*/
_write_result($no_updates, $errored, $error_ary);
?>
<br />
<h1><?php echo $lang['UPDATE_COMPLETED']; ?></h1>
<br />
<?php
if (!$inline_update)
{
?>
<p style="color:red"><?php echo $lang['UPDATE_FILES_NOTICE']; ?></p>
<p><?php echo $lang['COMPLETE_LOGIN_TO_BOARD']; ?></p>
<?php
}
else
{
?>
<p><?php echo ((isset($lang['INLINE_UPDATE_SUCCESSFUL'])) ? $lang['INLINE_UPDATE_SUCCESSFUL'] : 'The database update was successful. Now you need to continue the update process.'); ?></p>
<p><a href="<?php echo append_sid("{$phpbb_root_path}install/index.{$phpEx}", "mode=update&sub=file_check&lang=$language"); ?>" class="button1"><?php echo (isset($lang['CONTINUE_UPDATE_NOW'])) ? $lang['CONTINUE_UPDATE_NOW'] : 'Continue the update process now'; ?></a></p>
<?php
}
// Add database update to log
add_log('admin', 'LOG_UPDATE_DATABASE', $orig_version, $updates_to_version);
// Now we purge the session table as well as all cache files
$cache->purge();
_print_footer();
garbage_collection();
if (function_exists('exit_handler'))
{
exit_handler();
}
/**
* Print out footer
*/
function _print_footer()
{
echo <<<EOF
</div>
</div>
<span class="corners-bottom"><span></span></span>
</div>
</div>
</div>
<div id="page-footer">
Powered by phpBB © 2000, 2002, 2005, 2007 <a href="http://www.phpbb.com/">phpBB Group</a>
</div>
</div>
</body>
</html>
EOF;
}
/**
* Function for triggering an sql statement
*/
function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
{
global $db;
if (defined('DEBUG_EXTRA'))
{
echo "<br />\n{$sql}\n<br />";
}
$db->sql_return_on_error(true);
$result = $db->sql_query($sql);
if ($db->sql_error_triggered)
{
$errored = true;
$error_ary['sql'][] = $db->sql_error_sql;
$error_ary['error_code'][] = $db->sql_error_returned;
}
$db->sql_return_on_error(false);
if ($echo_dot)
{
echo ". \n";
flush();
}
return $result;
}
function _write_result($no_updates, $errored, $error_ary)
{
global $lang;
if ($no_updates)
{
echo ' ' . $lang['NO_UPDATES_REQUIRED'] . '</strong></p>';
}
else
{
echo ' <span class="success">' . $lang['DONE'] . '</span></strong><br />' . $lang['RESULT'] . ' :: ';
if ($errored)
{
echo ' <strong>' . $lang['SOME_QUERIES_FAILED'] . '</strong> <ul>';
for ($i = 0; $i < sizeof($error_ary['sql']); $i++)
{
echo '<li>' . $lang['ERROR'] . ' :: <strong>' . htmlspecialchars($error_ary['error_code'][$i]['message']) . '</strong><br />';
echo $lang['SQL'] . ' :: <strong>' . htmlspecialchars($error_ary['sql'][$i]) . '</strong><br /><br /></li>';
}
echo '</ul> <br /><br />' . $lang['SQL_FAILURE_EXPLAIN'] . '</p>';
}
else
{
echo '<strong>' . $lang['NO_ERRORS'] . '</strong></p>';
}
}
}
function _add_modules($modules_to_install)
{
global $phpbb_root_path, $phpEx, $db;
include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx);
$_module = new acp_modules();
foreach ($modules_to_install as $module_mode => $module_data)
{
$_module->module_class = $module_data['class'];
// Determine parent id first
$sql = 'SELECT module_id
FROM ' . MODULES_TABLE . "
WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
AND module_langname = '" . $db->sql_escape($module_data['cat']) . "'
AND module_mode = ''
AND module_basename = ''";
$result = $db->sql_query($sql);
// There may be more than one categories with the same name
$categories = array();
while ($row = $db->sql_fetchrow($result))
{
$categories[] = (int) $row['module_id'];
}
$db->sql_freeresult($result);
if (!sizeof($categories))
{
continue;
}
// Add the module to all categories found
foreach ($categories as $parent_id)
{
// Check if the module already exists
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_basename = '" . $db->sql_escape($module_data['base']) . "'
AND module_class = '" . $db->sql_escape($module_data['class']) . "'
AND module_langname = '" . $db->sql_escape($module_data['title']) . "'
AND module_mode = '" . $db->sql_escape($module_mode) . "'
AND module_auth = '" . $db->sql_escape($module_data['auth']) . "'
AND parent_id = {$parent_id}";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// If it exists, we simply continue with the next category
if ($row)
{
continue;
}
// Build the module sql row
$module_row = array(
'module_basename' => $module_data['base'],
'module_enabled' => (isset($module_data['enabled'])) ? (int) $module_data['enabled'] : 1,
'module_display' => (isset($module_data['display'])) ? (int) $module_data['display'] : 1,
'parent_id' => $parent_id,
'module_class' => $module_data['class'],
'module_langname' => $module_data['title'],
'module_mode' => $module_mode,
'module_auth' => $module_data['auth'],
);
$_module->update_module_data($module_row, true);
// Ok, do we need to re-order the module, move it up or down?
if (!isset($module_data['after']))
{
continue;
}
$after_mode = $module_data['after'][0];
$after_langname = $module_data['after'][1];
// First of all, get the module id for the module this one has to be placed after
$sql = 'SELECT left_id
FROM ' . MODULES_TABLE . "
WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
AND module_basename = '" . $db->sql_escape($module_data['base']) . "'
AND module_langname = '" . $db->sql_escape($after_langname) . "'
AND module_mode = '" . $db->sql_escape($after_mode) . "'
AND parent_id = '{$parent_id}'";
$result = $db->sql_query($sql);
$first_left_id = (int) $db->sql_fetchfield('left_id');
$db->sql_freeresult($result);
if (!$first_left_id)
{
continue;
}
// Ok, count the number of modules between $after_mode and the added module
$sql = 'SELECT COUNT(module_id) as num_modules
FROM ' . MODULES_TABLE . "
WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'
AND parent_id = {$parent_id}
AND left_id BETWEEN {$first_left_id} AND {$module_row['left_id']}
GROUP BY left_id
ORDER BY left_id";
$result = $db->sql_query($sql);
$steps = (int) $db->sql_fetchfield('num_modules');
$db->sql_freeresult($result);
// We need to substract 2
$steps -= 2;
if ($steps <= 0)
{
continue;
}
// Ok, move module up $num_modules times. ;)
$_module->move_module_by($module_row, 'move_up', $steps);
}
}
$_module->remove_cache_file();
}
/****************************************************************************
* ADD YOUR DATABASE SCHEMA CHANGES HERE *
*****************************************************************************/
function database_update_info()
{
return array(
// Changes from 3.0.0 to the next version
'3.0.0' => array(
// Add the following columns
'add_columns' => array(
FORUMS_TABLE => array(
'display_subforum_list' => array('BOOL', 1),
),
SESSIONS_TABLE => array(
'session_forum_id' => array('UINT', 0),
),
),
'drop_keys' => array(
GROUPS_TABLE => array('group_legend'),
),
'add_index' => array(
SESSIONS_TABLE => array(
'session_forum_id' => array('session_forum_id'),
),
GROUPS_TABLE => array(
'group_legend_name' => array('group_legend', 'group_name'),
),
),
),
// No changes from 3.0.1-RC1 to 3.0.1
'3.0.1-RC1' => array(),
// No changes from 3.0.1 to 3.0.2-RC1
'3.0.1' => array(),
// Changes from 3.0.2-RC1 to 3.0.2-RC2
'3.0.2-RC1' => array(
'change_columns' => array(
DRAFTS_TABLE => array(
'draft_subject' => array('STEXT_UNI', ''),
),
FORUMS_TABLE => array(
'forum_last_post_subject' => array('STEXT_UNI', ''),
),
POSTS_TABLE => array(
'post_subject' => array('STEXT_UNI', '', 'true_sort'),
),
PRIVMSGS_TABLE => array(
'message_subject' => array('STEXT_UNI', ''),
),
TOPICS_TABLE => array(
'topic_title' => array('STEXT_UNI', '', 'true_sort'),
'topic_last_post_subject' => array('STEXT_UNI', ''),
),
),
'drop_keys' => array(
SESSIONS_TABLE => array('session_forum_id'),
),
'add_index' => array(
SESSIONS_TABLE => array(
'session_fid' => array('session_forum_id'),
),
),
),
// No changes from 3.0.2-RC2 to 3.0.2
'3.0.2-RC2' => array(),
// Changes from 3.0.2 to 3.0.3-RC1
'3.0.2' => array(
// Add the following columns
'add_columns' => array(
STYLES_TEMPLATE_TABLE => array(
'template_inherits_id' => array('UINT:4', 0),
'template_inherit_path' => array('VCHAR', ''),
),
GROUPS_TABLE => array(
'group_max_recipients' => array('UINT', 0),
),
),
),
// No changes from 3.0.3-RC1 to 3.0.3
'3.0.3-RC1' => array(),
// Changes from 3.0.3 to 3.0.4-RC1
'3.0.3' => array(
'add_columns' => array(
PROFILE_FIELDS_TABLE => array(
'field_show_profile' => array('BOOL', 0),
),
),
'change_columns' => array(
STYLES_TABLE => array(
'style_id' => array('UINT', NULL, 'auto_increment'),
'template_id' => array('UINT', 0),
'theme_id' => array('UINT', 0),
'imageset_id' => array('UINT', 0),
),
STYLES_IMAGESET_TABLE => array(
'imageset_id' => array('UINT', NULL, 'auto_increment'),
),
STYLES_IMAGESET_DATA_TABLE => array(
'image_id' => array('UINT', NULL, 'auto_increment'),
'imageset_id' => array('UINT', 0),
),
STYLES_THEME_TABLE => array(
'theme_id' => array('UINT', NULL, 'auto_increment'),
),
STYLES_TEMPLATE_TABLE => array(
'template_id' => array('UINT', NULL, 'auto_increment'),
),
STYLES_TEMPLATE_DATA_TABLE => array(
'template_id' => array('UINT', 0),
),
FORUMS_TABLE => array(
'forum_style' => array('UINT', 0),
),
USERS_TABLE => array(
'user_style' => array('UINT', 0),
),
),
),
// Changes from 3.0.4-RC1 to 3.0.4
'3.0.4-RC1' => array(),
// Changes from 3.0.4 to 3.0.5-RC1
'3.0.4' => array(
'change_columns' => array(
FORUMS_TABLE => array(
'forum_style' => array('UINT', 0),
),
),
),
// No changes from 3.0.5-RC1 to 3.0.5
'3.0.5-RC1' => array(),
// Changes from 3.0.5 to 3.0.6-RC1
'3.0.5' => array(
'add_columns' => array(
CONFIRM_TABLE => array(
'attempts' => array('UINT', 0),
),
USERS_TABLE => array(
'user_new' => array('BOOL', 1),
'user_reminded' => array('TINT:4', 0),
'user_reminded_time'=> array('TIMESTAMP', 0),
),
GROUPS_TABLE => array(
'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'),
),
PRIVMSGS_TABLE => array(
'message_reported' => array('BOOL', 0),
),
REPORTS_TABLE => array(
'pm_id' => array('UINT', 0),
),
PROFILE_FIELDS_TABLE => array(
'field_show_on_vt' => array('BOOL', 0),
),
FORUMS_TABLE => array(
'forum_options' => array('UINT:20', 0),
),
),
'change_columns' => array(
USERS_TABLE => array(
'user_options' => array('UINT:11', 230271),
),
),
'add_index' => array(
REPORTS_TABLE => array(
'post_id' => array('post_id'),
'pm_id' => array('pm_id'),
),
POSTS_TABLE => array(
'post_username' => array('post_username'),
),
),
),
// No changes from 3.0.6-RC1 to 3.0.6-RC2
'3.0.6-RC1' => array(),
// No changes from 3.0.6-RC2 to 3.0.6-RC3
'3.0.6-RC2' => array(),
// No changes from 3.0.6-RC3 to 3.0.6-RC4
'3.0.6-RC3' => array(),
// No changes from 3.0.6-RC4 to 3.0.6
'3.0.6-RC4' => array(),
// Changes from 3.0.6 to 3.0.7-RC1
'3.0.6' => array(
'drop_keys' => array(
LOG_TABLE => array('log_time'),
),
),
);
}
/****************************************************************************
* ADD YOUR DATABASE DATA CHANGES HERE *
* REMEMBER: You NEED to enter a schema array above and a data array here, *
* even if both or one of them are empty. *
*****************************************************************************/
function change_database_data(&$no_updates, $version)
{
global $db, $errored, $error_ary, $config, $phpbb_root_path, $phpEx;
switch ($version)
{
case '3.0.0':
$sql = 'UPDATE ' . TOPICS_TABLE . "
SET topic_last_view_time = topic_last_post_time
WHERE topic_last_view_time = 0";
_sql($sql, $errored, $error_ary);
// Update smiley sizes
$smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif');
foreach ($smileys as $smiley)
{
if (file_exists($phpbb_root_path . 'images/smilies/' . $smiley))
{
list($width, $height) = getimagesize($phpbb_root_path . 'images/smilies/' . $smiley);
$sql = 'UPDATE ' . SMILIES_TABLE . '
SET smiley_width = ' . $width . ', smiley_height = ' . $height . "
WHERE smiley_url = '" . $db->sql_escape($smiley) . "'";
_sql($sql, $errored, $error_ary);
}
}
$no_updates = false;
break;
// No changes from 3.0.1-RC1 to 3.0.1
case '3.0.1-RC1':
break;
// changes from 3.0.1 to 3.0.2-RC1
case '3.0.1':
set_config('referer_validation', '1');
set_config('check_attachment_content', '1');
set_config('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title');
$no_updates = false;
break;
// No changes from 3.0.2-RC1 to 3.0.2-RC2
case '3.0.2-RC1':
break;
// No changes from 3.0.2-RC2 to 3.0.2
case '3.0.2-RC2':
break;
// Changes from 3.0.2 to 3.0.3-RC1
case '3.0.2':
set_config('enable_queue_trigger', '0');
set_config('queue_trigger_posts', '3');
set_config('pm_max_recipients', '0');
// Set maximum number of recipients for the registered users, bots, guests group
$sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5
WHERE ' . $db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
_sql($sql, $errored, $error_ary);
// Not prefilling yet
set_config('dbms_version', '');
// Add new permission u_masspm_group and duplicate settings from u_masspm
include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
$auth_admin = new auth_admin();
// Only add the new permission if it does not already exist
if (empty($auth_admin->acl_options['id']['u_masspm_group']))
{
$auth_admin->acl_add_option(array('global' => array('u_masspm_group')));
// Now the tricky part, filling the permission
$old_id = $auth_admin->acl_options['id']['u_masspm'];
$new_id = $auth_admin->acl_options['id']['u_masspm_group'];
$tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE);
foreach ($tables as $table)
{
$sql = 'SELECT *
FROM ' . $table . '