1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-20 04:32:01 +02:00

Part of bugtracker #4069 - DB updates to allow for IPV6

This commit is contained in:
e107steved 2007-09-22 21:46:23 +00:00
parent 402940382b
commit 71c83e3cb2
5 changed files with 95 additions and 92 deletions

View File

@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_admin/sql/core_sql.php,v $
| $Revision: 1.2 $
| $Date: 2007-09-22 20:32:31 $
| $Revision: 1.3 $
| $Date: 2007-09-22 21:46:09 $
| $Author: e107steved $
+----------------------------------------------------------------------------+
*/
@ -83,7 +83,7 @@ CREATE TABLE comments (
comment_datestamp int(10) unsigned NOT NULL default '0',
comment_comment text NOT NULL,
comment_blocked tinyint(3) unsigned NOT NULL default '0',
comment_ip varchar(20) NOT NULL default '',
comment_ip varchar(45) NOT NULL default '',
comment_type varchar(10) NOT NULL default '0',
comment_lock tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (comment_id)
@ -183,7 +183,7 @@ CREATE TABLE download_mirror (
CREATE TABLE download_requests (
download_request_id int(10) unsigned NOT NULL auto_increment,
download_request_userid int(10) unsigned NOT NULL default '0',
download_request_ip varchar(30) NOT NULL default '',
download_request_ip varchar(45) NOT NULL default '',
download_request_download_id int(10) unsigned NOT NULL default '0',
download_request_datestamp int(10) unsigned NOT NULL default '0',
PRIMARY KEY (download_request_id),
@ -278,7 +278,7 @@ CREATE TABLE online (
online_timestamp int(10) unsigned NOT NULL default '0',
online_flag tinyint(3) unsigned NOT NULL default '0',
online_user_id varchar(100) NOT NULL default '',
online_ip varchar(15) NOT NULL default '',
online_ip varchar(45) NOT NULL default '',
online_location varchar(100) NOT NULL default '',
online_pagecount tinyint(3) unsigned NOT NULL default '0',
online_active int(10) unsigned NOT NULL default '0'
@ -390,7 +390,7 @@ CREATE TABLE submitnews (
submitnews_category tinyint(3) unsigned NOT NULL default '0',
submitnews_item text NOT NULL,
submitnews_datestamp int(10) unsigned NOT NULL default '0',
submitnews_ip varchar(15) NOT NULL default '',
submitnews_ip varchar(45) NOT NULL default '',
submitnews_auth tinyint(3) unsigned NOT NULL default '0',
submitnews_file varchar(100) NOT NULL default '',
PRIMARY KEY (submitnews_id)
@ -402,7 +402,7 @@ CREATE TABLE submitnews (
#
CREATE TABLE tmp (
tmp_ip varchar(20) NOT NULL default '',
tmp_ip varchar(45) NOT NULL default '',
tmp_time int(10) unsigned NOT NULL default '0',
tmp_info text NOT NULL,
KEY tmp_ip (tmp_ip)
@ -457,7 +457,7 @@ CREATE TABLE user (
user_chats int(10) unsigned NOT NULL default '0',
user_comments int(10) unsigned NOT NULL default '0',
user_forums int(10) unsigned NOT NULL default '0',
user_ip varchar(20) NOT NULL default '',
user_ip varchar(45) NOT NULL default '',
user_ban tinyint(3) unsigned NOT NULL default '0',
user_prefs text NOT NULL,
user_new text NOT NULL,

View File

@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_admin/update_routines.php,v $
| $Revision: 1.9 $
| $Date: 2007-09-22 20:32:31 $
| $Revision: 1.10 $
| $Date: 2007-09-22 21:46:09 $
| $Author: e107steved $
+----------------------------------------------------------------------------+
*/
@ -27,6 +27,7 @@ require_once("../class2.php");
// To do - how do we handle multi-language tables?
$update_debug = FALSE; // TRUE gives extra messages in places
if (!defined("LAN_UPDATE_8")) { define("LAN_UPDATE_8", ""); }
@ -85,39 +86,6 @@ foreach ($dbupdateplugs as $path => $ver)
}
/*
if($sql->db_Select("plugin", "plugin_version", "plugin_path = 'forum' AND plugin_installflag='1' ")) {
if(file_exists(e_PLUGIN.'forum/forum_update_check.php'))
{
include_once(e_PLUGIN.'forum/forum_update_check.php');
}
}
if (mysql_table_exists("stat_info") && $sql -> db_Select("plugin", "*", "plugin_path = 'log' AND plugin_installflag='1'")) {
if(file_exists(e_PLUGIN.'log/log_update_check.php'))
{
include_once(e_PLUGIN.'log/log_update_check.php');
}
}
//content
if($sql->db_Select("plugin", "plugin_version", "plugin_path = 'content' AND plugin_installflag='1' "))
{
if(file_exists(e_PLUGIN.'content/content_update_check.php'))
{
include_once(e_PLUGIN.'content/content_update_check.php');
}
}
if($sql->db_Select("plugin", "plugin_version", "plugin_path = 'pm' AND plugin_installflag='1' "))
{
if(file_exists(e_PLUGIN.'pm/pm_update_check.php'))
{
include_once(e_PLUGIN.'pm/pm_update_check.php');
}
}
*/
// List of potential updates
$dbupdate["core_prefs"] = LAN_UPDATE_13; // Prefs check
$dbupdate["706_to_800"] = LAN_UPDATE_8." .706 ".LAN_UPDATE_9." .8";
@ -218,6 +186,16 @@ function update_706_to_800($type='')
// List of DB tables not required (includes a few from 0.6xx)
$obs_tables = array('flood', 'headlines', 'stat_info', 'stat_counter', 'stat_last');
// List of DB tables (key) and field (value) which need changing to accommodate IPV6 addresses
$ip_upgrade = array('comments' => 'comment_ip',
'download_requests' => 'download_request_ip',
'online' => 'online_ip',
'submitnews' => 'submitnews_ip',
'tmp' => 'tmp_ip',
'user' => 'user_ip',
'chatbox' => 'cb_ip'
);
$do_save = FALSE;
$just_check = $type == 'do' ? FALSE : TRUE; // TRUE if we're just seeing if an update is needed
@ -334,10 +312,33 @@ function update_706_to_800($type='')
{
if (mysql_table_exists($ot))
{
if ($just_check) return update_needed();
if ($just_check) return update_needed("Delete table: ".$ot);
mysql_query('DROP TABLE `'.MPREFIX.$ot.'`');
}
}
// 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 (mysql_table_exists($t))
{ // Check for table - might add some core plugin tables in here
if ($field_info = ($sql->db_Field($t, $f, '', TRUE)))
{
if (strtolower($field_info['Type']) != 'varchar(45)')
{
if ($just_check) return update_needed('Update field '.$f.' in table '.$t);
mysql_query("ALTER TABLE `".MPREFIX.$t."` MODIFY `{$f}` VARCHAR( 45 ) NOT NULL DEFAULT '';");
catch_error();
}
}
else
{
// Got a strange error here
}
}
}
if ($do_save) save_prefs();
@ -429,9 +430,10 @@ function update_70x_to_706($type='')
}
function update_needed()
function update_needed($message='')
{
global $ns;
global $ns, $update_debug;
if ($update_debug) echo "Update: ".$message."<br />";
if(E107_DEBUG_LEVEL)
{
$tmp = debug_backtrace();
@ -440,6 +442,7 @@ function update_needed()
return FALSE;
}
function mysql_table_exists($table)
{
$exists = mysql_query("SELECT 1 FROM ".MPREFIX."$table LIMIT 0");

View File

@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
| $Revision: 1.17 $
| $Date: 2007-08-08 21:01:46 $
| $Revision: 1.18 $
| $Date: 2007-09-22 21:46:16 $
| $Author: e107steved $
|
+----------------------------------------------------------------------------+
@ -30,7 +30,7 @@ $db_ConnectionID = NULL;
* MySQL Abstraction class
*
* @package e107
* @version $Revision: 1.17 $
* @version $Revision: 1.18 $
* @author $Author: e107steved $
*/
class db {
@ -739,49 +739,49 @@ class db {
}
// Determines if a plugin field (and key) exist. OR if fieldid is numeric - return the field name in that position.
function db_Field($table,$fieldid="",$key=""){
if(!$this->mySQLdefaultdb){
global $mySQLdefaultdb;
$this->mySQLdefaultdb = $mySQLdefaultdb;
}
$convert = array("PRIMARY"=>"PRI","INDEX"=>"MUL","UNIQUE"=>"UNI");
$key = ($convert[$key]) ? $convert[$key] : "OFF";
// If $retinfo is true, returns complete array of field data; FALSE if not found
function db_Field($table,$fieldid="",$key="", $retinfo = FALSE)
{
if(!$this->mySQLdefaultdb)
{
global $mySQLdefaultdb;
$this->mySQLdefaultdb = $mySQLdefaultdb;
}
$convert = array("PRIMARY"=>"PRI","INDEX"=>"MUL","UNIQUE"=>"UNI");
$key = ($convert[$key]) ? $convert[$key] : "OFF";
if(!$this->mySQLaccess)
{
global $db_ConnectionID;
$this->mySQLaccess = $db_ConnectionID;
}
if(!$this->mySQLaccess)
{
global $db_ConnectionID;
$this->mySQLaccess = $db_ConnectionID;
}
$result = mysql_query("SHOW COLUMNS FROM ".MPREFIX.$table,$this->mySQLaccess);
if (mysql_num_rows($result) > 0) {
$c=0;
while ($row = mysql_fetch_assoc($result)) {
if(is_numeric($fieldid))
{
if($c == $fieldid)
{
return $row['Field']; // field number matches.
}
}
else
{
if(($key == "OFF") && ($fieldid == $row['Field']))
{
return TRUE; // key not in use, but field matches.
}
elseif(($fieldid == $row['Field']) && $key == $row['Key'])
{
return TRUE;
}
}
$c++;
}
if (mysql_num_rows($result) > 0)
{
$c=0;
while ($row = mysql_fetch_assoc($result))
{
if(is_numeric($fieldid))
{
if($c == $fieldid)
{
if ($retinfo) return $row;
return $row['Field']; // field number matches.
}
}
else
{ // Check for match of key name - and allow that key might not be used
if(($fieldid == $row['Field']) && (($key == "OFF") || ($key == $row['Key'])))
{
if ($retinfo) return $row;
return TRUE;
}
}
$c++;
}
}
return FALSE;
}
/**

View File

@ -4,6 +4,6 @@ CREATE TABLE chatbox (
cb_message text NOT NULL,
cb_datestamp int(10) unsigned NOT NULL default '0',
cb_blocked tinyint(3) unsigned NOT NULL default '0',
cb_ip varchar(15) NOT NULL default '',
cb_ip varchar(45) NOT NULL default '',
PRIMARY KEY (cb_id)
) TYPE=MyISAM;

View File

@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/chatbox_menu/plugin.php,v $
| $Revision: 1.1.1.1 $
| $Date: 2006-12-02 04:34:51 $
| $Author: mcfly_e107 $
| $Revision: 1.2 $
| $Date: 2007-09-22 21:46:23 $
| $Author: e107steved $
+----------------------------------------------------------------------------+
*/
@ -68,7 +68,7 @@ $eplug_tables = array(
cb_message text NOT NULL,
cb_datestamp int(10) unsigned NOT NULL default '0',
cb_blocked tinyint(3) unsigned NOT NULL default '0',
cb_ip varchar(15) NOT NULL default '',
cb_ip varchar(45) NOT NULL default '',
PRIMARY KEY (cb_id)
) TYPE=MyISAM;"
);