forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.update.php
1439 lines (1264 loc) · 42.4 KB
/
core.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
/**
* This file is called on header.php and checks the database to see
* if it up to date with the current software version.
*
* In case you are updating from an old one, the new values, columns
* and rows will be created, and a message will appear under the menu
* one time only.
*/
$allowed_update = array(9,8,7);
if (current_role_in($allowed_update)) {
$statement = $dbh->prepare("SET SQL_MODE='ALLOW_INVALID_DATES';");
$statement->execute();
$update_data = get_latest_version_data();
$update_data = json_decode($update_data);
if (empty($update_data)) {
return;
}
$updates_made = 0;
$updates_errors = 0;
$updates_error_messages = [];
/**
* r264 updates
* Save the value of the last update on the database, to prevent
* running all this queries everytime a page is loaded.
* Done on top for convenience.
*/
$statement = $dbh->prepare("SELECT value FROM " . TABLE_OPTIONS . " WHERE name = 'last_update'");
$statement->execute();
if ( $statement->rowCount() == 0 ) {
$dbh->query( "INSERT INTO " . TABLE_OPTIONS . " (name, value) VALUES ('last_update', '264')" );
$updates_made++;
}
else {
$statement->setFetchMode(PDO::FETCH_ASSOC);
while ( $row = $statement->fetch() ) {
$last_update = $row['value'];
}
}
if ($last_update < $update_data->local_version || !isset($last_update)) {
/**
* r92 updates
* The logo file name is now stored on the database.
* If the row doesn't exist, create it and add the default value.
*/
if ($last_update < 92) {
$new_database_values = array(
'logo_filename' => ''
);
foreach ($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r94 updates
* A new column was added on the clients table, to store the value of the
* user that created it.
* If the column doesn't exist, create it.
*/
/*
DEPRECATED
table tbl_clients doesn't exist anymore
if ($last_update < 94) {
$statement = $dbh->prepare("SELECT created_by FROM tbl_clients");
$statement->execute();
if( $statement->rowCount() == 0 ) {
$statement = $dbh->query("ALTER TABLE tbl_clients ADD created_by VARCHAR(".MAX_USER_CHARS.") NOT NULL");
$updates_made++;
}
}
*/
/**
* DEPRECATED
* r102 updates
* A function was added to hide or show uploaded files from the clients lists.
* If the "hidden" column on the files table doesn't exist, create it.
*/
/*
$statement = $dbh->query("SELECT hidden FROM " . TABLE_FILES);
if ( $statement->rowCount() == 0 ) {
$statement = $dbh->query("ALTER TABLE " . TABLE_FILES . " ADD hidden INT(1) NOT NULL");
$updates_made++;
}
*/
/**
* r135 updates
* The e-mail address used for notifications to new users, clients and files
* can now be defined on the options page. When installing or updating, it
* will default to the primary admin user's e-mail.
*/
if ($last_update < 135) {
$statement = $dbh->query("SELECT * FROM " . TABLE_USERS . " WHERE id = '1'");
$statement->setFetchMode(PDO::FETCH_ASSOC);
while ( $row = $statement->fetch() ) {
$set_admin_email = $row['email'];
}
$new_database_values = array(
'admin_email_address' => $set_admin_email
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r183 updates
* A new column was added on the clients table, to store the value of the
* account active status.
* If the column doesn't exist, create it. Also, mark every existing
* client as active (1).
*/
if ($last_update < 183) {
/*
DEPRECATED
table tbl_clients doesn't exist anymore
$q = $database->query("SELECT active FROM tbl_clients");
if (!$q) {
mysql_query("ALTER TABLE tbl_clients ADD active tinyint(1) NOT NULL");
$sql = $database->query('SELECT * FROM tbl_clients');
while($row = mysql_fetch_array($sql)) {
$database->query('UPDATE tbl_clients SET active = 1');
}
$updates_made++;
}
*/
/**
* Add the "users can register" value to the options table.
* Defaults to 0, since this is a new feature.
* */
$new_database_values = array(
'clients_can_register' => '0'
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r189 updates
* Move every uploaded file to a neutral location
*/
if ($last_update < 189) {
$work_folder = ROOT_DIR.'/upload/';
$folders = glob($work_folder."*", GLOB_NOSORT);
foreach ($folders as $folder) {
if(is_dir($folder) && !stristr($folder,'/temp') && !stristr($folder,'/files')) {
$files = glob($folder.'/*', GLOB_NOSORT);
foreach ($files as $file) {
if(is_file($file) && !stristr($file,'index.php')) {
$filename = basename($file);
$mark_for_moving[$filename] = $file;
}
}
}
}
$work_folder = UPLOADED_FILES_DIR;
if (!empty($mark_for_moving)) {
foreach ($mark_for_moving as $filename => $path) {
$new = UPLOADED_FILES_DIR.DS.$filename;
$try_moving = rename($path, $new);
chmod($new, 0644);
}
}
}
/**
* r202 updates
* Combine clients and users on the same table.
*/
if ($last_update < 202) {
try {
$statement = $dbh->query("SELECT created_by FROM " . TABLE_USERS);
} catch( PDOException $e ) {
/* Mark existing users as active */
$dbh->query("ALTER TABLE " . TABLE_USERS . " ADD address TEXT NULL, ADD phone varchar(32) NULL, ADD notify TINYINT(1) NOT NULL default='0', ADD contact TEXT NULL, ADD created_by varchar(32) NULL, ADD active TINYINT(1) NOT NULL default='1'");
$dbh->query("INSERT INTO " . TABLE_USERS
." (user, password, name, email, timestamp, address, phone, notify, contact, created_by, active, level)"
." SELECT client_user, password, name, email, timestamp, address, phone, notify, contact, created_by, active, '0' FROM tbl_clients");
$dbh->query("UPDATE " . TABLE_USERS . " SET active = 1");
$updates_made++;
}
}
/**
* r210 updates
* A new database table was added, that allows the creation of clients groups.
*/
if ($last_update < 210) {
if ( !table_exists( TABLE_GROUPS ) ) {
/** Create the GROUPS table */
$query = "
CREATE TABLE IF NOT EXISTS `".TABLE_GROUPS."` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
`created_by` varchar(32) NOT NULL,
`name` varchar(32) NOT NULL,
`description` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
";
$statement = $dbh->prepare($query);
$statement->execute();
$updates_made++;
/**
* r215 updates
* Change the engine of every table to InnoDB, to use foreign keys on the
* groups feature.
* Included inside the previous update since that is not an officially
* released version.
*/
foreach ($original_basic_tables as $working_table) {
$statement = $dbh->prepare("ALTER TABLE $working_table ENGINE = InnoDB");
$statement->execute();
$updates_made++;
}
}
}
/**
* r219 updates
* A new database table was added.
* Folders are related to clients or groups.
*/
if ($last_update < 219) {
if ( !table_exists( TABLE_FOLDERS ) ) {
$query = "
CREATE TABLE IF NOT EXISTS `".TABLE_FOLDERS."` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent` int(11) DEFAULT NULL,
`name` varchar(32) NOT NULL,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
`client_id` int(11) DEFAULT NULL,
`group_id` int(11) DEFAULT NULL,
FOREIGN KEY (`parent`) REFERENCES ".TABLE_FOLDERS."(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`client_id`) REFERENCES ".TABLE_USERS."(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`group_id`) REFERENCES ".TABLE_GROUPS."(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
";
$statement = $dbh->prepare($query);
$statement->execute();
$updates_made++;
}
}
/**
* r217 updates (after previous so the folder column can be created)
* A new database table was added, to facilitate the relation of files
* with clients and groups.
*/
if ($last_update < 217) {
if ( !table_exists( TABLE_FILES_RELATIONS ) ) {
$query = "
CREATE TABLE IF NOT EXISTS `".TABLE_FILES_RELATIONS."` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
`file_id` int(11) NOT NULL,
`client_id` int(11) DEFAULT NULL,
`group_id` int(11) DEFAULT NULL,
`folder_id` int(11) DEFAULT NULL,
`hidden` int(1) NOT NULL,
`download_count` int(16) NOT NULL default '0',
FOREIGN KEY (`file_id`) REFERENCES ".TABLE_FILES."(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`client_id`) REFERENCES ".TABLE_USERS."(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`group_id`) REFERENCES ".TABLE_GROUPS."(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`folder_id`) REFERENCES ".TABLE_FOLDERS."(`id`) ON UPDATE CASCADE,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
";
$statement = $dbh->prepare($query);
$statement->execute();
$updates_made++;
}
}
/**
* r241 updates
* A new database table was added, that stores users and clients actions.
*/
if ($last_update < 241) {
if ( !table_exists( TABLE_LOG ) ) {
$query = "
CREATE TABLE IF NOT EXISTS `".TABLE_LOG."` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
`action` int(2) NOT NULL,
`owner_id` int(11) NOT NULL,
`owner_user` text DEFAULT NULL,
`affected_file` int(11) DEFAULT NULL,
`affected_account` int(11) DEFAULT NULL,
`affected_file_name` text DEFAULT NULL,
`affected_account_name` text DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
";
$statement = $dbh->prepare($query);
$statement->execute();
$updates_made++;
}
}
/**
* r266 updates
* Set timestamp columns as real timestamp data, instead of INT
*/
if ($last_update < 266) {
$statement = $dbh->query("ALTER TABLE `" . TABLE_USERS . "` ADD COLUMN `timestamp2` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP()");
$statement = $dbh->query("UPDATE `" . TABLE_USERS . "` SET `timestamp2` = FROM_UNIXTIME(`timestamp`)");
$statement = $dbh->query("ALTER TABLE `" . TABLE_USERS . "` DROP COLUMN `timestamp`");
$statement = $dbh->query("ALTER TABLE `" . TABLE_USERS . "` CHANGE `timestamp2` `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP()");
$updates_made++;
}
/**
* r275 updates
* A new database table was added.
* It stores the new files-to clients relations to be
* used on notifications.
*/
if ($last_update < 275) {
if ( !table_exists( TABLE_NOTIFICATIONS ) ) {
$query = "
CREATE TABLE IF NOT EXISTS `".TABLE_NOTIFICATIONS."` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
`file_id` int(11) NOT NULL,
`client_id` int(11) NOT NULL,
`upload_type` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
";
$statement = $dbh->prepare($query);
$statement->execute();
$updates_made++;
}
}
/**
* r278 updates
* Set timestamp columns as real timestamp data, instead of INT
*/
if ($last_update < 278) {
$statement = $dbh->query("ALTER TABLE `" . TABLE_FILES . "` ADD COLUMN `timestamp2` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP()");
$statement = $dbh->query("UPDATE `" . TABLE_FILES . "` SET `timestamp2` = FROM_UNIXTIME(`timestamp`)");
$statement = $dbh->query("ALTER TABLE `" . TABLE_FILES . "` DROP COLUMN `timestamp`");
$statement = $dbh->query("ALTER TABLE `" . TABLE_FILES . "` CHANGE `timestamp2` `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP()");
$updates_made++;
}
/**
* r282 updates
* Add new options to select the handler for sending emails.
*/
if ($last_update < 282) {
$new_database_values = array(
'mail_system_use' => 'mail',
'mail_smtp_host' => '',
'mail_smtp_port' => '',
'mail_smtp_user' => '',
'mail_smtp_pass' => '',
'mail_from_name' => get_option('this_install_title')
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r338 updates
* The Members table wasn't being created on existing installations.
*/
if ($last_update < 338) {
if ( !table_exists( TABLE_MEMBERS ) ) {
/** Create the MEMBERS table */
$query = "
CREATE TABLE IF NOT EXISTS `".TABLE_MEMBERS."` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
`added_by` varchar(32) NOT NULL,
`client_id` int(11) NOT NULL,
`group_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`client_id`) REFERENCES ".TABLE_USERS."(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`group_id`) REFERENCES ".TABLE_GROUPS."(`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
";
$statement = $dbh->prepare($query);
$statement->execute();
$updates_made++;
}
}
/**
* r348 updates
* chmod the emails folder and files to 777
*/
if ($last_update < 348) {
$update_chmod_emails = update_chmod_emails();
if (!empty($update_chmod_emails)) {
foreach ($update_chmod_emails as $error) {
$updates_error_messages[] = $update_chmod_emails;
$updates_errors++;
}
}
else {
$updates_made++;
}
}
/**
* r352 updates
* chmod the main system files to 644
*/
if ($last_update < 352) {
$chmod_main_files = chmod_main_files();
if (!empty($chmod_main_files)) {
foreach ($chmod_main_files as $error) {
$updates_error_messages[] = $chmod_main_files;
$updates_errors++;
}
}
else {
$updates_made++;
}
}
/**
* r354 updates
* Import the files relations (up until r335 it was
* only one-to-one with clients) into the new database
* table. This should have been done before r335 release.
* Sorry :(
*/
if ($last_update < 354) {
import_files_relations();
}
/**
* r358 updates
* New columns where added to the notifications table, to
* store values about the state of it.
* If the columns don't exist, create them.
*/
if ($last_update < 358) {
try {
$statement = $dbh->query("SELECT sent_status FROM " . TABLE_NOTIFICATIONS);
} catch( PDOException $e ) {
$statement = $dbh->query("ALTER TABLE " . TABLE_NOTIFICATIONS . " ADD sent_status INT(2) NOT NULL");
$statement = $dbh->query("ALTER TABLE " . TABLE_NOTIFICATIONS . " ADD times_failed INT(11) NOT NULL");
$updates_made++;
}
}
/**
* r364 updates
* Add new options to send copies of notifications emails
* to the specified addresses.
*/
if ($last_update < 364) {
$new_database_values = array(
'mail_copy_user_upload' => '',
'mail_copy_client_upload' => '',
'mail_copy_main_user' => '',
'mail_copy_addresses' => ''
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r377 updates
* Add new options to store the last time the system checked
* for a new version.
*/
$today = date('d-m-Y');
if ($last_update < 377) {
$new_database_values = array(
'version_last_check' => $today,
'version_new_found' => '0',
'version_new_number' => '',
'version_new_url' => '',
'version_new_chlog' => '',
'version_new_security' => '',
'version_new_features' => '',
'version_new_important' => ''
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r386 / r412 updates
* Add new options to handle actions related to clients
* self registrations.
*/
if ($last_update < 412) {
$new_database_values = array(
'clients_auto_approve' => '0',
'clients_auto_group' => '0',
'clients_can_upload' => '1'
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r419 updates
* Add new options to customize the emails sent by the system.
*/
if ($last_update < 419) {
$new_database_values = array(
/**
* On or Off fields
* Each one corresponding to a type of email
*/
'email_new_file_by_user_customize' => '0',
'email_new_file_by_client_customize' => '0',
'email_new_client_by_user_customize' => '0',
'email_new_client_by_self_customize' => '0',
'email_new_user_customize' => '0',
/**
* Text fields
* Each one corresponding to a type of email
*/
'email_new_file_by_user_text' => '',
'email_new_file_by_client_text' => '',
'email_new_client_by_user_text' => '',
'email_new_client_by_self_text' => '',
'email_new_user_text' => ''
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r426 updates
* Add new options to customize the header and footer of emails.
*/
if ($last_update < 426) {
$new_database_values = array(
'email_header_footer_customize' => '0',
'email_header_text' => '',
'email_footer_text' => '',
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r442 updates
* Add new options to customize the header and footer of emails.
*/
if ($last_update < 442) {
$new_database_values = array(
'email_pass_reset_customize' => '0',
'email_pass_reset_text' => '',
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r464 updates
* New columns where added to the files table, to
* set expiry dates and download limit.
* Also, set a new option to hide or show expired
* files to clients.
*/
if ($last_update < 464) {
try {
$statement = $dbh->query("SELECT expires FROM " . TABLE_FILES);
} catch( PDOException $e ) {
$statement = $dbh->query("ALTER TABLE " . TABLE_FILES . " ADD expires INT(1) NOT NULL default '0'");
$statement = $dbh->query("ALTER TABLE " . TABLE_FILES . " ADD expiry_date TIMESTAMP NOT NULL");
$updates_made++;
}
$new_database_values = array(
'expired_files_hide' => '1',
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r474 updates
* A new database table was added.
* Each download will now be saved here, to distinguish
* individual downloads even if the origin is a group.
*/
if ($last_update < 474 ) {
if ( !table_exists( TABLE_DOWNLOADS ) ) {
$query = "
CREATE TABLE IF NOT EXISTS `" . TABLE_DOWNLOADS . "` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
`file_id` int(11) NOT NULL,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
FOREIGN KEY (`user_id`) REFERENCES " . TABLE_USERS . "(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`file_id`) REFERENCES " . TABLE_FILES . "(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
";
$statement = $dbh->prepare($query);
$statement->execute();
$updates_made++;
}
}
/**
* r475 updates
* New columns where added to the files table, to
* allow public downloads via a token.
*/
if ($last_update < 475) {
try {
$statement = $dbh->query("SELECT public_allow FROM " . TABLE_FILES);
} catch( PDOException $e ) {
$sql1 = $dbh->query("ALTER TABLE " . TABLE_FILES . " ADD public_allow INT(1) NOT NULL default '0'");
$sql2 = $dbh->query("ALTER TABLE " . TABLE_FILES . " ADD public_token varchar(32) NULL");
$updates_made++;
}
}
/**
* r487 updates
* Add new options to limit the retries of notifications emails
* and also set an expiry date.
*/
if ($last_update < 487) {
$new_database_values = array(
'notifications_max_tries' => '2',
'notifications_max_days' => '15',
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r490 updates
* Set foreign keys to update the notifications table automatically.
* Rows that references deleted users or files will be deleted
* before adding the keys.
*/
if ($last_update < 490) {
$statement = $dbh->query("DELETE FROM " . TABLE_NOTIFICATIONS . " WHERE file_id NOT IN (SELECT id FROM " . TABLE_FILES . ")");
$statement = $dbh->query("DELETE FROM " . TABLE_NOTIFICATIONS . " WHERE client_id NOT IN (SELECT id FROM " . TABLE_USERS . ")");
$statement = $dbh->query("ALTER TABLE " . TABLE_NOTIFICATIONS . " ADD FOREIGN KEY (`file_id`) REFERENCES " . TABLE_FILES . "(`id`) ON DELETE CASCADE ON UPDATE CASCADE");
$statement = $dbh->query("ALTER TABLE " . TABLE_NOTIFICATIONS . " ADD FOREIGN KEY (`client_id`) REFERENCES " . TABLE_USERS . "(`id`) ON DELETE CASCADE ON UPDATE CASCADE");
$updates_made++;
}
/**
* r501 updates
* Migrate the download count on each client to the new table.
*/
if ($last_update < 501) {
$statement = $dbh->query("SELECT * FROM " . TABLE_FILES_RELATIONS . " WHERE client_id IS NOT NULL AND download_count > 0");
if( $statement->rowCount() > 0 ) {
$downloads = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ( $downloads as $key => $row ) {
$download_count = $row['download_count'];
$client_id = $row['client_id'];
$file_id = $row['file_id'];
for ($i = 0; $i < $download_count; $i++) {
$statement = $dbh->prepare("INSERT INTO " . TABLE_DOWNLOADS . " (file_id, user_id) VALUES (:file_id, :client_id)");
$statement->bindParam(':file_id', $file_id, PDO::PARAM_INT);
$statement->bindParam(':client_id', $client_id, PDO::PARAM_INT);
$statement->execute();
}
}
$updates_made++;
}
}
/**
* r528 updates
* Add new options for email security, file types limits and
* requirements for passwords.
* and also set an expiry date.
*/
if ($last_update < 528) {
$new_database_values = array(
'file_types_limit_to' => 'all',
'pass_require_upper' => '0',
'pass_require_lower' => '0',
'pass_require_number' => '0',
'pass_require_special' => '0',
'mail_smtp_auth' => 'none'
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r557 updates
* Change the database collations
*/
if ($last_update < 557) {
$alter = [];
$statement = $dbh->exec('ALTER DATABASE ' . DB_NAME . ' CHARACTER SET utf8 COLLATE utf8_general_ci');
$statement = $dbh->query('SET foreign_key_checks = 0');
$statement = $dbh->query('SHOW TABLES');
$tables = $statement->fetchAll(PDO::FETCH_COLUMN);
foreach ( $tables as $key => $table ) {
$alter[$key] = $table;
}
foreach ( $alter as $key => $value ) {
$statement = $dbh->prepare("ALTER TABLE $value DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
$statement->execute();
}
$statement = $dbh->query('SET foreign_key_checks = 1');
$updates_made++;
}
/**
* r572 updates
* No DB changes
*/
if ($last_update < 572) {
$updates_made++;
}
/**
* r582 updates
* No DB changes
*/
if ($last_update < 582) {
$updates_made++;
}
/**
* r645 updates
* Added an option to use the browser language instead of
* the one on the config file.
*/
if ($last_update < 645) {
$new_database_values = array(
'use_browser_lang' => '0',
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r672 updates
* Added an option to allow clients to delete their own uploads
*/
if ($last_update < 672) {
$new_database_values = array(
'clients_can_delete_own_files' => '0',
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r674 updates
* Add the Google Sign in options to the database
*/
if ($last_update < 674) {
$new_database_values = array(
'google_client_id' => '',
'google_client_secret' => '',
'google_signin_enabled' => '0',
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r678 updates
* A new database table was added.
* Files categories.
*/
if ($last_update < 678) {
if ( !table_exists( TABLE_CATEGORIES ) ) {
$query = "
CREATE TABLE IF NOT EXISTS `".TABLE_CATEGORIES."` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
`parent` int(11) DEFAULT NULL,
`description` text NULL,
`created_by` varchar(".MAX_USER_CHARS.") NULL,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
FOREIGN KEY (`parent`) REFERENCES ".TABLE_CATEGORIES."(`id`) ON DELETE SET NULL ON UPDATE CASCADE,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
";
$statement = $dbh->prepare($query);
$statement->execute();
$updates_made++;
}
}
/**
* r680 updates
* A new database table was added.
* Relates files categories to files.
*/
if ($last_update < 680) {
if ( !table_exists( TABLE_CATEGORIES_RELATIONS ) ) {
$query = "
CREATE TABLE IF NOT EXISTS `".TABLE_CATEGORIES_RELATIONS."` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
`file_id` int(11) NOT NULL,
`cat_id` int(11) NOT NULL,
FOREIGN KEY (`file_id`) REFERENCES ".TABLE_FILES."(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`cat_id`) REFERENCES ".TABLE_CATEGORIES."(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
";
$statement = $dbh->prepare($query);
$statement->execute();
$updates_made++;
}
}
/**
* r737 updates
* Add the reCAPTCHA options to the database
*/
if ($last_update < 737) {
$new_database_values = array(
'recaptcha_enabled' => '0',
'recaptcha_site_key' => '',
'recaptcha_secret_key' => '',
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r738 updates
* New columns where added to the downloads table, to
* store the ip and hostname of the user, and a boolean
* field set to true for anonymous downloads (public files)
*/
if ($last_update < 738) {
try {
$statement = $dbh->query("SELECT remote_ip FROM " . TABLE_DOWNLOADS);
} catch( PDOException $e ) {
$statement = $dbh->query("ALTER TABLE " . TABLE_DOWNLOADS . " ADD remote_ip varchar(45) NULL");
$statement = $dbh->query("ALTER TABLE " . TABLE_DOWNLOADS . " ADD remote_host text NULL");
$statement = $dbh->query("ALTER TABLE " . TABLE_DOWNLOADS . " ADD anonymous tinyint(1) NULL");
$updates_made++;
}
}
/**
* r757 updates
* Add new options that clients can set expiration date when Uploaded New files
*/
if ($last_update < 757) {
$new_database_values = array(
'clients_can_set_expiration_date' => '0'
);
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r835 updates
* Uploaded files now save the filename twice on the database. The original filename (to
* use when downloading) and the filename on disk, so no 2 files with the same name exist.
*/
if ($last_update < 835) {
try {
$statement = $dbh->query("SELECT original_url FROM " . TABLE_FILES);
} catch( PDOException $e ) {
$sql1 = $dbh->query("ALTER TABLE " . TABLE_FILES . " ADD original_url TEXT NULL AFTER `url`");
$updates_made++;
}
}
/**
* r837 updates