|
From: Bart v. B. <ba...@us...> - 2001-11-24 21:04:55
|
Update of /cvsroot/phpbb/phpBB2
In directory usw-pr-cvs1:/tmp/cvs-serv15816
Modified Files:
upgrade.php install.php
Log Message:
Upgrade script; updating keys, using table_prefix properly
Index: upgrade.php
===================================================================
RCS file: /cvsroot/phpbb/phpBB2/upgrade.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** upgrade.php 2001/11/09 15:02:46 1.3
--- upgrade.php 2001/11/24 21:04:51 1.4
***************
*** 29,36 ****
include('includes/constants.'.$phpEx);
}
include('includes/db.'.$phpEx);
include('includes/bbcode.'.$phpEx);
! set_time_limit(20*60); // Increase maximum execution time to 20 minutes.
$months = array(
--- 29,38 ----
include('includes/constants.'.$phpEx);
}
+ // Force the DB type to be MySQL
+ $dbms = 'mysql';
include('includes/db.'.$phpEx);
include('includes/bbcode.'.$phpEx);
! set_time_limit(0); // Unlimited execution time
$months = array(
***************
*** 95,101 ****
function get_schema()
{
! $schemafile = file('db/mysql_schema.sql');
$tabledata = 0;
- $pattern = "/^\s*(\w+)\s+(\w+)\((\d+)\)(.*)$/";
for($i=0; $i < count($schemafile); $i++)
{
--- 97,103 ----
function get_schema()
{
! global $table_prefix;
! $schemafile = file('db/schemas/mysql_schema.sql');
$tabledata = 0;
for($i=0; $i < count($schemafile); $i++)
{
***************
*** 103,113 ****
if(preg_match("/^CREATE TABLE (\w+)/i", $line, $matches))
{
$tabledata = 1;
! $table = $matches[1];
! $table_def[$table] = $line;
continue;
}
if(preg_match("/^\);/", $line))
{
$tabledata = 0;
$table_def[$table] .= ")"; // We don't need the closing semicolon
--- 105,119 ----
if(preg_match("/^CREATE TABLE (\w+)/i", $line, $matches))
{
+ // Start of a new table definition, set some variables and go to the next line.
$tabledata = 1;
! // Replace the 'phpbb_' prefix by the user defined prefix.
! $table = str_replace("phpbb_", $table_prefix, $matches[1]);
! $table_def[$table] = "CREATE TABLE $table (\n";
continue;
}
if(preg_match("/^\);/", $line))
{
+ // End of the table definition
+ // After this we will skip everything until the next 'CREATE' line
$tabledata = 0;
$table_def[$table] .= ")"; // We don't need the closing semicolon
***************
*** 115,153 ****
if($tabledata == 1)
{
$table_def[$table] .= $line;
! preg_match($pattern, $line, $matches);
! $i%2 == 1 ? $color = "#FF0000" : $color = "#0000FF";
! $field = $matches[1];
! $type = $matches[2];
! $size = $matches[3];
! preg_match("/DEFAULT (NULL|\'.*?\')[,\s](.*)$/i", $matches[4], $match);
! $default = $match[1];
! preg_match("/NOT NULL/i", $matches[4]) ? $notnull = 1 : $notnull =0;
! preg_match("/auto_increment/i", $matches[4]) ? $auto_increment = 1 : $auto_increment =0;
! /*
! print "<font color = $color>\n";
! print "$line<br>\n";
! print "$field $type($size)";
! if (isset($default)){
! print " DEFAULT $default";
! }
! if ($notnull == 1)
! {
! print " NOT NULL";
! }
! if ($auto_increment == 1)
! {
! print " auto_increment";
! }
! print "<br>\n";
! print "<font>\n";
! */
! $field_def[$table][$field] = array(
! 'type' => $type,
! 'size' => $size,
! 'default' => $default,
! 'notnull' => $notnull,
! 'auto_increment' => $auto_increment
);
}
}
--- 121,185 ----
if($tabledata == 1)
{
+ // We are inside a table definition, parse this line.
+ // Add the current line to the complete table definition:
$table_def[$table] .= $line;
! if(preg_match("/^\s*(\w+)\s+(\w+)\((\d+)\)(.*)$/", $line, $matches))
! {
! // This is a column definition
! $field = $matches[1];
! $type = $matches[2];
! $size = $matches[3];
! preg_match("/DEFAULT (NULL|\'.*?\')[,\s](.*)$/i", $matches[4], $match);
! $default = $match[1];
! preg_match("/NOT NULL/i", $matches[4]) ? $notnull = 1 : $notnull =0;
! preg_match("/auto_increment/i", $matches[4]) ? $auto_increment = 1 : $auto_increment = 0;
! /*
! $i%2 == 1 ? $color = "#FF0000" : $color = "#0000FF";
! print "<font color = $color>\n";
! print "$line<br>\n";
! print "$field $type($size)";
! if (isset($default)){
! print " DEFAULT $default";
! }
! if ($notnull == 1)
! {
! print " NOT NULL";
! }
! if ($auto_increment == 1)
! {
! print " auto_increment";
! }
! print "<br>\n";
! print "<font>\n";
! */
! $field_def[$table][$field] = array(
! 'type' => $type,
! 'size' => $size,
! 'default' => $default,
! 'notnull' => $notnull,
! 'auto_increment' => $auto_increment
);
+ }
+
+ if(preg_match("/\s*PRIMARY\s+KEY\s*\((.*)\).*/", $line, $matches))
+ {
+ // Primary key
+ $key_def[$table]['PRIMARY'] = $matches[1];
+ }
+ else if(preg_match("/\s*KEY\s+(\w+)\s*\((.*)\)/", $line, $matches))
+ {
+ // Normal key
+ $key_def[$table][$matches[1]] = $matches[2];
+ }
+ else if(preg_match("/^\s*(\w+)\s*(.*?),?\s*$/", $line, $matches))
+ {
+ // Column definition
+ $create_def[$table][$matches[1]] = $matches[2];
+ }
+ else
+ {
+ print "$line<br>";
+ // It's a bird! It's a plane! It's something we didn't expect ;(
+ }
}
}
***************
*** 159,162 ****
--- 191,196 ----
$schema['field_def'] = $field_def;
$schema['table_def'] = $table_def;
+ $schema['create_def'] = $create_def;
+ $schema['key_def'] = $key_def;
return $schema;
}
***************
*** 164,171 ****
function get_inserts()
{
! $insertfile = file("db/mysql_basic.sql");
for($i=0; $i < count($insertfile); $i++)
{
! if (preg_match("/^(.*INSERT INTO (.*?)\s.*);$/i", $insertfile[$i], $matches))
{
$returnvalue[$matches[2]][] = $matches[1];
--- 198,206 ----
function get_inserts()
{
! global $table_prefix;
! $insertfile = file("db/schemas/mysql_basic.sql");
for($i=0; $i < count($insertfile); $i++)
{
! if (preg_match("/^(.*INSERT INTO (.*?)\s.*);$/i", str_replace("phpbb_", $table_prefix, $insertfile[$i]), $matches))
{
$returnvalue[$matches[2]][] = $matches[1];
***************
*** 297,300 ****
--- 332,350 ----
$debug=1;
+ // Parse the MySQL schema file into some arrays.
+ $schema = get_schema();
+ $table_def = $schema['table_def'];
+ $field_def = $schema['field_def'];
+ $key_def = $schema['key_def'];
+ $create_def = $schema['create_def'];
+
+ /*
+ print "tables:<br>";
+ print_r($table_def);
+ print "create:<br>";
+ print_r($create_def);
+ die;
+ */
+
if(isset($next))
{
***************
*** 306,320 ****
$sql = "DROP TABLE sessions";
query($sql, "Couldn't drop table 'sessions'");
! end_step('rename_tables');
! case 'rename_tables':
common_header();
echo "<H2>Step 2: Rename tables</H2>\n";
! $newnames = array(
"banlist" => "banlist",
"catagories" => "categories",
! // Don't rename config yet, we'll create a new one and merge those later.
! //"config" => "config",
"forums" => "forums",
"disallow" => "disallow",
--- 356,371 ----
$sql = "DROP TABLE sessions";
query($sql, "Couldn't drop table 'sessions'");
! $sql = "DROP TABLE themes";
! query($sql, "Couldn't drop table 'themes'");
! end_step('mod_old_tables');
! case 'mod_old_tables':
common_header();
echo "<H2>Step 2: Rename tables</H2>\n";
! $modtables = array(
"banlist" => "banlist",
"catagories" => "categories",
! "config" => "old_config",
"forums" => "forums",
"disallow" => "disallow",
***************
*** 323,346 ****
"priv_msgs" => "privmsgs",
"ranks" => "ranks",
- "sessions" => "sessions",
"smiles" => "smilies",
"topics" => "topics",
"users" => "users",
"words" => "words"
! );
! while(list($old, $new) = each($newnames))
{
! $new = $table_prefix . $new;
! $sql = "ALTER TABLE $old RENAME $new";
! if(!$result = $db->sql_query($sql))
! {
! echo "Couldn't rename '$old' to '$new'<br>\n";
! $sql_error = $db->sql_error();
! print $sql_error['code'] .": ". $sql_error['message']. "<br>\n";
! }
! else
{
! print "Renamed '$old' to '$new'<br>\n";
}
}
common_footer();
--- 374,401 ----
"priv_msgs" => "privmsgs",
"ranks" => "ranks",
"smiles" => "smilies",
"topics" => "topics",
"users" => "users",
"words" => "words"
! );
! while(list($old, $new) = each($modtables))
{
! $sql = "SHOW INDEX FROM $old";
! $result = query($sql, "Couldn't get list of indices for table $old");
! while($row = mysql_fetch_array($result))
{
! $index = $row['Key_name'];
! if($index != 'PRIMARY')
! {
! query("ALTER TABLE $old DROP INDEX $index", "Couldn't DROP INDEX $old.$index");
! }
}
+
+ // Rename table
+ $new = $table_prefix . $new;
+ $sql = "ALTER TABLE $old RENAME $new";
+ print "Renaming '$old' to '$new'<br>\n";
+ query($sql, "Failed to rename $old to $new");
+
}
common_footer();
***************
*** 351,366 ****
echo "<H2>Step 2: Create new phpBB2 tables</H2>\n";
- $schema = get_schema();
- $table_def = $schema['table_def'];
- $field_def = $schema['field_def'];
-
// Create array with tables in 'old' database
$sql = 'SHOW TABLES';
! if(!$result = $db->sql_query($sql))
! {
! echo "Couldn't get list of current tables<br>\n";
! $sql_error = $db->sql_error();
! print $sql_error['code'] .": ". $sql_error['message']. "<br>\n";
! }
while ($table = $db->sql_fetchrow($result))
{
--- 406,412 ----
echo "<H2>Step 2: Create new phpBB2 tables</H2>\n";
// Create array with tables in 'old' database
$sql = 'SHOW TABLES';
! $result = query($sql, "Couldn't get list of current tables");
while ($table = $db->sql_fetchrow($result))
{
***************
*** 371,382 ****
while (list($table, $definition) = each ($table_def))
{
if (!inarray($table, $currenttables))
{
print "Creating $table: ";
! if(!$result = $db->sql_query($definition))
{
! echo "Couldn't create table<br>\n";
! $sql_error = $db->sql_error();
! print $sql_error['code'] .": ". $sql_error['message']. "<br>\n";
print $definition . "<br>\n";
}
--- 417,428 ----
while (list($table, $definition) = each ($table_def))
{
+ print "<font color='green'>Table: $table</font><br>";
if (!inarray($table, $currenttables))
{
print "Creating $table: ";
! $result = query($definition, "Couldn't create table $table");
! if($db->sql_affectedrows($result) < 1)
{
! echo "Couldn't create table (no affected rows)<br>\n";
print $definition . "<br>\n";
}
***************
*** 407,410 ****
--- 453,457 ----
}
}
+ print "New config table has been created with default values.<p>\n";
//end_step('convert_config');
***************
*** 412,416 ****
common_header();
print "Starting!<br>";
! $sql = "SELECT * FROM config";
$result = query($sql, "Couldn't get info from old config table");
$oldconfig = $db->sql_fetchrow($result);
--- 459,463 ----
common_header();
print "Starting!<br>";
! $sql = "SELECT * FROM $table_prefix"."old_config";
$result = query($sql, "Couldn't get info from old config table");
$oldconfig = $db->sql_fetchrow($result);
***************
*** 521,524 ****
--- 568,573 ----
$sql = "SELECT * from ". USERS_TABLE. " WHERE user_id BETWEEN $batchstart AND $batchend";
$result = query($sql, "Couldn't get ". USERS_TABLE .".user_id $batchstart to $batchend");
+
+ // Array with user fields that we want to check for invalid data (to few characters)
$checklength = array(
'user_occ',
***************
*** 913,926 ****
// If the current is not a key of $current_def and it is not a field that is
// to be renamed then the field doesn't currently exist.
! $changes[] = "\nADD $field $type($size) $default $notnull $auto_increment ";
}
else
{
! $changes[] = "\nCHANGE $oldfield $field $type($size) $default $notnull $auto_increment";
}
}
$alter_sql .= join(',', $changes);
unset($changes);
unset($current_fields);
print "$alter_sql<br>\n";
query($alter_sql, "Couldn't alter table $table");
--- 962,994 ----
// If the current is not a key of $current_def and it is not a field that is
// to be renamed then the field doesn't currently exist.
! //$changes[] = "\nADD $field $type($size) $default $notnull $auto_increment ";
! $changes[] = "\nADD $field ". $create_def[$table][$field];
}
else
{
! //$changes[] = "\nCHANGE $oldfield $field $type($size) $default $notnull $auto_increment";
! $changes[] = "\nCHANGE $oldfield $field ". $create_def[$table][$field];
}
}
+
$alter_sql .= join(',', $changes);
unset($changes);
unset($current_fields);
+
+ $sql = "SHOW INDEX FROM $table";
+ $result = query($sql, "Couldn't get list of indices for table $table");
+ unset($indices);
+ while($row = mysql_fetch_array($result))
+ {
+ $indices[] = $row['Key_name'];
+ }
+
+ while (list($key_name, $key_field) = each($key_def[$table]) )
+ {
+ if(!inarray($key_name, $indices))
+ {
+ $alter_sql .= ($key_name == 'PRIMARY') ? ",\nADD PRIMARY KEY ($key_field)" : ",\nADD INDEX $key_name ($key_field)";
+ }
+ }
print "$alter_sql<br>\n";
query($alter_sql, "Couldn't alter table $table");
Index: install.php
===================================================================
RCS file: /cvsroot/phpbb/phpBB2/install.php,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** install.php 2001/11/20 22:31:58 1.15
--- install.php 2001/11/24 21:04:51 1.16
***************
*** 433,436 ****
--- 433,437 ----
// for the odbc DBMS.
//
+ print "dbms = - $dbms -<br>";
if( isset($dbms) )
{
|