forked from toomanycurls/FanficTalk-Archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
403 lines (338 loc) · 12.3 KB
/
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
<?php
// ----------------------------------------------------------------------
// eFiction 3.0
// Copyright (c) 2007 by Tammy Keefer
// Valid HTML 4.01 Transitional
// Based on eFiction 1.1
// Copyright (C) 2003 by Rebecca Smallwood.
// http://efiction.sourceforge.net/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
$current = "update";
include("header.php");
$blocks['news']['status'] = 0;
$blocks['info']['status'] = 0;
//make a new TemplatePower object
if (file_exists("$skindir/default.tpl")) $tpl = new TemplatePower("$skindir/default.tpl");
else $tpl = new TemplatePower("default_tpls/default.tpl");
include("includes/pagesetup.php");
if (file_exists("languages/" . $language . "_admin.php")) include_once("languages/" . $language . "_admin.php");
else include_once("languages/en_admin.php");
// end basic page setup
if (!isADMIN)
{
$output .= "<script language=\"javascript\" type=\"text/javascript\">
location = \"maintenance.php\";
</script>";
$tpl->assign("output", $output);
$tpl->printToScreen();
dbclose();
exit();
}
$oldVersion = explode(".", $settings['version']);
if ($oldVersion[0] <= 3 && $oldVersion[1] <= 5 && $oldVersion[2] < 5)
{
header("Location: update355.php");
exit();
}
$set_355 = false;
$set_355 = do_version_check_355();
if($set_355) {
$output .= write_message("Table <b>" . $set_355 . "</b> needs a update.");
dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '3.5.5' WHERE sitekey = '" . SITEKEY . "'");
$settings['version'] = '3.5.5';
}
else {
$set_356 = do_version_check_356();
if ($set_356)
{
$output .= write_message("Table <b>" . $set_356 . "</b> needs a update.");
dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '3.5.6' WHERE sitekey = '" . SITEKEY . "'");
$settings['version'] = '3.5.6';
}
}
$oldVersion = explode(".", $settings['version']);
$confirm = isset($_GET['confirm']) ? $_GET['confirm'] : false;
if ($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 3))
{
write_message("This version is working only for 3.5.5 database. If you have only database, there is way how to do it.");
exit;
}
if ($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 6)) //3.5.5
{
if ($confirm == "yes")
{
if ($oldVersion[0] == 3 && $oldVersion[1] == 5 && $oldVersion[2] < 6)
{
// List of DB tables (key) and field (value) which need changing to accommodate datetime field
// List of DB tables (key) and field (value) which need changing date from datetime/timestamp to int
$date_upgrade = array(
array('table' => 'fanfiction_authors', 'field' => 'date'),
array(
'table' =>
'fanfiction_comments', 'field' => 'time'
),
array(
'table' =>
'fanfiction_reviews', 'field' => 'date'
),
array(
'table' =>
'fanfiction_stories', 'field' => 'date'
),
array(
'table' =>
'fanfiction_stories', 'field' => 'updated'
),
array(
'table' =>
'fanfiction_news', 'field' => 'time'
),
array(
'table' =>
'fanfiction_poll', 'field' => 'poll_start'
),
array(
'table' =>
'fanfiction_poll', 'field' => 'poll_end'
),
);
// Tables where IP address field needs updating to accommodate IPV6
// Set to varchar(45) - just in case something uses the IPV4 subnet (see http://en.wikipedia.org/wiki/IPV6#Notation)
foreach ($date_upgrade as $tmp)
{
$t = $tmp['table'];
$f = $tmp['field'];
if (isTable($t))
{
// Check for table - might add some core plugin tables in here
if ($field_info = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . $t . " LIKE '{$f}'")))
{
if (strtolower($field_info['Type']) == 'datetime')
{
$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . $t . " LIKE '{$f}_tmp'"));
if (!$updated)
{
dbquery("ALTER TABLE `" . TABLEPREFIX . $t . "` ADD `{$f}_tmp` int(10) unsigned NOT NULL default '0' ");
}
dbquery("UPDATE `" . TABLEPREFIX . $t . "` SET `{$f}_tmp` = UNIX_TIMESTAMP( `{$f}` )");
dbquery("ALTER TABLE `" . TABLEPREFIX . $t . "` CHANGE `{$f}` `{$f}` DATETIME NOT NULL)");
dbquery("ALTER TABLE `" . TABLEPREFIX . $t . "` CHANGE `{$f}` `{$f}` INT NOT NULL");
dbquery("UPDATE `" . TABLEPREFIX . $t . "` set {$f} = {$f}_tmp");
dbquery("ALTER TABLE `" . TABLEPREFIX . $t . "` DROP `{$f}_tmp`");
}
}
}
}
/****************************************************************************************************************/
$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_log LIKE 'log_timestamp'"));
if ($tmp['Type'] == "timestamp")
{
$updated = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_log LIKE 'log_timestamp_tmp'"));
if (!$updated)
{
dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_log` ADD `log_timestamp_tmp` int(10) unsigned NOT NULL default '0' ");
}
dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_log` SET `log_timestamp_tmp` = UNIX_TIMESTAMP( `log_timestamp` )");
dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_log` CHANGE `log_timestamp` `log_timestamp` INT NOT NULL");
dbquery("UPDATE `" . TABLEPREFIX . "fanfiction_log` set log_timestamp = log_timestamp_tmp");
dbquery("ALTER TABLE `" . TABLEPREFIX . "fanfiction_log` DROP `log_timestamp_tmp`");
}
$set_355 = false;
$set_355 = do_version_check_355();
if($set_355) {
$output .= write_error(_ERROR);
}
else {
$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '" . $version . "' WHERE sitekey = '" . SITEKEY . "'");
if ($update) $output .= write_message(_ACTIONSUCCESSFUL);
}
}
}
else if ($confirm == "no")
{
$output .= write_message(_ACTIONCANCELLED);
}
else
{
if ($oldVersion[0] == 3 && ($oldVersion[1] < 4 || $oldVersion[1] == 4 && (!isset($oldVersion[2]) || $oldVersion[2] < 6)))
$output .= write_message(_CONFIRMUPDATE . "<br /> <a href='update.php?confirm=yes'>" . _YES . "</a> " . _OR . " <a href='update.php?confirm=no'>" . _NO . "</a>");
else $output .= write_message("Are you ready to update? <a href='update.php?confirm=yes'>" . _YES . "</a> " . _OR . " <a href='update.php?confirm=no'>" . _NO . "</a>");
}
}
elseif ($oldVersion[0] == 3 && ($oldVersion[1] < 5 || $oldVersion[2] < 8)) //3.5.6 + 3.5.7
{
if ($confirm == "yes")
{
if ($oldVersion[0] == 3 && $oldVersion[1] == 5 && $oldVersion[2] < 7)
{
// List of DB tables (key) and field (value) which need changing to accommodate IPV6 addresses
$ip_upgrade = array(
'fanfiction_log' => 'log_ip',
'fanfiction_online' => 'online_ip'
);
// Tables where IP address field needs updating to accommodate IPV6
// Set to varchar(45) - just in case something uses the IPV4 subnet (see http://en.wikipedia.org/wiki/IPV6#Notation)
foreach ($ip_upgrade as $t => $f)
{
if (isTable($t))
{
// Check for table - might add some core plugin tables in here
if ($field_info = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . $t . " LIKE '{$f}'")))
{
//print_r($field_info);
if (strtolower($field_info['Type']) != 'VARBINARY(16)')
{
dbquery("ALTER TABLE `" . TABLEPREFIX . $t . "` MODIFY `$f` varbinary(16) DEFAULT NULL;");
}
}
}
}
}
$set_356 = false;
$set_356 = do_version_check_356();
if ($set_356)
{
$output .= write_error(_ERROR);
}
else
{
$update = dbquery("UPDATE " . $settingsprefix . "fanfiction_settings SET version = '" . $version . "' WHERE sitekey = '" . SITEKEY . "'");
if ($update) $output .= write_message(_ACTIONSUCCESSFUL);
}
}
else if ($confirm == "no")
{
$output .= write_message(_ACTIONCANCELLED);
}
else
{
if ($oldVersion[0] == 3 && ($oldVersion[1] < 4 || $oldVersion[1] == 4 && (!isset($oldVersion[2]) || $oldVersion[2] < 7)))
$output .= write_message(_CONFIRMUPDATE . "<br /> <a href='update.php?confirm=yes'>" . _YES . "</a> " . _OR . " <a href='update.php?confirm=no'>" . _NO . "</a>");
else $output .= write_message("Are you ready to update? <a href='update.php?confirm=yes'>" . _YES . "</a> " . _OR . " <a href='update.php?confirm=no'>" . _NO . "</a>");
}
}
else $output .= write_message(_ALREADYUPDATED);
/* until database is fully fixed, not update efiction version */
function do_version_check_355() {
global $fanfiction_poll_exists;
$check_355 = false;
// List of DB tables (key) and field (value) which need changing date from datetime/timestamp to int
$date_upgrade = array(
array('table'=>'fanfiction_authors', 'field' => 'date'),
array(
'table' =>
'fanfiction_comments', 'field' => 'time'),
array(
'table' =>
'fanfiction_reviews', 'field' => 'date'),
array(
'table' =>
'fanfiction_stories', 'field' => 'date'),
array(
'table' =>
'fanfiction_stories', 'field' => 'updated'),
array(
'table' =>
'fanfiction_news', 'field' => 'time'),
array(
'table' =>
'fanfiction_poll', 'field' => 'poll_start'),
array(
'table' =>
'fanfiction_poll', 'field' => 'poll_end'),
);
foreach ($date_upgrade as $tmp)
{
$t = $tmp['table'];
$f = $tmp['field'];
if (isTable($t))
{
// Check for table - might add some core plugin tables in here
if ($field_info = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . $t . " LIKE '{$f}'")))
{
// echo "<pre>";
// print_r($t);
// print_r($field_info);
// echo "</pre>";
if (strtolower($field_info['Type']) != 'int'
&& strtolower($field_info['Type']) != 'int(10)'
&& strtolower($field_info['Type']) != 'int(11)'
&& strtolower($field_info['Type']) != 'int unsigned'
&& strtolower($field_info['Type']) != 'int(10) unsigned')
{
// echo "<pre>"; print_r($field_info); echo "</pre>";
$check_355 = $t . " - field: " . $f;
return $check_355;
}
}
}
}
$tmp = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . "fanfiction_log LIKE 'log_timestamp'"));
if ($tmp['Type'] == "timestamp")
{
$check_355 = $t . " - field: " . $f;;
return $check_355;
}
return $check_355;
}
function do_version_check_356()
{
$check_356 = false;
// List of DB tables (key) and field (value) which need changing to accommodate IPV6 addresses
$ip_upgrade = array(
'fanfiction_log' => 'log_ip',
'fanfiction_online' => 'online_ip'
);
foreach ($ip_upgrade as $t => $f)
{
if (isTable($t))
{
// Check for table - might add some core plugin tables in here
if ($field_info = dbassoc(dbquery("SHOW COLUMNS FROM " . TABLEPREFIX . $t ." LIKE '{$f}'")) )
{
if (strtolower($field_info['Type']) != 'varbinary(16)')
{
$check_356 = $t . " - field: " . $f;;
return $check_356;
}
}
}
}
return $check_356;
}
$tpl->assign("output", $output);
$tpl->printToScreen();
dbclose();
// new functions for easier db manipulation 3.6.
function db_mySQLtableList()
{
global $debug, $dbconnect, $dbname, $settingsprefix;
$table = array();
if ($res = dbquery("SHOW TABLES FROM " . $dbname . " LIKE '" . $settingsprefix . "%' "))
$length = strlen($settingsprefix);
while ($rows = dbrow($res))
{
$t = substr($rows[0], $length);
$table[] = $t;
}
return $table;
}
function isTable($table)
{
$mySQLtableList = db_mySQLtableList();
return in_array($table, $mySQLtableList);
}