forked from projectsend/projectsend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.update.silent.php
149 lines (134 loc) · 4.55 KB
/
core.update.silent.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
<?php
/**
* This file includes updates that should be done regardless of the
* user / client status.
*/
global $updates_made;
/** Remove "r" from version */
$current_version = substr(CURRENT_VERSION, 1);
$statement = $dbh->prepare("SELECT value FROM " . TABLE_OPTIONS . " WHERE name = 'last_update'");
$statement->execute();
if ( $statement->rowCount() > 0 ) {
$statement->setFetchMode(PDO::FETCH_ASSOC);
while( $row = $statement->fetch() ) {
$last_update = $row['value'];
}
}
if ($last_update < $current_version || !isset($last_update)) {
/**
* r431 updates
* A new database table was added.
* Password reset support is now supported.
*/
if ($last_update < 431) {
if ( !table_exists( TABLE_PASSWORD_RESET ) ) {
$query = '
CREATE TABLE IF NOT EXISTS `' . TABLE_PASSWORD_RESET . '` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
`token` varchar(32) NOT NULL,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
`used` int(1) DEFAULT \'0\',
FOREIGN KEY (`user_id`) REFERENCES ' . TABLE_USERS . '(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
';
$dbh->query($query);
$updates_made++;
}
}
/**
* r437 updates
* A new database table was added.
* Password reset support is now supported.
*/
if ($last_update < 520) {
$q = $dbh->query("ALTER TABLE " . TABLE_USERS . " MODIFY user VARCHAR(".MAX_USER_CHARS.") NOT NULL");
$q2 = $dbh->query("ALTER TABLE " . TABLE_USERS . " MODIFY password VARCHAR(".MAX_PASS_CHARS.") NOT NULL");
if ($q && $q2) {
$updates_made++;
}
}
/**
* r1118 updates
* A new database table was added to store users meta data
*/
if ($last_update < 1118) {
if ( !table_exists( TABLE_USER_META ) ) {
$query = "
CREATE TABLE IF NOT EXISTS `".TABLE_USER_META."` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
`name` varchar(255) NOT NULL,
`value` TEXT NULL,
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
FOREIGN KEY (`user_id`) REFERENCES ".TABLE_USERS."(`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++;
}
}
/**
* r1270 updates
* Added meta updated time column and action log details column
*/
if ($last_update < 1270) {
$statement = $dbh->prepare("SHOW COLUMNS FROM `" . TABLE_USER_META . "` LIKE 'updated_at'");
try {
$statement->execute();
if (!$statement->fetchColumn()) {
$statement = $dbh->query("
ALTER TABLE `" . TABLE_USER_META . "` ADD COLUMN `updated_at` TIMESTAMP NULL DEFAULT NULL
");
}
} catch(PDOException $e){
//die($e->getMessage());
}
$updates_made++;
$statement = $dbh->prepare("SHOW COLUMNS FROM `" . TABLE_LOG . "` LIKE 'details'");
try {
$statement->execute();
if (!$statement->fetchColumn()) {
$statement = $dbh->query("ALTER TABLE `" . TABLE_LOG . "` ADD COLUMN `details` TEXT DEFAULT NULL after `affected_account_name`");
}
} catch(PDOException $e){
//die($e->getMessage());
}
$updates_made++;
}
/**
* r1271 updates
* Added download method option. Set according to XSendFile value
*/
if ($last_update < 1271) {
$download_method = 'php';
if (get_option('xsendfile_enable') == 1) {
$download_method = 'apache_xsendfile';
}
$new_database_values = [
'download_method' => $download_method,
];
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
/**
* r1275 updates
* Added download method option. Set according to XSendFile value
*/
if ($last_update < 1275) {
$new_database_values = [
'pagination_results_per_page' => 10,
];
foreach($new_database_values as $row => $value) {
if ( add_option_if_not_exists($row, $value) ) {
$updates_made++;
}
}
}
}