-
Notifications
You must be signed in to change notification settings - Fork 253
/
upgrade_2-1_mysql.sql
3905 lines (3424 loc) · 117 KB
/
upgrade_2-1_mysql.sql
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
/* ATTENTION: You don't need to run or use this file! The upgrade.php script does everything for you! */
/******************************************************************************/
--- Fixing dates...
/******************************************************************************/
---# Updating old values
UPDATE {$db_prefix}calendar
SET start_date = DATE(CONCAT(1004, '-', MONTH(start_date), '-', DAY(start_date)))
WHERE YEAR(start_date) < 1004;
UPDATE {$db_prefix}calendar
SET end_date = DATE(CONCAT(1004, '-', MONTH(end_date), '-', DAY(end_date)))
WHERE YEAR(end_date) < 1004;
UPDATE {$db_prefix}calendar_holidays
SET event_date = DATE(CONCAT(1004, '-', MONTH(event_date), '-', DAY(event_date)))
WHERE YEAR(event_date) < 1004;
UPDATE {$db_prefix}log_spider_stats
SET stat_date = DATE(CONCAT(1004, '-', MONTH(stat_date), '-', DAY(stat_date)))
WHERE YEAR(stat_date) < 1004;
UPDATE {$db_prefix}members
SET birthdate = DATE(CONCAT(IF(YEAR(birthdate) < 1004, 1004, YEAR(birthdate)), '-', IF(MONTH(birthdate) < 1, 1, MONTH(birthdate)), '-', IF(DAY(birthdate) < 1, 1, DAY(birthdate))))
WHERE YEAR(birthdate) < 1004 OR MONTH(birthdate) < 1 OR DAY(birthdate) < 1;
---#
---# Changing default values
ALTER TABLE {$db_prefix}calendar CHANGE start_date start_date date NOT NULL DEFAULT '1004-01-01';
ALTER TABLE {$db_prefix}calendar CHANGE end_date end_date date NOT NULL DEFAULT '1004-01-01';
ALTER TABLE {$db_prefix}calendar_holidays CHANGE event_date event_date date NOT NULL DEFAULT '1004-01-01';
ALTER TABLE {$db_prefix}log_spider_stats CHANGE stat_date stat_date date NOT NULL DEFAULT '1004-01-01';
ALTER TABLE {$db_prefix}members CHANGE birthdate birthdate date NOT NULL DEFAULT '1004-01-01';
ALTER TABLE {$db_prefix}log_activity CHANGE DATE DATE date NOT NULL;
---#
/******************************************************************************/
--- Removing karma
/******************************************************************************/
---# Removing all karma data, if selected
---{
if (!empty($upcontext['delete_karma']))
{
// Delete old settings vars.
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}settings
WHERE variable IN ({array_string:karma_vars})',
array(
'karma_vars' => array('karmaMode', 'karmaTimeRestrictAdmins', 'karmaWaitTime', 'karmaMinPosts', 'karmaLabel', 'karmaSmiteLabel', 'karmaApplaudLabel'),
)
);
$member_columns = $smcFunc['db_list_columns']('{db_prefix}members');
// Cleaning up old karma member settings.
if (in_array('karma_good', $member_columns))
$smcFunc['db_query']('', '
ALTER TABLE {db_prefix}members
DROP karma_good',
array()
);
// Does karma bad was enable?
if (in_array('karma_bad', $member_columns))
$smcFunc['db_query']('', '
ALTER TABLE {db_prefix}members
DROP karma_bad',
array()
);
// Cleaning up old karma permissions.
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}permissions
WHERE permission = {string:karma_vars}',
array(
'karma_vars' => 'karma_edit',
)
);
// Cleaning up old log_karma table
$smcFunc['db_query']('', '
DROP TABLE IF EXISTS {db_prefix}log_karma',
array()
);
}
---}
---#
/******************************************************************************/
--- Emptying error log
/******************************************************************************/
---# Emptying error log, if selected
---{
if (!empty($upcontext['empty_error']))
{
$smcFunc['db_query']('truncate_table', '
TRUNCATE {db_prefix}log_errors',
array(
)
);
}
---}
---#
/******************************************************************************/
--- Adding new settings...
/******************************************************************************/
---# Adding login history...
CREATE TABLE IF NOT EXISTS {$db_prefix}member_logins (
id_login INT AUTO_INCREMENT,
id_member MEDIUMINT NOT NULL DEFAULT '0',
time INT NOT NULL DEFAULT '0',
ip VARBINARY(16),
ip2 VARBINARY(16),
PRIMARY KEY id_login(id_login),
INDEX idx_id_member (id_member),
INDEX idx_time (time)
) ENGINE=MyISAM;
---#
---# Copying the current package backup setting...
---{
if (!isset($modSettings['package_make_full_backups']) && isset($modSettings['package_make_backups']))
upgrade_query("
INSERT INTO {$db_prefix}settings
(variable, value)
VALUES
('package_make_full_backups', '" . $modSettings['package_make_backups'] . "')");
---}
---#
---# Copying the current "allow users to disable word censor" setting...
---{
if (!isset($modSettings['allow_no_censored']))
{
$request = upgrade_query("
SELECT value
FROM {$db_prefix}themes
WHERE variable='allow_no_censored'
AND id_theme = 1 OR id_theme = '$modSettings[theme_default]'
");
// Is it set for either "default" or the one they've set as default?
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['value'] == 1)
{
upgrade_query("
INSERT INTO {$db_prefix}settings
VALUES ('allow_no_censored', 1)
");
// Don't do this twice...
break;
}
}
}
---}
---#
---# Converting collapsed categories...
---{
// We cannot do this twice
if (version_compare(trim(strtolower(@$modSettings['smfVersion'])), '2.1.foo', '<'))
{
$request = $smcFunc['db_query']('', '
SELECT id_member, id_cat
FROM {db_prefix}collapsed_categories');
$inserts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$inserts[] = array($row['id_member'], 1, 'collapse_category_' . $row['id_cat'], $row['id_cat']);
$smcFunc['db_free_result']($request);
if (!empty($inserts))
$smcFunc['db_insert']('replace',
'{db_prefix}themes',
array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string', 'value' => 'string'),
$inserts,
array('id_theme', 'id_member', 'variable')
);
}
---}
---#
---# Parsing board descriptions and names
---{
if (version_compare(trim(strtolower(@$modSettings['smfVersion'])), '2.1.foo', '<'))
{
$request = $smcFunc['db_query']('', '
SELECT name, description, id_board
FROM {db_prefix}boards');
$inserts = array();
$smcFunc['db_free_result']($request);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$inserts[] = array(
'name' => $smcFunc['htmlspecialchars'](strip_tags(html_to_bbc($row['name']))),
'description' => $smcFunc['htmlspecialchars'](strip_tags(html_to_bbc($row['description']))),
'id' => $row['id'],
);
}
if (!empty($inserts))
{
foreach ($inserts as $insert)
{
$smcFunc['db_query']('', '
UPDATE {db_prefix}boards
SET name = {string:name}, description = {string:description}
WHERE id = {int:id}',
$insert
);
}
}
}
---}
---#
---# Dropping "collapsed_categories"
DROP TABLE IF EXISTS {$db_prefix}collapsed_categories;
---#
---# Adding new "topic_move_any" setting
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('topic_move_any', '1');
---#
---# Adding new "enable_ajax_alerts" setting
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('enable_ajax_alerts', '1');
---#
---# Adding new "alerts_auto_purge" setting
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('alerts_auto_purge', '30');
---#
---# Adding new "minimize_files" setting
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('minimize_files', '1');
---#
---# Collapse object
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('additional_options_collapsable', '1');
---#
---# Adding new "DEFAULTMaxListItems" setting
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('defaultMaxListItems', '15');
---#
---# Adding new "loginHistoryDays" setting
---{
if (!isset($modSettings['loginHistoryDays']))
$smcFunc['db_insert']('insert',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
array('loginHistoryDays', '30'),
array('variable')
);
---}
---#
---# Enable some settings we ripped from Theme settings
---{
$ripped_settings = array('show_modify', 'show_user_images', 'show_blurb', 'show_profile_buttons', 'subject_toggle', 'hide_post_group');
$request = $smcFunc['db_query']('', '
SELECT variable, value
FROM {db_prefix}themes
WHERE variable IN({array_string:ripped_settings})
AND id_member = 0
AND id_theme = 1',
array(
'ripped_settings' => $ripped_settings,
)
);
$inserts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$inserts[] = array($row['variable'], $row['value']);
$smcFunc['db_free_result']($request);
$smcFunc['db_insert']('replace',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
$inserts,
array('variable')
);
---}
---#
---# Adding new "httponlyCookies" setting
---{
if (!isset($modSettings['httponlyCookies']))
$smcFunc['db_insert']('insert',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
array('httponlyCookies', '1'),
array()
);
---}
---#
---# Adding new "samesiteCookies" setting
---{
if (!isset($modSettings['samesiteCookies']))
$smcFunc['db_insert']('insert',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
array('samesiteCookies', 'lax'),
array()
);
---}
---#
---# Calculate appropriate hash cost
---{
$smcFunc['db_insert']('replace',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
array('bcrypt_hash_cost', hash_benchmark()),
array('variable')
);
---}
---# Disable Moderation Center Security if it doesn't exist
---{
if (!isset($modSettings['securityDisable_moderate']))
$smcFunc['db_insert']('insert',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
array('securityDisable_moderate', '1'),
array('variable')
);
---}
---#
---# Adding new profile data export settings
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('export_dir', '{$boarddir}/exports');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('export_expiry', '7');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('export_min_diskspace_pct', '5');
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('export_rate', '250');
---#
---# Adding settings for marking boards as read
---{
if (!isset($modSettings['mark_read_beyond']))
$smcFunc['db_insert']('insert',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
array('mark_read_beyond', '90'),
array()
);
if (!isset($modSettings['mark_read_delete_beyond']))
$smcFunc['db_insert']('insert',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
array('mark_read_delete_beyond', '365'),
array()
);
if (!isset($modSettings['mark_read_max_users']))
$smcFunc['db_insert']('insert',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
array('mark_read_max_users', '500'),
array()
);
---}
---#
/******************************************************************************/
--- Updating legacy attachments...
/******************************************************************************/
---# Adding more space to the mime_type column.
ALTER TABLE {$db_prefix}attachments
CHANGE `mime_type` `mime_type` VARCHAR(128) NOT NULL DEFAULT '';
---#
---# Converting legacy attachments.
---{
// Need to know a few things first.
$custom_av_dir = !empty($modSettings['custom_avatar_dir']) ? $modSettings['custom_avatar_dir'] : $GLOBALS['boarddir'] .'/custom_avatar';
// This little fellow has to cooperate...
if (!is_writable($custom_av_dir))
{
// Try 755 and 775 first since 777 doesn't always work and could be a risk...
$chmod_values = array(0755, 0775, 0777);
foreach($chmod_values as $val)
{
// If it's writable, break out of the loop
if (is_writable($custom_av_dir))
break;
else
@chmod($custom_av_dir, $val);
}
}
// If we already are using a custom dir, delete the predefined one.
if (realpath($custom_av_dir) != realpath($GLOBALS['boarddir'] .'/custom_avatar'))
{
// Borrow custom_avatars index.php file.
if (!file_exists($custom_av_dir . '/index.php'))
@rename($GLOBALS['boarddir'] .'/custom_avatar/index.php', $custom_av_dir .'/index.php');
else
@unlink($GLOBALS['boarddir'] . '/custom_avatar/index.php');
// Borrow blank.png as well
if (!file_exists($custom_av_dir . '/blank.png'))
@rename($GLOBALS['boarddir'] . '/custom_avatar/blank.png', $custom_av_dir . '/blank.png');
else
@unlink($GLOBALS['boarddir'] . '/custom_avatar/blank.png');
// Attempt to delete the directory.
@rmdir($GLOBALS['boarddir'] .'/custom_avatar');
}
$request = upgrade_query("
SELECT COUNT(*)
FROM {$db_prefix}attachments
WHERE attachment_type != 1");
list ($step_progress['total']) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
$_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
$step_progress['name'] = 'Converting legacy attachments';
$step_progress['current'] = $_GET['a'];
// We may be using multiple attachment directories.
// Allow for reruns - it's possible it's json...
if (!empty($modSettings['currentAttachmentUploadDir']) && !is_array($modSettings['attachmentUploadDir']))
if (empty($modSettings['json_done']))
$modSettings['attachmentUploadDir'] = @unserialize($modSettings['attachmentUploadDir']);
else
$modSettings['attachmentUploadDir'] = @json_decode($modSettings['attachmentUploadDir'], true);
// No need to do this if we already did it previously... Unless requested...
if (empty($modSettings['attachments_21_done']) || !empty($upcontext['reprocess_attachments']))
$is_done = false;
else
$is_done = true;
while (!$is_done)
{
nextSubStep($substep);
$request = upgrade_query("
SELECT id_attach, id_member, id_folder, filename, file_hash, mime_type
FROM {$db_prefix}attachments
WHERE attachment_type != 1
ORDER BY id_attach
LIMIT $_GET[a], 100");
// Finished?
if ($smcFunc['db_num_rows']($request) == 0)
$is_done = true;
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// The current folder.
$currentFolder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$row['id_folder']] : $modSettings['attachmentUploadDir'];
$fileHash = '';
// Old School?
if (empty($row['file_hash']))
{
// Remove international characters (windows-1252)
// These lines should never be needed again. Still, behave.
if (empty($db_character_set) || $db_character_set != 'utf8')
{
$row['filename'] = strtr($row['filename'],
"\x8a\x8e\x9a\x9e\x9f\xc0\xc1\xc2\xc3\xc4\xc5\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xe0\xe1\xe2\xe3\xe4\xe5\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xff",
'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy');
$row['filename'] = strtr($row['filename'], array("\xde" => 'TH', "\xfe" =>
'th', "\xd0" => 'DH', "\xf0" => 'dh', "\xdf" => 'ss', "\x8c" => 'OE',
"\x9c" => 'oe', "\xc6" => 'AE', "\xe6" => 'ae', "\xb5" => 'u'));
}
// Sorry, no spaces, dots, or anything else but letters allowed.
$row['filename'] = preg_replace(array('/\s/', '/[^\w_\.\-]/'), array('_', ''), $row['filename']);
// Create a nice hash.
$fileHash = sha1(md5($row['filename'] . time()) . mt_rand());
// Iterate through the possible attachment names until we find the one that exists
$oldFile = $currentFolder . '/' . $row['id_attach']. '_' . strtr($row['filename'], '.', '_') . md5($row['filename']);
if (!file_exists($oldFile))
{
$oldFile = $currentFolder . '/' . $row['filename'];
if (!file_exists($oldFile)) $oldFile = false;
}
// Build the new file.
$newFile = $currentFolder . '/' . $row['id_attach'] . '_' . $fileHash .'.dat';
}
// Just rename the file.
else
{
$oldFile = $currentFolder . '/' . $row['id_attach'] . '_' . $row['file_hash'];
$newFile = $currentFolder . '/' . $row['id_attach'] . '_' . $row['file_hash'] .'.dat';
// Make sure it exists...
if (!file_exists($oldFile))
$oldFile = false;
}
if (!$oldFile)
{
// Existing attachment could not be found. Just skip it...
continue;
}
// Check if the av is an attachment
if ($row['id_member'] != 0)
{
if (rename($oldFile, $custom_av_dir . '/' . $row['filename']))
{
upgrade_query("
UPDATE {$db_prefix}attachments
SET file_hash = '', attachment_type = 1
WHERE id_attach = $row[id_attach]");
$_GET['a'] -= 1;
}
}
// Just a regular attachment.
else
{
rename($oldFile, $newFile);
}
// Only update this if it was successful and the file was using the old system.
if (empty($row['file_hash']) && !empty($fileHash) && file_exists($newFile) && !file_exists($oldFile))
upgrade_query("
UPDATE {$db_prefix}attachments
SET file_hash = '$fileHash'
WHERE id_attach = $row[id_attach]");
// While we're here, do we need to update the mime_type?
if (empty($row['mime_type']) && file_exists($newFile))
{
$size = @getimagesize($newFile);
if (!empty($size['mime']))
$smcFunc['db_query']('', '
UPDATE {db_prefix}attachments
SET mime_type = {string:mime_type}
WHERE id_attach = {int:id_attach}',
array(
'id_attach' => $row['id_attach'],
'mime_type' => substr($size['mime'], 0, 20),
)
);
}
}
$smcFunc['db_free_result']($request);
$_GET['a'] += 100;
$step_progress['current'] = $_GET['a'];
}
unset($_GET['a']);
---}
---#
---# Note attachment conversion complete
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('attachments_21_done', '1');
---#
---# Fixing invalid sizes on attachments
---{
$attachs = array();
// If id_member = 0, then it's not an avatar
// If attachment_type = 0, then it's also not a thumbnail
// Theory says there shouldn't be *that* many of these
$request = $smcFunc['db_query']('', '
SELECT id_attach, mime_type, width, height
FROM {db_prefix}attachments
WHERE id_member = 0
AND attachment_type = 0'
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (($row['width'] > 0 || $row['height'] > 0) && strpos($row['mime_type'], 'image') !== 0)
$attachs[] = $row['id_attach'];
}
$smcFunc['db_free_result']($request);
if (!empty($attachs))
$smcFunc['db_query']('', '
UPDATE {db_prefix}attachments
SET width = 0,
height = 0
WHERE id_attach IN ({array_int:attachs})',
array(
'attachs' => $attachs,
)
);
---}
---#
---# Fixing attachment directory setting...
---{
// If it's a directory or an array, ensure it is stored as a serialized string (prep for later serial_to_json conversion)
// Also ensure currentAttachmentUploadDir is set even for single directories
// Make sure to do it in memory and in db...
if (empty($modSettings['json_done']))
{
if (!is_array($modSettings['attachmentUploadDir']) && is_dir($modSettings['attachmentUploadDir']))
{
$modSettings['attachmentUploadDir'] = serialize(array(1 => $modSettings['attachmentUploadDir']));
$smcFunc['db_query']('', '
UPDATE {db_prefix}settings
SET value = {string:attach_dir}
WHERE variable = {string:uploadDir}',
array(
'attach_dir' => $modSettings['attachmentUploadDir'],
'uploadDir' => 'attachmentUploadDir'
)
);
$smcFunc['db_insert']('replace',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
array('currentAttachmentUploadDir', '1'),
array('variable')
);
}
elseif (is_array($modSettings['attachmentUploadDir']))
{
$modSettings['attachmentUploadDir'] = serialize($modSettings['attachmentUploadDir']);
$smcFunc['db_query']('', '
UPDATE {db_prefix}settings
SET value = {string:attach_dir}
WHERE variable = {string:uploadDir}',
array(
'attach_dir' => $modSettings['attachmentUploadDir'],
'uploadDir' => 'attachmentUploadDir'
)
);
// Assume currentAttachmentUploadDir is already set
}
}
---}
---#
/******************************************************************************/
--- Adding support for logging who fulfils a group request.
/******************************************************************************/
---# Adding new columns to log_group_requests
ALTER TABLE {$db_prefix}log_group_requests
ADD COLUMN status TINYINT UNSIGNED NOT NULL DEFAULT '0',
ADD COLUMN id_member_acted MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
ADD COLUMN member_name_acted VARCHAR(255) NOT NULL DEFAULT '',
ADD COLUMN time_acted INT UNSIGNED NOT NULL DEFAULT '0',
ADD COLUMN act_reason TEXT NOT NULL;
---#
---# Adjusting the indexes for log_group_requests
ALTER TABLE {$db_prefix}log_group_requests
DROP INDEX `id_member`,
ADD INDEX `idx_id_member` (`id_member`, `id_group`);
---#
/******************************************************************************/
--- Package Manager New Features
/******************************************************************************/
---# Adding support for <credits> tag in package manager
ALTER TABLE {$db_prefix}log_packages
ADD COLUMN credits TEXT NOT NULL;
---#
---# Adding support for package hashes
ALTER TABLE {$db_prefix}log_packages
ADD COLUMN sha256_hash TEXT;
---#
---# Adding support for validation servers
ALTER TABLE {$db_prefix}package_servers
ADD COLUMN validation_url VARCHAR(255) DEFAULT '',
ADD COLUMN extra TEXT;
---#
---# Add Package Validation to Downloads Site
---{
$request = $smcFunc['db_query']('', '
SELECT id_server
FROM {db_prefix}package_servers
WHERE url LIKE {string:downloads_site}',
array(
'downloads_site' => 'https://download.simplemachines.org%',
)
);
if ($smcFunc['db_num_rows']($request) != 0)
list($downloads_server) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
if (empty($downloads_server))
$smcFunc['db_insert']('',
'{db_prefix}package_servers',
array('name' => 'string', 'url' => 'string', 'validation_url' => 'string'),
array('Simple Machines Download Site', 'https://download.simplemachines.org/browse.php?api=v1;smf_version={SMF_VERSION}', 'https://download.simplemachines.org/validate.php?api=v1;smf_version={SMF_VERSION}'),
array('id_server')
);
---}
---#
---# Ensure The Simple Machines Customize Site is https
UPDATE {$db_prefix}package_servers
SET url = 'https://custom.simplemachines.org/packages/mods'
WHERE url = 'http://custom.simplemachines.org/packages/mods';
---#
---# Add validation to Simple Machines Customize Site
UPDATE {$db_prefix}package_servers
SET validation_url = 'https://custom.simplemachines.org/api.php?action=validate;version=v1;smf_version={SMF_VERSION}'
WHERE url = 'https://custom.simplemachines.org/packages/mods';
---#
/******************************************************************************/
--- Adding more space for session ids
/******************************************************************************/
---# Altering the session_id columns...
ALTER TABLE {$db_prefix}log_online
CHANGE `session` `session` VARCHAR(128) NOT NULL DEFAULT '';
ALTER TABLE {$db_prefix}log_errors
CHANGE `session` `session` VARCHAR(128) NOT NULL DEFAULT ' ';
ALTER TABLE {$db_prefix}sessions
CHANGE `session_id` `session_id` VARCHAR(128) NOT NULL DEFAULT '';
---#
/******************************************************************************/
--- Adding support for MOVED topics enhancements
/******************************************************************************/
---# Adding new columns to topics ..
ALTER TABLE {$db_prefix}topics
ADD COLUMN redirect_expires INT UNSIGNED NOT NULL DEFAULT '0',
ADD COLUMN id_redirect_topic MEDIUMINT UNSIGNED NOT NULL DEFAULT '0';
---#
/******************************************************************************/
--- Adding new scheduled tasks
/******************************************************************************/
---# Adding a new column "callable" to scheduled_tasks table
ALTER TABLE {$db_prefix}scheduled_tasks
ADD COLUMN callable VARCHAR(60) NOT NULL DEFAULT '';
---#
---# Adding new scheduled tasks
INSERT INTO {$db_prefix}scheduled_tasks
(next_time, time_offset, time_regularity, time_unit, disabled, task, callable)
VALUES
(0, 120, 1, 'd', 0, 'remove_temp_attachments', '');
INSERT INTO {$db_prefix}scheduled_tasks
(next_time, time_offset, time_regularity, time_unit, disabled, task, callable)
VALUES
(0, 180, 1, 'd', 0, 'remove_topic_redirect', '');
INSERT INTO {$db_prefix}scheduled_tasks
(next_time, time_offset, time_regularity, time_unit, disabled, task, callable)
VALUES
(0, 240, 1, 'd', 0, 'remove_old_drafts', '');
INSERT INTO {$db_prefix}scheduled_tasks
(next_time, time_offset, time_regularity, time_unit, disabled, task, callable)
VALUES
(0, 0, 1, 'w', 1, 'prune_log_topics', '');
---#
---# Adding a new task-related setting...
---{
if (!isset($modSettings['allow_expire_redirect']))
{
$get_info = $smcFunc['db_query']('', '
SELECT disabled
FROM {db_prefix}scheduled_tasks
WHERE task = {string:remove_redirect}',
array(
'remove_redirect' => 'remove_topic_redirect'
)
);
list($task_disabled) = $smcFunc['db_fetch_row']($get_info);
$smcFunc['db_free_result']($get_info);
$smcFunc['db_insert']('replace',
'{db_prefix}settings',
array('variable' => 'string', 'value' => 'string'),
array('allow_expire_redirect', !$task_disabled),
array('variable')
);
}
---}
---#
---# Remove old tasks added by modifications...
---{
$vanilla_tasks = array(
'birthdayemails',
'daily_digest',
'daily_maintenance',
'fetchSMfiles',
'paid_subscriptions',
'remove_temp_attachments',
'remove_topic_redirect',
'remove_old_drafts',
'prune_log_topics',
'weekly_digest',
'weekly_maintenance');
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}scheduled_tasks
WHERE task NOT IN ({array_string:keep_tasks});',
array(
'keep_tasks' => $vanilla_tasks
)
);
---}
---#
/******************************************************************************/
---- Adding background tasks support
/******************************************************************************/
---# Adding the new table
CREATE TABLE IF NOT EXISTS {$db_prefix}background_tasks (
id_task INT UNSIGNED AUTO_INCREMENT,
task_file VARCHAR(255) NOT NULL DEFAULT '',
task_class VARCHAR(255) NOT NULL DEFAULT '',
task_data mediumtext NOT NULL,
claimed_time INT UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (id_task)
) ENGINE=MyISAM;
---#
/******************************************************************************/
--- Adding support for deny boards access
/******************************************************************************/
---# Adding new columns to boards...
ALTER TABLE {$db_prefix}boards
ADD COLUMN deny_member_groups VARCHAR(255) NOT NULL DEFAULT '';
---#
/******************************************************************************/
--- Adding setting for max depth of sub-boards to check for new posts, etc.
/******************************************************************************/
---# Adding the boardindex_max_depth setting.
INSERT INTO {$db_prefix}settings
(variable, value)
VALUES
('boardindex_max_depth', '1');
---#
/******************************************************************************/
--- Removing manage_boards permission from anyone who shouldn't have it
/******************************************************************************/
---# Removing manage_boards permission
---{
if (version_compare(trim(strtolower(@$modSettings['smfVersion'])), '2.1.foo', '<'))
{
$board_managers = array();
$request = $smcFunc['db_query']('', '
SELECT id_group
FROM {db_prefix}permissions
WHERE permission = {string:permission}',
array(
'permission' => 'manage_boards',
)
);
if ($smcFunc['db_num_rows']($request) != 0)
{
while ($row = $smcFunc['db_fetch_assoc']($request))
$board_managers[$row['id_group']] = 0;
}
$smcFunc['db_free_result']($request);
$request = $smcFunc['db_query']('', '
SELECT member_groups
FROM {db_prefix}boards',
array()
);
$num_boards = $smcFunc['db_num_rows']($request);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$groups = explode(',', $row['member_groups']);
foreach ($groups as $group)
if (array_key_exists($group, $board_managers))
++$board_managers[$group];
}
$smcFunc['db_free_result']($request);
$ex_board_managers = array();
foreach ($board_managers as $id_group => $board_count)
if ($board_count < $num_boards)
$ex_board_managers[] = $id_group;
if (!empty($ex_board_managers))
{
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}permissions
WHERE permission = {string:permission}
AND id_group IN ({array_int:ex_board_managers})',
array(
'permission' => 'manage_boards',
'ex_board_managers' => $ex_board_managers,
)
);
}
}
---}
---#
/******************************************************************************/
--- Adding support for category descriptions
/******************************************************************************/
---# Adding new columns to categories...
ALTER TABLE {$db_prefix}categories
ADD COLUMN description TEXT NOT NULL;
---#
/******************************************************************************/
--- Adding support for alerts
/******************************************************************************/
---# Adding the count to the members table...
ALTER TABLE {$db_prefix}members
ADD COLUMN alerts INT UNSIGNED NOT NULL DEFAULT '0';
---#
---# Adding the new table for alerts.
CREATE TABLE IF NOT EXISTS {$db_prefix}user_alerts (
id_alert INT UNSIGNED AUTO_INCREMENT,
alert_time INT UNSIGNED NOT NULL DEFAULT '0',
id_member MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
id_member_started MEDIUMINT UNSIGNED NOT NULL DEFAULT '0',
member_name VARCHAR(255) NOT NULL DEFAULT '',
content_type VARCHAR(255) NOT NULL DEFAULT '',
content_id INT UNSIGNED NOT NULL DEFAULT '0',
content_action VARCHAR(255) NOT NULL DEFAULT '',
is_read INT UNSIGNED NOT NULL DEFAULT '0',
extra TEXT NOT NULL,
PRIMARY KEY (id_alert),
INDEX idx_id_member (id_member),
INDEX idx_alert_time (alert_time)
) ENGINE=MyISAM;
---#
---# Adding alert preferences.
CREATE TABLE IF NOT EXISTS {$db_prefix}user_alerts_prefs (
id_member MEDIUMINT UNSIGNED DEFAULT '0',
alert_pref VARCHAR(32) DEFAULT '',
alert_value TINYINT NOT NULL DEFAULT '0',
PRIMARY KEY (id_member, alert_pref)
) ENGINE=MyISAM;
INSERT INTO {$db_prefix}user_alerts_prefs
(id_member, alert_pref, alert_value)
VALUES (0, 'alert_timeout', 10),
(0, 'announcements', 0),
(0, 'birthday', 2),
(0, 'board_notify', 1),
(0, 'buddy_request', 1),
(0, 'groupr_approved', 3),
(0, 'groupr_rejected', 3),
(0, 'member_group_request', 1),
(0, 'member_register', 1),
(0, 'member_report', 3),
(0, 'member_report_reply', 3),
(0, 'msg_auto_notify', 0),
(0, 'msg_like', 1),
(0, 'msg_mention', 1),
(0, 'msg_notify_pref', 1),
(0, 'msg_notify_type', 1),
(0, 'msg_quote', 1),
(0, 'msg_receive_body', 0),
(0, 'msg_report', 1),
(0, 'msg_report_reply', 1),
(0, 'pm_new', 1),
(0, 'pm_notify', 1),
(0, 'pm_reply', 1),
(0, 'request_group', 1),
(0, 'topic_notify', 1),
(0, 'unapproved_attachment', 1),
(0, 'unapproved_reply', 3),
(0, 'unapproved_post', 1),
(0, 'warn_any', 1);
---#
---# Upgrading post notification settings
---{
// First see if we still have a notify_regularity column
$results = $smcFunc['db_list_columns']('{db_prefix}members');
if (in_array('notify_regularity', $results))
{
$_GET['a'] = isset($_GET['a']) ? (int) $_GET['a'] : 0;
$step_progress['name'] = 'Upgrading post notification settings';
$step_progress['current'] = $_GET['a'];