location = \"maintenance.php\"; "; $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 " . $set_355 . " 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 " . $set_356 . " 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 . "
" . _YES . " " . _OR . " " . _NO . ""); else $output .= write_message("Are you ready to update? " . _YES . " " . _OR . " " . _NO . ""); } } 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 . "
" . _YES . " " . _OR . " " . _NO . ""); else $output .= write_message("Are you ready to update? " . _YES . " " . _OR . " " . _NO . ""); } } 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 "
";
				// print_r($t);
				// print_r($field_info);
				// echo "
"; 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 "
"; print_r($field_info); echo "
"; $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); }