Version 3.1.4
This commit is contained in:
1 parent
1d4720f3e2
commit
ae5c01cc78
2563 files changed
+283048
-240689
No files matched your search
@@ -1,18 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Invision Power Services
|
||||
* IP.Board v3.0.5
|
||||
* IP.Board v3.1.4
|
||||
* MySQL Database Diagnostic Methods
|
||||
* Last Updated: $Date: 2009-10-09 09:24:39 -0400 (Fri, 09 Oct 2009) $
|
||||
* Last Updated: $Date: 2010-10-18 16:58:05 -0400 (Mon, 18 Oct 2010) $
|
||||
* </pre>
|
||||
*
|
||||
* @author $Author: josh $
|
||||
* @author $Author: bfarber $
|
||||
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license http://www.iinvisionpower.com/community/board/license.html
|
||||
* @package Invision Power Services Kernel
|
||||
* @link http://www.iinvisionpower.com
|
||||
* @license http://www.invisionpower.com/community/board/license.html
|
||||
* @package IP.Board
|
||||
* @subpackage Kernel
|
||||
* @link http://www.invisionpower.com
|
||||
* @since Tuesday 1st March 2005 15:40
|
||||
* @version $Revision: 337 $
|
||||
* @version $Revision: 478 $
|
||||
*/
|
||||
|
||||
class db_tools
|
||||
@@ -87,7 +90,7 @@ class db_tools
|
||||
if ( preg_match( "#CREATE\s+TABLE\s+?(.+?)\s+?\(#ie", $definition, $tablename ) )
|
||||
{
|
||||
$tableName = $tablename[1];
|
||||
|
||||
|
||||
//-----------------------------------------
|
||||
// Does the table have a primary key?
|
||||
//-----------------------------------------
|
||||
@@ -138,50 +141,51 @@ class db_tools
|
||||
//-----------------------------------------
|
||||
// Now find all non-primary keys
|
||||
//-----------------------------------------
|
||||
|
||||
if ( preg_match_all( "#(?<!PRIMARY)\s*?KEY\s+?(?:(\w+?)\s+?)?\((.+?)\)(\n|,\n)#is", $definition, $fields ) )
|
||||
|
||||
if ( preg_match_all( "#\s+?(UNIQUE KEY|KEY|INDEX|UNIQUE)\s+?(?:(\w+?)\s+?)?\(\s*(.+?)\s*\)(\n|,\n)#is", $definition, $fields ) )
|
||||
{
|
||||
//-----------------------------------------
|
||||
// We got some fields!
|
||||
//-----------------------------------------
|
||||
|
||||
if( count( $fields[2] ) )
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
//-----------------------------------------
|
||||
// Loop over the data from the preg statement
|
||||
//-----------------------------------------
|
||||
|
||||
foreach( $fields[2] as $index_cols )
|
||||
{
|
||||
//-----------------------------------------
|
||||
// Get index name, column name, and store
|
||||
//-----------------------------------------
|
||||
|
||||
//$index_cols = implode( ",", array_map( 'trim', explode( ",", $this->_sqlStripTicks( preg_replace( "#\(([^\(]+?)\)#", "", $index_cols ) ) ) ) );
|
||||
$index_cols = implode( ",", array_map( 'trim', explode( ",", $this->_sqlStripTicks( $index_cols ) ) ) );
|
||||
$index_name = $fields[1][$i] ? $fields[1][$i] : $index_cols;
|
||||
|
||||
if( $index_cols != $final_primary[1] )
|
||||
{
|
||||
$final_keys[] = array( $index_name, $index_cols );
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( count( $fields[3] ) )
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
//-----------------------------------------
|
||||
// Loop over the data from the preg statement
|
||||
//-----------------------------------------
|
||||
|
||||
foreach( $fields[3] as $index_cols )
|
||||
{
|
||||
//-----------------------------------------
|
||||
// Get index name, column name, and store
|
||||
//-----------------------------------------
|
||||
|
||||
//$index_cols = implode( ",", array_map( 'trim', explode( ",", $this->_sqlStripTicks( preg_replace( "#\(([^\(]+?)\)#", "", $index_cols ) ) ) ) );
|
||||
$index_cols = implode( ",", array_map( 'trim', explode( ",", $this->_sqlStripTicks( $index_cols ) ) ) );
|
||||
|
||||
$index_name = $fields[2][$i] ? $fields[2][$i] : $index_cols;
|
||||
|
||||
if( $index_cols != $final_primary[1] )
|
||||
{
|
||||
$final_keys[] = array( $index_name, $index_cols, in_array( strtolower($fields[1][$i]), array( 'unique key', 'unique' ) ) ? true : false );
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
// We have some indexes for this table
|
||||
//-----------------------------------------
|
||||
|
||||
if( $tableName AND ( $primary_key OR count($final_keys) ) )
|
||||
{
|
||||
{
|
||||
$indexes[] = array( 'table' => $tableName,
|
||||
'primary' => $final_primary,
|
||||
'index' => $final_keys
|
||||
'index' => $final_keys,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -195,11 +199,11 @@ class db_tools
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------
|
||||
// Loop over the indexes
|
||||
//-----------------------------------------
|
||||
|
||||
|
||||
foreach( $indexes as $data )
|
||||
{
|
||||
//-----------------------------------------
|
||||
@@ -232,14 +236,20 @@ class db_tools
|
||||
// Can we find it...?
|
||||
//-----------------------------------------
|
||||
|
||||
if ( preg_match( "#\s*PRIMARY\s+?KEY\s*(\((.+?)\))?#is", $tbl, $matches ) )
|
||||
if ( preg_match( "#\s*PRIMARY\s+?KEY\s*(\(([^\)]+?)\))?#is", $tbl, $matches ) )
|
||||
{
|
||||
$ok = 1;
|
||||
|
||||
|
||||
if ( $matches[2] )
|
||||
{
|
||||
/* strip out white space so that def: key, key matches $index_cols which is always key,key */
|
||||
$matches[2] = str_replace( ' ', '', $matches[2] );
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
// It is...now is the index right (mulicolumn)?
|
||||
//-----------------------------------------
|
||||
|
||||
|
||||
if ( $index_cols != $matches[2] )
|
||||
{
|
||||
//-----------------------------------------
|
||||
@@ -339,18 +349,37 @@ class db_tools
|
||||
foreach( $data['index'] as $indexes )
|
||||
{
|
||||
$index_name = $indexes[0];
|
||||
$index_cols = $indexes[1] ? $indexes[1] : $index_name;
|
||||
$_checkName = $index_name;
|
||||
$index_cols = str_replace( ' ', '', $indexes[1] ? $indexes[1] : $index_name );
|
||||
|
||||
$ok = 0;
|
||||
|
||||
/* MySql seems to name multi-column indexes by the first field name regardless of what KEY NAME you specify. I know, nice isn't it. */
|
||||
if ( strstr( $index_cols, ',' ) AND ! preg_match( "#\n\s*?(?:UNIQUE KEY|KEY|INDEX|UNIQUE)\s+?{$_checkName}\s+?(\(\s*(.+?)\s*\))(\n|,\n)#is", $tbl, $match ) )
|
||||
{
|
||||
list( $_checkName, ) = explode( ',', $index_cols );
|
||||
|
||||
/* Now remove the xxxx(int) if it's there */
|
||||
if ( strstr( $_checkName, '(' ) )
|
||||
{
|
||||
$_checkName = preg_replace( "#^(.*)\(([^\)]+?)\)#", "\\1", $_checkName );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
// Is the key there?
|
||||
//-----------------------------------------
|
||||
|
||||
if ( preg_match( "#(?<!PRIMARY)\s+?KEY\s+?{$index_name}\s+?(\((.+?)\))(\n|,\n)#is", $tbl, $match ) )
|
||||
if ( preg_match( "#\n\s*?(?:UNIQUE KEY|KEY|INDEX|UNIQUE)\s+?{$_checkName}\s+?(\(\s*(.+?)\s*\))(\n|,\n)#is", $tbl, $match ) )
|
||||
{
|
||||
$ok = 1;
|
||||
|
||||
$ok = 1;
|
||||
|
||||
if ( $match[2] )
|
||||
{
|
||||
/* strip out white space so that def: key, key matches $index_cols which is always key,key */
|
||||
$match[2] = str_replace( ' ', '', $match[2] );
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
// It is...now is the index right (mulicolumn)?
|
||||
//-----------------------------------------
|
||||
@@ -369,7 +398,9 @@ class db_tools
|
||||
|
||||
if ( strpos( $match[2], str_replace(' ', '', $mc) ) === false )
|
||||
{
|
||||
$query_needed = 'ALTER TABLE ' . ipsRegistry::$settings['sql_tbl_prefix'] . $data['table'] . ' DROP INDEX ' . $index_name . ', ADD INDEX ' . $index_name . ' (' . $index_cols . ')';
|
||||
$_indexType = $indexes[2] ? "UNIQUE KEY" : "INDEX";
|
||||
|
||||
$query_needed = 'ALTER TABLE ' . ipsRegistry::$settings['sql_tbl_prefix'] . $data['table'] . ' DROP INDEX ' . $index_name . ', ADD ' . $_indexType . ' ' . $index_name . ' (' . $index_cols . ')';
|
||||
|
||||
//-----------------------------------------
|
||||
// Are we fixing now?
|
||||
@@ -402,7 +433,9 @@ class db_tools
|
||||
// Generate query and set the output array
|
||||
//-----------------------------------------
|
||||
|
||||
$query_needed = 'ALTER TABLE ' . ipsRegistry::$settings['sql_tbl_prefix'] . $data['table'] . ' ADD INDEX ' . $index_name . ' (' . $index_cols . ')';
|
||||
$_indexType = $indexes[2] ? "UNIQUE KEY" : "INDEX";
|
||||
|
||||
$query_needed = 'ALTER TABLE ' . ipsRegistry::$settings['sql_tbl_prefix'] . $data['table'] . ' ADD ' . $_indexType . ' ' . $index_name . ' (' . $index_cols . ')';
|
||||
|
||||
//-----------------------------------------
|
||||
// Are we fixing now?
|
||||
@@ -537,7 +570,7 @@ class db_tools
|
||||
// If this is a real column, map it
|
||||
//-----------------------------------------
|
||||
|
||||
if( !in_array( $columnName, array( "PRIMARY", "KEY", "UNIQUE", "", "(", ";", ");" ) ) )
|
||||
if( !in_array( $columnName, array( "PRIMARY", "KEY", "INDEX", "UNIQUE", "", "(", ";", ");" ) ) )
|
||||
{
|
||||
$expected_columns[] = $columnName;
|
||||
$this->_mapping[ $tableName ][ $columnName ] = trim( str_replace( ',', ';', $col ) );
|
||||
|
||||
Reference in new issue
Block a user