|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
* @package install
|
|
|
4c79b5 |
* @version $Id: database_update.php 9187 2008-12-12 14:47:03Z acydburn $
|
|
|
4c79b5 |
* @copyright (c) 2006 phpBB Group
|
|
|
4c79b5 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
4c79b5 |
*
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$updates_to_version = '3.0.4';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Return if we "just include it" to find out for which version the database update is responsible for
|
|
|
4c79b5 |
if (defined('IN_PHPBB') && defined('IN_INSTALL'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
define('IN_PHPBB', true);
|
|
|
4c79b5 |
define('IN_INSTALL', true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
|
|
|
4c79b5 |
$phpEx = substr(strrchr(__FILE__, '.'), 1);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Report all errors, except notices
|
|
|
4c79b5 |
//error_reporting(E_ALL ^ E_NOTICE);
|
|
|
4c79b5 |
error_reporting(E_ALL);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
@set_time_limit(0);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Include essential scripts
|
|
|
4c79b5 |
include($phpbb_root_path . 'config.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
die("Please read: INSTALL.html before attempting to update.");
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Load Extensions
|
|
|
4c79b5 |
if (!empty($load_extensions))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$load_extensions = explode(',', $load_extensions);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($load_extensions as $extension)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@dl(trim($extension));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Include files
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/cache.' . $phpEx);
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/template.' . $phpEx);
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/session.' . $phpEx);
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/auth.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (file_exists($phpbb_root_path . 'includes/functions_content.' . $phpEx))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/functions_content.' . $phpEx);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// If we are on PHP >= 6.0.0 we do not need some code
|
|
|
4c79b5 |
if (version_compare(PHP_VERSION, '6.0.0-dev', '>='))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* @ignore
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
define('STRIP', false);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@set_magic_quotes_runtime(0);
|
|
|
4c79b5 |
define('STRIP', (get_magic_quotes_gpc()) ? true : false);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$user = new user();
|
|
|
4c79b5 |
$cache = new cache();
|
|
|
4c79b5 |
$db = new $sql_db();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Add own hook handler, if present. :o
|
|
|
4c79b5 |
if (file_exists($phpbb_root_path . 'includes/hooks/index.' . $phpEx))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
|
|
|
4c79b5 |
$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($cache->obtain_hooks() as $hook)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
@include($phpbb_root_path . 'includes/hooks/' . $hook . '.' . $phpEx);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$phpbb_hook = false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Connect to DB
|
|
|
4c79b5 |
$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// We do not need this any longer, unset for safety purposes
|
|
|
4c79b5 |
unset($dbpasswd);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$user->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT config_value
|
|
|
4c79b5 |
FROM " . CONFIG_TABLE . "
|
|
|
4c79b5 |
WHERE config_name = 'default_lang'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$language = basename(request_var('language', ''));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$language)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$language = $row['config_value'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!file_exists($phpbb_root_path . 'language/' . $language))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
die('No language found!');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// And finally, load the relevant language files
|
|
|
4c79b5 |
include($phpbb_root_path . 'language/' . $language . '/common.' . $phpEx);
|
|
|
4c79b5 |
include($phpbb_root_path . 'language/' . $language . '/acp/common.' . $phpEx);
|
|
|
4c79b5 |
include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Set PHP error handler to ours
|
|
|
4c79b5 |
//set_error_handler('msg_handler');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Define some variables for the database update
|
|
|
4c79b5 |
$inline_update = (request_var('type', 0)) ? true : false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Database column types mapping
|
|
|
4c79b5 |
$dbms_type_map = array(
|
|
|
4c79b5 |
'mysql_41' => array(
|
|
|
4c79b5 |
'INT:' => 'int(%d)',
|
|
|
4c79b5 |
'BINT' => 'bigint(20)',
|
|
|
4c79b5 |
'UINT' => 'mediumint(8) UNSIGNED',
|
|
|
4c79b5 |
'UINT:' => 'int(%d) UNSIGNED',
|
|
|
4c79b5 |
'TINT:' => 'tinyint(%d)',
|
|
|
4c79b5 |
'USINT' => 'smallint(4) UNSIGNED',
|
|
|
4c79b5 |
'BOOL' => 'tinyint(1) UNSIGNED',
|
|
|
4c79b5 |
'VCHAR' => 'varchar(255)',
|
|
|
4c79b5 |
'VCHAR:' => 'varchar(%d)',
|
|
|
4c79b5 |
'CHAR:' => 'char(%d)',
|
|
|
4c79b5 |
'XSTEXT' => 'text',
|
|
|
4c79b5 |
'XSTEXT_UNI'=> 'varchar(100)',
|
|
|
4c79b5 |
'STEXT' => 'text',
|
|
|
4c79b5 |
'STEXT_UNI' => 'varchar(255)',
|
|
|
4c79b5 |
'TEXT' => 'text',
|
|
|
4c79b5 |
'TEXT_UNI' => 'text',
|
|
|
4c79b5 |
'MTEXT' => 'mediumtext',
|
|
|
4c79b5 |
'MTEXT_UNI' => 'mediumtext',
|
|
|
4c79b5 |
'TIMESTAMP' => 'int(11) UNSIGNED',
|
|
|
4c79b5 |
'DECIMAL' => 'decimal(5,2)',
|
|
|
4c79b5 |
'VCHAR_UNI' => 'varchar(255)',
|
|
|
4c79b5 |
'VCHAR_UNI:'=> 'varchar(%d)',
|
|
|
4c79b5 |
'VCHAR_CI' => 'varchar(255)',
|
|
|
4c79b5 |
'VARBINARY' => 'varbinary(255)',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'mysql_40' => array(
|
|
|
4c79b5 |
'INT:' => 'int(%d)',
|
|
|
4c79b5 |
'BINT' => 'bigint(20)',
|
|
|
4c79b5 |
'UINT' => 'mediumint(8) UNSIGNED',
|
|
|
4c79b5 |
'UINT:' => 'int(%d) UNSIGNED',
|
|
|
4c79b5 |
'TINT:' => 'tinyint(%d)',
|
|
|
4c79b5 |
'USINT' => 'smallint(4) UNSIGNED',
|
|
|
4c79b5 |
'BOOL' => 'tinyint(1) UNSIGNED',
|
|
|
4c79b5 |
'VCHAR' => 'varbinary(255)',
|
|
|
4c79b5 |
'VCHAR:' => 'varbinary(%d)',
|
|
|
4c79b5 |
'CHAR:' => 'binary(%d)',
|
|
|
4c79b5 |
'XSTEXT' => 'blob',
|
|
|
4c79b5 |
'XSTEXT_UNI'=> 'blob',
|
|
|
4c79b5 |
'STEXT' => 'blob',
|
|
|
4c79b5 |
'STEXT_UNI' => 'blob',
|
|
|
4c79b5 |
'TEXT' => 'blob',
|
|
|
4c79b5 |
'TEXT_UNI' => 'blob',
|
|
|
4c79b5 |
'MTEXT' => 'mediumblob',
|
|
|
4c79b5 |
'MTEXT_UNI' => 'mediumblob',
|
|
|
4c79b5 |
'TIMESTAMP' => 'int(11) UNSIGNED',
|
|
|
4c79b5 |
'DECIMAL' => 'decimal(5,2)',
|
|
|
4c79b5 |
'VCHAR_UNI' => 'blob',
|
|
|
4c79b5 |
'VCHAR_UNI:'=> array('varbinary(%d)', 'limit' => array('mult', 3, 255, 'blob')),
|
|
|
4c79b5 |
'VCHAR_CI' => 'blob',
|
|
|
4c79b5 |
'VARBINARY' => 'varbinary(255)',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'firebird' => array(
|
|
|
4c79b5 |
'INT:' => 'INTEGER',
|
|
|
4c79b5 |
'BINT' => 'DOUBLE PRECISION',
|
|
|
4c79b5 |
'UINT' => 'INTEGER',
|
|
|
4c79b5 |
'UINT:' => 'INTEGER',
|
|
|
4c79b5 |
'TINT:' => 'INTEGER',
|
|
|
4c79b5 |
'USINT' => 'INTEGER',
|
|
|
4c79b5 |
'BOOL' => 'INTEGER',
|
|
|
4c79b5 |
'VCHAR' => 'VARCHAR(255) CHARACTER SET NONE',
|
|
|
4c79b5 |
'VCHAR:' => 'VARCHAR(%d) CHARACTER SET NONE',
|
|
|
4c79b5 |
'CHAR:' => 'CHAR(%d) CHARACTER SET NONE',
|
|
|
4c79b5 |
'XSTEXT' => 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
|
|
|
4c79b5 |
'STEXT' => 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
|
|
|
4c79b5 |
'TEXT' => 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
|
|
|
4c79b5 |
'MTEXT' => 'BLOB SUB_TYPE TEXT CHARACTER SET NONE',
|
|
|
4c79b5 |
'XSTEXT_UNI'=> 'VARCHAR(100) CHARACTER SET UTF8',
|
|
|
4c79b5 |
'STEXT_UNI' => 'VARCHAR(255) CHARACTER SET UTF8',
|
|
|
4c79b5 |
'TEXT_UNI' => 'BLOB SUB_TYPE TEXT CHARACTER SET UTF8',
|
|
|
4c79b5 |
'MTEXT_UNI' => 'BLOB SUB_TYPE TEXT CHARACTER SET UTF8',
|
|
|
4c79b5 |
'TIMESTAMP' => 'INTEGER',
|
|
|
4c79b5 |
'DECIMAL' => 'DOUBLE PRECISION',
|
|
|
4c79b5 |
'VCHAR_UNI' => 'VARCHAR(255) CHARACTER SET UTF8',
|
|
|
4c79b5 |
'VCHAR_UNI:'=> 'VARCHAR(%d) CHARACTER SET UTF8',
|
|
|
4c79b5 |
'VCHAR_CI' => 'VARCHAR(255) CHARACTER SET UTF8',
|
|
|
4c79b5 |
'VARBINARY' => 'CHAR(255) CHARACTER SET NONE',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'mssql' => array(
|
|
|
4c79b5 |
'INT:' => '[int]',
|
|
|
4c79b5 |
'BINT' => '[float]',
|
|
|
4c79b5 |
'UINT' => '[int]',
|
|
|
4c79b5 |
'UINT:' => '[int]',
|
|
|
4c79b5 |
'TINT:' => '[int]',
|
|
|
4c79b5 |
'USINT' => '[int]',
|
|
|
4c79b5 |
'BOOL' => '[int]',
|
|
|
4c79b5 |
'VCHAR' => '[varchar] (255)',
|
|
|
4c79b5 |
'VCHAR:' => '[varchar] (%d)',
|
|
|
4c79b5 |
'CHAR:' => '[char] (%d)',
|
|
|
4c79b5 |
'XSTEXT' => '[varchar] (1000)',
|
|
|
4c79b5 |
'STEXT' => '[varchar] (3000)',
|
|
|
4c79b5 |
'TEXT' => '[varchar] (8000)',
|
|
|
4c79b5 |
'MTEXT' => '[text]',
|
|
|
4c79b5 |
'XSTEXT_UNI'=> '[varchar] (100)',
|
|
|
4c79b5 |
'STEXT_UNI' => '[varchar] (255)',
|
|
|
4c79b5 |
'TEXT_UNI' => '[varchar] (4000)',
|
|
|
4c79b5 |
'MTEXT_UNI' => '[text]',
|
|
|
4c79b5 |
'TIMESTAMP' => '[int]',
|
|
|
4c79b5 |
'DECIMAL' => '[float]',
|
|
|
4c79b5 |
'VCHAR_UNI' => '[varchar] (255)',
|
|
|
4c79b5 |
'VCHAR_UNI:'=> '[varchar] (%d)',
|
|
|
4c79b5 |
'VCHAR_CI' => '[varchar] (255)',
|
|
|
4c79b5 |
'VARBINARY' => '[varchar] (255)',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'oracle' => array(
|
|
|
4c79b5 |
'INT:' => 'number(%d)',
|
|
|
4c79b5 |
'BINT' => 'number(20)',
|
|
|
4c79b5 |
'UINT' => 'number(8)',
|
|
|
4c79b5 |
'UINT:' => 'number(%d)',
|
|
|
4c79b5 |
'TINT:' => 'number(%d)',
|
|
|
4c79b5 |
'USINT' => 'number(4)',
|
|
|
4c79b5 |
'BOOL' => 'number(1)',
|
|
|
4c79b5 |
'VCHAR' => 'varchar2(255)',
|
|
|
4c79b5 |
'VCHAR:' => 'varchar2(%d)',
|
|
|
4c79b5 |
'CHAR:' => 'char(%d)',
|
|
|
4c79b5 |
'XSTEXT' => 'varchar2(1000)',
|
|
|
4c79b5 |
'STEXT' => 'varchar2(3000)',
|
|
|
4c79b5 |
'TEXT' => 'clob',
|
|
|
4c79b5 |
'MTEXT' => 'clob',
|
|
|
4c79b5 |
'XSTEXT_UNI'=> 'varchar2(300)',
|
|
|
4c79b5 |
'STEXT_UNI' => 'varchar2(765)',
|
|
|
4c79b5 |
'TEXT_UNI' => 'clob',
|
|
|
4c79b5 |
'MTEXT_UNI' => 'clob',
|
|
|
4c79b5 |
'TIMESTAMP' => 'number(11)',
|
|
|
4c79b5 |
'DECIMAL' => 'number(5, 2)',
|
|
|
4c79b5 |
'VCHAR_UNI' => 'varchar2(765)',
|
|
|
4c79b5 |
'VCHAR_UNI:'=> array('varchar2(%d)', 'limit' => array('mult', 3, 765, 'clob')),
|
|
|
4c79b5 |
'VCHAR_CI' => 'varchar2(255)',
|
|
|
4c79b5 |
'VARBINARY' => 'raw(255)',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'sqlite' => array(
|
|
|
4c79b5 |
'INT:' => 'int(%d)',
|
|
|
4c79b5 |
'BINT' => 'bigint(20)',
|
|
|
4c79b5 |
'UINT' => 'INTEGER UNSIGNED', //'mediumint(8) UNSIGNED',
|
|
|
4c79b5 |
'UINT:' => 'INTEGER UNSIGNED', // 'int(%d) UNSIGNED',
|
|
|
4c79b5 |
'TINT:' => 'tinyint(%d)',
|
|
|
4c79b5 |
'USINT' => 'INTEGER UNSIGNED', //'mediumint(4) UNSIGNED',
|
|
|
4c79b5 |
'BOOL' => 'INTEGER UNSIGNED', //'tinyint(1) UNSIGNED',
|
|
|
4c79b5 |
'VCHAR' => 'varchar(255)',
|
|
|
4c79b5 |
'VCHAR:' => 'varchar(%d)',
|
|
|
4c79b5 |
'CHAR:' => 'char(%d)',
|
|
|
4c79b5 |
'XSTEXT' => 'text(65535)',
|
|
|
4c79b5 |
'STEXT' => 'text(65535)',
|
|
|
4c79b5 |
'TEXT' => 'text(65535)',
|
|
|
4c79b5 |
'MTEXT' => 'mediumtext(16777215)',
|
|
|
4c79b5 |
'XSTEXT_UNI'=> 'text(65535)',
|
|
|
4c79b5 |
'STEXT_UNI' => 'text(65535)',
|
|
|
4c79b5 |
'TEXT_UNI' => 'text(65535)',
|
|
|
4c79b5 |
'MTEXT_UNI' => 'mediumtext(16777215)',
|
|
|
4c79b5 |
'TIMESTAMP' => 'INTEGER UNSIGNED', //'int(11) UNSIGNED',
|
|
|
4c79b5 |
'DECIMAL' => 'decimal(5,2)',
|
|
|
4c79b5 |
'VCHAR_UNI' => 'varchar(255)',
|
|
|
4c79b5 |
'VCHAR_UNI:'=> 'varchar(%d)',
|
|
|
4c79b5 |
'VCHAR_CI' => 'varchar(255)',
|
|
|
4c79b5 |
'VARBINARY' => 'blob',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'postgres' => array(
|
|
|
4c79b5 |
'INT:' => 'INT4',
|
|
|
4c79b5 |
'BINT' => 'INT8',
|
|
|
4c79b5 |
'UINT' => 'INT4', // unsigned
|
|
|
4c79b5 |
'UINT:' => 'INT4', // unsigned
|
|
|
4c79b5 |
'USINT' => 'INT2', // unsigned
|
|
|
4c79b5 |
'BOOL' => 'INT2', // unsigned
|
|
|
4c79b5 |
'TINT:' => 'INT2',
|
|
|
4c79b5 |
'VCHAR' => 'varchar(255)',
|
|
|
4c79b5 |
'VCHAR:' => 'varchar(%d)',
|
|
|
4c79b5 |
'CHAR:' => 'char(%d)',
|
|
|
4c79b5 |
'XSTEXT' => 'varchar(1000)',
|
|
|
4c79b5 |
'STEXT' => 'varchar(3000)',
|
|
|
4c79b5 |
'TEXT' => 'varchar(8000)',
|
|
|
4c79b5 |
'MTEXT' => 'TEXT',
|
|
|
4c79b5 |
'XSTEXT_UNI'=> 'varchar(100)',
|
|
|
4c79b5 |
'STEXT_UNI' => 'varchar(255)',
|
|
|
4c79b5 |
'TEXT_UNI' => 'varchar(4000)',
|
|
|
4c79b5 |
'MTEXT_UNI' => 'TEXT',
|
|
|
4c79b5 |
'TIMESTAMP' => 'INT4', // unsigned
|
|
|
4c79b5 |
'DECIMAL' => 'decimal(5,2)',
|
|
|
4c79b5 |
'VCHAR_UNI' => 'varchar(255)',
|
|
|
4c79b5 |
'VCHAR_UNI:'=> 'varchar(%d)',
|
|
|
4c79b5 |
'VCHAR_CI' => 'varchar_ci',
|
|
|
4c79b5 |
'VARBINARY' => 'bytea',
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// A list of types being unsigned for better reference in some db's
|
|
|
4c79b5 |
$unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Only an example, but also commented out
|
|
|
4c79b5 |
$database_update_info = array(
|
|
|
4c79b5 |
// Changes from 3.0.RC2 to the next version
|
|
|
4c79b5 |
'3.0.RC2' => array(
|
|
|
4c79b5 |
// Change the following columns
|
|
|
4c79b5 |
'change_columns' => array(
|
|
|
4c79b5 |
BANLIST_TABLE => array(
|
|
|
4c79b5 |
'ban_reason' => array('VCHAR_UNI', ''),
|
|
|
4c79b5 |
'ban_give_reason' => array('VCHAR_UNI', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
// Changes from 3.0.RC3 to the next version
|
|
|
4c79b5 |
'3.0.RC3' => array(
|
|
|
4c79b5 |
// Change the following columns
|
|
|
4c79b5 |
'change_columns' => array(
|
|
|
4c79b5 |
BANLIST_TABLE => array(
|
|
|
4c79b5 |
'ban_reason' => array('VCHAR_UNI', ''),
|
|
|
4c79b5 |
'ban_give_reason' => array('VCHAR_UNI', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_TABLE => array(
|
|
|
4c79b5 |
'style_id' => array('USINT', 0),
|
|
|
4c79b5 |
'template_id' => array('USINT', 0),
|
|
|
4c79b5 |
'theme_id' => array('USINT', 0),
|
|
|
4c79b5 |
'imageset_id' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_TEMPLATE_TABLE => array(
|
|
|
4c79b5 |
'template_id' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_TEMPLATE_DATA_TABLE => array(
|
|
|
4c79b5 |
'template_id' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_THEME_TABLE => array(
|
|
|
4c79b5 |
'theme_id' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_IMAGESET_TABLE => array(
|
|
|
4c79b5 |
'imageset_id' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_IMAGESET_DATA_TABLE => array(
|
|
|
4c79b5 |
'imageset_id' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
USERS_TABLE => array(
|
|
|
4c79b5 |
'user_style' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
FORUMS_TABLE => array(
|
|
|
4c79b5 |
'forum_style' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
GROUPS_TABLE => array(
|
|
|
4c79b5 |
'group_avatar_type' => array('TINT:2', 0),
|
|
|
4c79b5 |
'group_avatar_width' => array('USINT', 0),
|
|
|
4c79b5 |
'group_avatar_height' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
// Changes from 3.0.RC4 to the next version
|
|
|
4c79b5 |
'3.0.RC4' => array(
|
|
|
4c79b5 |
// Change the following columns
|
|
|
4c79b5 |
'change_columns' => array(
|
|
|
4c79b5 |
STYLES_TABLE => array(
|
|
|
4c79b5 |
'style_id' => array('USINT', NULL, 'auto_increment'),
|
|
|
4c79b5 |
'template_id' => array('USINT', 0),
|
|
|
4c79b5 |
'theme_id' => array('USINT', 0),
|
|
|
4c79b5 |
'imageset_id' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_TEMPLATE_TABLE => array(
|
|
|
4c79b5 |
'template_id' => array('USINT', NULL, 'auto_increment'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_TEMPLATE_DATA_TABLE => array(
|
|
|
4c79b5 |
'template_id' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_THEME_TABLE => array(
|
|
|
4c79b5 |
'theme_id' => array('USINT', NULL, 'auto_increment'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_IMAGESET_TABLE => array(
|
|
|
4c79b5 |
'imageset_id' => array('USINT', NULL, 'auto_increment'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_IMAGESET_DATA_TABLE => array(
|
|
|
4c79b5 |
'imageset_id' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
USERS_TABLE => array(
|
|
|
4c79b5 |
'user_style' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
FORUMS_TABLE => array(
|
|
|
4c79b5 |
'forum_style' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
GROUPS_TABLE => array(
|
|
|
4c79b5 |
'group_avatar_width' => array('USINT', 0),
|
|
|
4c79b5 |
'group_avatar_height' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
// Changes from 3.0.RC5 to the next version
|
|
|
4c79b5 |
'3.0.RC5' => array(
|
|
|
4c79b5 |
// Add the following columns
|
|
|
4c79b5 |
'add_columns' => array(
|
|
|
4c79b5 |
USERS_TABLE => array(
|
|
|
4c79b5 |
'user_form_salt' => array('VCHAR_UNI:32', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
// Change the following columns
|
|
|
4c79b5 |
'change_columns' => array(
|
|
|
4c79b5 |
POSTS_TABLE => array(
|
|
|
4c79b5 |
'bbcode_uid' => array('VCHAR:8', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
PRIVMSGS_TABLE => array(
|
|
|
4c79b5 |
'bbcode_uid' => array('VCHAR:8', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
USERS_TABLE => array(
|
|
|
4c79b5 |
'user_sig_bbcode_uid' => array('VCHAR:8', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
// Changes from 3.0.RC6 to the next version
|
|
|
4c79b5 |
'3.0.RC6' => array(
|
|
|
4c79b5 |
// Change the following columns
|
|
|
4c79b5 |
'change_columns' => array(
|
|
|
4c79b5 |
FORUMS_TABLE => array(
|
|
|
4c79b5 |
'forum_desc_uid' => array('VCHAR:8', ''),
|
|
|
4c79b5 |
'forum_rules_uid' => array('VCHAR:8', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
GROUPS_TABLE => array(
|
|
|
4c79b5 |
'group_desc_uid' => array('VCHAR:8', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
USERS_TABLE => array(
|
|
|
4c79b5 |
'user_newpasswd' => array('VCHAR_UNI:40', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
// Changes from 3.0.RC8 to the next version
|
|
|
4c79b5 |
'3.0.RC8' => array(
|
|
|
4c79b5 |
// Change the following columns
|
|
|
4c79b5 |
'change_columns' => array(
|
|
|
4c79b5 |
USERS_TABLE => array(
|
|
|
4c79b5 |
'user_new_privmsg' => array('INT:4', 0),
|
|
|
4c79b5 |
'user_unread_privmsg' => array('INT:4', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
// Changes from 3.0.0 to the next version
|
|
|
4c79b5 |
'3.0.0' => array(
|
|
|
4c79b5 |
// Add the following columns
|
|
|
4c79b5 |
'add_columns' => array(
|
|
|
4c79b5 |
FORUMS_TABLE => array(
|
|
|
4c79b5 |
'display_subforum_list' => array('BOOL', 1),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
SESSIONS_TABLE => array(
|
|
|
4c79b5 |
'session_forum_id' => array('UINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'add_index' => array(
|
|
|
4c79b5 |
SESSIONS_TABLE => array(
|
|
|
4c79b5 |
'session_forum_id' => array('session_forum_id'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
GROUPS_TABLE => array(
|
|
|
4c79b5 |
'group_legend_name' => array('group_legend', 'group_name'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'drop_keys' => array(
|
|
|
4c79b5 |
GROUPS_TABLE => array('group_legend'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
// No changes from 3.0.1-RC1 to 3.0.1
|
|
|
4c79b5 |
'3.0.1-RC1' => array(),
|
|
|
4c79b5 |
// No changes from 3.0.1 to 3.0.2-RC1
|
|
|
4c79b5 |
'3.0.1' => array(),
|
|
|
4c79b5 |
// Changes from 3.0.2-RC1 to 3.0.2-RC2
|
|
|
4c79b5 |
'3.0.2-RC1' => array(
|
|
|
4c79b5 |
'change_columns' => array(
|
|
|
4c79b5 |
DRAFTS_TABLE => array(
|
|
|
4c79b5 |
'draft_subject' => array('STEXT_UNI', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
FORUMS_TABLE => array(
|
|
|
4c79b5 |
'forum_last_post_subject' => array('STEXT_UNI', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
POSTS_TABLE => array(
|
|
|
4c79b5 |
'post_subject' => array('STEXT_UNI', '', 'true_sort'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
PRIVMSGS_TABLE => array(
|
|
|
4c79b5 |
'message_subject' => array('STEXT_UNI', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
TOPICS_TABLE => array(
|
|
|
4c79b5 |
'topic_title' => array('STEXT_UNI', '', 'true_sort'),
|
|
|
4c79b5 |
'topic_last_post_subject' => array('STEXT_UNI', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'drop_keys' => array(
|
|
|
4c79b5 |
SESSIONS_TABLE => array('session_forum_id'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'add_index' => array(
|
|
|
4c79b5 |
SESSIONS_TABLE => array(
|
|
|
4c79b5 |
'session_fid' => array('session_forum_id'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
// No changes from 3.0.2-RC2 to 3.0.2
|
|
|
4c79b5 |
'3.0.2-RC2' => array(),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Changes from 3.0.2 to 3.0.3-RC1
|
|
|
4c79b5 |
'3.0.2' => array(
|
|
|
4c79b5 |
// Add the following columns
|
|
|
4c79b5 |
'add_columns' => array(
|
|
|
4c79b5 |
STYLES_TEMPLATE_TABLE => array(
|
|
|
4c79b5 |
'template_inherits_id' => array('UINT:4', 0),
|
|
|
4c79b5 |
'template_inherit_path' => array('VCHAR', ''),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
GROUPS_TABLE => array(
|
|
|
4c79b5 |
'group_max_recipients' => array('UINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// No changes from 3.0.3-RC1 to 3.0.3
|
|
|
4c79b5 |
'3.0.3-RC1' => array(),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Changes from 3.0.3 to 3.0.4-RC1
|
|
|
4c79b5 |
'3.0.3' => array(
|
|
|
4c79b5 |
'add_columns' => array(
|
|
|
4c79b5 |
PROFILE_FIELDS_TABLE => array(
|
|
|
4c79b5 |
'field_show_profile' => array('BOOL', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
'change_columns' => array(
|
|
|
4c79b5 |
STYLES_TABLE => array(
|
|
|
4c79b5 |
'style_id' => array('UINT', NULL, 'auto_increment'),
|
|
|
4c79b5 |
'template_id' => array('UINT', 0),
|
|
|
4c79b5 |
'theme_id' => array('UINT', 0),
|
|
|
4c79b5 |
'imageset_id' => array('UINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_IMAGESET_TABLE => array(
|
|
|
4c79b5 |
'imageset_id' => array('UINT', NULL, 'auto_increment'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_IMAGESET_DATA_TABLE => array(
|
|
|
4c79b5 |
'image_id' => array('UINT', NULL, 'auto_increment'),
|
|
|
4c79b5 |
'imageset_id' => array('UINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_THEME_TABLE => array(
|
|
|
4c79b5 |
'theme_id' => array('UINT', NULL, 'auto_increment'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_TEMPLATE_TABLE => array(
|
|
|
4c79b5 |
'template_id' => array('UINT', NULL, 'auto_increment'),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_TEMPLATE_DATA_TABLE => array(
|
|
|
4c79b5 |
'template_id' => array('UINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
FORUMS_TABLE => array(
|
|
|
4c79b5 |
'forum_style' => array('USINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
USERS_TABLE => array(
|
|
|
4c79b5 |
'user_style' => array('UINT', 0),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Changes from 3.0.4-RC1 to 3.0.4
|
|
|
4c79b5 |
'3.0.4-RC1' => array(),
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Determine mapping database type
|
|
|
4c79b5 |
switch ($db->sql_layer)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'mysql':
|
|
|
4c79b5 |
$map_dbms = 'mysql_40';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql4':
|
|
|
4c79b5 |
if (version_compare($db->sql_server_info(true), '4.1.3', '>='))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$map_dbms = 'mysql_41';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$map_dbms = 'mysql_40';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysqli':
|
|
|
4c79b5 |
$map_dbms = 'mysql_41';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
case 'mssql_odbc':
|
|
|
4c79b5 |
$map_dbms = 'mssql';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
$map_dbms = $db->sql_layer;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$error_ary = array();
|
|
|
4c79b5 |
$errored = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
header('Content-type: text/html; charset=UTF-8');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $lang['DIRECTION']; ?>" lang="<?php echo $lang['USER_LANG']; ?>" xml:lang="<?php echo $lang['USER_LANG']; ?>">
|
|
|
4c79b5 |
<head>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
|
|
4c79b5 |
<meta http-equiv="content-language" content="<?php echo $lang['USER_LANG']; ?>" />
|
|
|
4c79b5 |
<meta http-equiv="content-style-type" content="text/css" />
|
|
|
4c79b5 |
<meta http-equiv="imagetoolbar" content="no" />
|
|
|
4c79b5 |
|
|
|
4c79b5 |
<title></title>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
<link href="../adm/style/admin.css" rel="stylesheet" type="text/css" media="screen" />
|
|
|
4c79b5 |
|
|
|
4c79b5 |
</head>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
<body>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
:: sql_layer; ?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// To let set_config() calls succeed, we need to make the config array available globally
|
|
|
4c79b5 |
$config = array();
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . CONFIG_TABLE;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$config[$row['config_name']] = $row['config_value'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/*if ($debug_from_version !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$config['version'] = $debug_from_version;
|
|
|
4c79b5 |
}*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
echo $lang['PREVIOUS_VERSION'] . ' :: ' . $config['version'] . ' ';
|
|
|
4c79b5 |
echo $lang['UPDATED_VERSION'] . ' :: ' . $updates_to_version . '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$current_version = str_replace('rc', 'RC', strtolower($config['version']));
|
|
|
4c79b5 |
$latest_version = str_replace('rc', 'RC', strtolower($updates_to_version));
|
|
|
4c79b5 |
$orig_version = $config['version'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// If the latest version and the current version are 'unequal', we will update the version_update_from, else we do not update anything.
|
|
|
4c79b5 |
if ($inline_update)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($current_version !== $latest_version)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
set_config('version_update_from', $orig_version);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// If not called from the update script, we will actually remove the traces
|
|
|
4c79b5 |
$db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'");
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Checks/Operations that have to be completed prior to starting the update itself
|
|
|
4c79b5 |
$exit = false;
|
|
|
4c79b5 |
if (version_compare($current_version, '3.0.RC8', '<=')) /* && $debug_from_version === false) */
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Define missing language entries...
|
|
|
4c79b5 |
if (!isset($lang['CLEANING_USERNAMES']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$lang = array_merge($lang, array(
|
|
|
4c79b5 |
'CLEANING_USERNAMES' => 'Cleaning usernames',
|
|
|
4c79b5 |
'LONG_SCRIPT_EXECUTION' => 'Please note that this can take a while... Please do not stop the script.',
|
|
|
4c79b5 |
'CHANGE_CLEAN_NAMES' => 'The method used to make sure a username is not used by multiple users has been changed. There are some users which have the same name when compared with the new method. You have to delete or rename these users to make sure that each name is only used by one user before you can proceed.',
|
|
|
4c79b5 |
'USER_ACTIVE' => 'Active user',
|
|
|
4c79b5 |
'USER_INACTIVE' => 'Inactive user',
|
|
|
4c79b5 |
'BOT' => 'Spider/Robot',
|
|
|
4c79b5 |
'UPDATE_REQUIRES_FILE' => 'The updater requires that the following file is present: %s',
|
|
|
4c79b5 |
|
|
|
4c79b5 |
'DELETE_USER_REMOVE' => 'Delete user and remove posts',
|
|
|
4c79b5 |
'DELETE_USER_RETAIN' => 'Delete user but keep posts',
|
|
|
4c79b5 |
'EDIT_USERNAME' => 'Edit username',
|
|
|
4c79b5 |
'KEEP_OLD_NAME' => 'Keep username',
|
|
|
4c79b5 |
'NEW_USERNAME' => 'New username',
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
flush();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$submit = (isset($_POST['resolve_conflicts'])) ? true : false;
|
|
|
4c79b5 |
$modify_users = request_var('modify_users', array(0 => ''));
|
|
|
4c79b5 |
$new_usernames = request_var('new_usernames', array(0 => ''), true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// We need this file if someone wants to edit usernames.
|
|
|
4c79b5 |
include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!class_exists('utf_new_normalizer'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!file_exists($phpbb_root_path . 'install/data/new_normalizer.' . $phpEx))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $lang;
|
|
|
4c79b5 |
trigger_error(sprintf($lang['UPDATE_REQUIRES_FILE'], $phpbb_root_path . 'install/data/new_normalizer.' . $phpEx), E_USER_ERROR);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
include($phpbb_root_path . 'install/data/new_normalizer.' . $phpEx);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// the admin decided to change some usernames
|
|
|
4c79b5 |
if (sizeof($modify_users) && $submit)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT user_id, username, user_type
|
|
|
4c79b5 |
FROM ' . USERS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('user_id', array_keys($modify_users));
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$users = 0;
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$users++;
|
|
|
4c79b5 |
$user_id = (int) $row['user_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($modify_users[$user_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$row['action'] = $modify_users[$user_id];
|
|
|
4c79b5 |
$modify_users[$user_id] = $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// only if all ids really existed
|
|
|
4c79b5 |
if (sizeof($modify_users) == $users)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$user->data['user_id'] = ANONYMOUS;
|
|
|
4c79b5 |
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
|
|
|
4c79b5 |
foreach ($modify_users as $user_id => $row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($row['action'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'edit':
|
|
|
4c79b5 |
if (isset($new_usernames[$user_id]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$data = array('username' => utf8_new_normalize_nfc($new_usernames[$user_id]));
|
|
|
4c79b5 |
// Need to update config, forum, topic, posting, messages, etc.
|
|
|
4c79b5 |
if ($data['username'] != $row['username'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$check_ary = array('username' => array(
|
|
|
4c79b5 |
array('string', false, $config['min_name_chars'], $config['max_name_chars']),
|
|
|
4c79b5 |
array('username'),
|
|
|
4c79b5 |
));
|
|
|
4c79b5 |
// need a little trick for this to work properly
|
|
|
4c79b5 |
$user->data['username_clean'] = utf8_clean_string($data['username']) . 'a';
|
|
|
4c79b5 |
$errors = validate_data($data, $check_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($errors)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
include($phpbb_root_path . 'language/' . $language . '/ucp.' . $phpEx);
|
|
|
4c79b5 |
echo '';
|
|
|
4c79b5 |
foreach ($errors as $error)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
echo '' . $lang[$error] . ' ';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
echo '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$errors)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . '
|
|
|
4c79b5 |
SET ' . $db->sql_build_array('UPDATE', array(
|
|
|
4c79b5 |
'username' => $data['username'],
|
|
|
4c79b5 |
'username_clean' => utf8_clean_string($data['username'])
|
|
|
4c79b5 |
)) . '
|
|
|
4c79b5 |
WHERE user_id = ' . $user_id;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $row['username'], $data['username']);
|
|
|
4c79b5 |
user_update_name($row['username'], $data['username']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'delete_retain':
|
|
|
4c79b5 |
case 'delete_remove':
|
|
|
4c79b5 |
if ($user_id != ANONYMOUS && $row['user_type'] != USER_FOUNDER)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
user_delete(substr($row['action'], 7), $user_id, $row['username']);
|
|
|
4c79b5 |
add_log('admin', 'LOG_USER_DELETED', $row['username']);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
::
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
flush();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// after RC3 a different utf8_clean_string function is used, this requires that
|
|
|
4c79b5 |
// the unique column username_clean is recalculated, during this recalculation
|
|
|
4c79b5 |
// duplicates might be created. Since the column has to be unique such usernames
|
|
|
4c79b5 |
// must not exist. We need identify them and let the admin decide what to do
|
|
|
4c79b5 |
// about them.
|
|
|
4c79b5 |
// After RC8 this was changed again, but this time only usernames containing spaces
|
|
|
4c79b5 |
// are affected.
|
|
|
4c79b5 |
$sql_where = (version_compare($current_version, '3.0.RC4', '<=')) ? '' : "WHERE username_clean LIKE '% %'";
|
|
|
4c79b5 |
$sql = 'SELECT user_id, username, username_clean
|
|
|
4c79b5 |
FROM ' . USERS_TABLE . "
|
|
|
4c79b5 |
$sql_where
|
|
|
4c79b5 |
ORDER BY user_id ASC";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$colliding_users = $found_names = array();
|
|
|
4c79b5 |
$echos = 0;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Calculate the new clean name. If it differs from the old one we need
|
|
|
4c79b5 |
// to make sure there is no collision
|
|
|
4c79b5 |
$clean_name = utf8_new_clean_string($row['username']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($clean_name != $row['username_clean'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Check if there would be a collission, if not put it up for changing
|
|
|
4c79b5 |
$user_id = (int) $row['user_id'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// If this clean name was not the result of another user already ...
|
|
|
4c79b5 |
if (!isset($found_names[$clean_name]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// then we need to figure out whether there are any other users
|
|
|
4c79b5 |
// who already had this clean name with the old version
|
|
|
4c79b5 |
$sql = 'SELECT user_id, username
|
|
|
4c79b5 |
FROM ' . USERS_TABLE . '
|
|
|
4c79b5 |
WHERE username_clean = \'' . $db->sql_escape($clean_name) . '\'';
|
|
|
4c79b5 |
$result2 = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$user_ids = array($user_id);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result2))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// For not trimmed entries this could happen, yes. ;)
|
|
|
4c79b5 |
if ($row['user_id'] == $user_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Make sure this clean name will still be the same with the
|
|
|
4c79b5 |
// new function. If it is, then we have to add it to the list
|
|
|
4c79b5 |
// of user ids for this clean name
|
|
|
4c79b5 |
if (utf8_new_clean_string($row['username']) == $clean_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$user_ids[] = (int) $row['user_id'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result2);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// if we already found a collision save it
|
|
|
4c79b5 |
if (sizeof($user_ids) > 1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$colliding_users[$clean_name] = $user_ids;
|
|
|
4c79b5 |
$found_names[$clean_name] = true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// otherwise just mark this name as found
|
|
|
4c79b5 |
$found_names[$clean_name] = $user_id;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
// Else, if we already found the username
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// If the value in the found_names lookup table is only true ...
|
|
|
4c79b5 |
if ($found_names[$clean_name] === true)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// then the actual data was already added to $colliding_users
|
|
|
4c79b5 |
// and we only need to append the user_id
|
|
|
4c79b5 |
$colliding_users[$clean_name][] = $user_id;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// otherwise it still keeps the first user_id for this name
|
|
|
4c79b5 |
// and we need to move the data to $colliding_users, and set
|
|
|
4c79b5 |
// the value in the found_names lookup table to true, so
|
|
|
4c79b5 |
// following users will directly be appended to $colliding_users
|
|
|
4c79b5 |
$colliding_users[$clean_name] = array($found_names[$clean_name], $user_id);
|
|
|
4c79b5 |
$found_names[$clean_name] = true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (($echos % 1000) == 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
echo '.';
|
|
|
4c79b5 |
flush();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$echos++;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_write_result(false, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// now retrieve all information about the users and let the admin decide what to do
|
|
|
4c79b5 |
if (sizeof($colliding_users))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$exit = true;
|
|
|
4c79b5 |
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
|
|
|
4c79b5 |
include($phpbb_root_path . 'language/' . $language . '/memberlist.' . $phpEx);
|
|
|
4c79b5 |
include($phpbb_root_path . 'language/' . $language . '/acp/users.' . $phpEx);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// link a few things to the correct place so we don't get any problems
|
|
|
4c79b5 |
$user->lang = &$lang;
|
|
|
4c79b5 |
$user->data['user_id'] = ANONYMOUS;
|
|
|
4c79b5 |
$user->date_format = $config['default_dateformat'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// a little trick to get all user_ids
|
|
|
4c79b5 |
$user_ids = call_user_func_array('array_merge', array_values($colliding_users));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT session_user_id, MAX(session_time) AS session_time
|
|
|
4c79b5 |
FROM ' . SESSIONS_TABLE . '
|
|
|
4c79b5 |
WHERE session_time >= ' . (time() - $config['session_length']) . '
|
|
|
4c79b5 |
AND ' . $db->sql_in_set('session_user_id', $user_ids) . '
|
|
|
4c79b5 |
GROUP BY session_user_id';
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$session_times = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$session_times[$row['session_user_id']] = $row['session_time'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . USERS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('user_id', $user_ids);
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$users = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (isset($session_times[$row['user_id']]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$row['session_time'] = $session_times[$row['user_id']];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$row['session_time'] = 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$users[(int) $row['user_id']] = $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
unset($session_times);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// now display a table with all users, some information about them and options
|
|
|
4c79b5 |
// for the admin: keep name, change name (with text input) or delete user
|
|
|
4c79b5 |
$u_action = "database_update.$phpEx?language=$language&type=$inline_update";
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
<form id="change_clean_names" method="post" action="<?php echo $u_action; ?>">
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($colliding_users as $clean_name => $user_ids)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
<fieldset class="tabulated">
|
|
|
4c79b5 |
|
|
|
4c79b5 |
<caption></caption>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($user_ids as $i => $user_id)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$row = $users[$user_id];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$rank_title = $rank_img = '';
|
|
|
4c79b5 |
get_user_rank($row['user_rank'], $row['user_posts'], $rank_title, $rank_img, $rank_img_src);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$last_visit = (!empty($row['session_time'])) ? $row['session_time'] : $row['user_lastvisit'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$info = '';
|
|
|
4c79b5 |
switch ($row['user_type'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case USER_INACTIVE:
|
|
|
4c79b5 |
$info .= $lang['USER_INACTIVE'];
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case USER_IGNORE:
|
|
|
4c79b5 |
$info .= $lang['BOT'];
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case USER_FOUNDER:
|
|
|
4c79b5 |
$info .= $lang['FOUNDER'];
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
default:
|
|
|
4c79b5 |
$info .= $lang['USER_ACTIVE'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($user_id == ANONYMOUS)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$info = $lang['GUEST'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
format_date($row['user_regdate']) ?>
|
|
|
4c79b5 |
format_date($last_visit); ?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
<label><input type="radio" class="radio" id="keep_user_<?php echo $user_id; ?>" name="modify_users[<?php echo $user_id; ?>]" value="keep" checked="checked" /> </label>
|
|
|
4c79b5 |
<label><input type="radio" class="radio" id="edit_user_<?php echo $user_id; ?>" name="modify_users[<?php echo $user_id; ?>]" value="edit" /> </label>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// some users must not be deleted
|
|
|
4c79b5 |
if ($user_id != ANONYMOUS && $row['user_type'] != USER_FOUNDER)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
<label><input type="radio" class="radio" id="delete_user_retain_<?php echo $user_id; ?>" name="modify_users[<?php echo $user_id; ?>]" value="delete_retain" /> </label>
|
|
|
4c79b5 |
<label><input type="radio" class="radio" id="delete_user_remove_<?php echo $user_id; ?>" name="modify_users[<?php echo $user_id; ?>]" value="delete_remove" /> </label>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
<input id="new_username_<?php echo $user_id; ?>" type="text" name="new_usernames[<?php echo $user_id; ?>]" value="<?php echo $row['username']; ?>" />
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
</fieldset>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
<input class="button2" id="resolve_conflicts" type="submit" name="resolve_conflicts" value="<?php echo $lang['SUBMIT']; ?>" />
|
|
|
4c79b5 |
|
|
|
4c79b5 |
</form>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (sizeof($found_names))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT user_id, username, username_clean
|
|
|
4c79b5 |
FROM ' . USERS_TABLE . '
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('user_id', array_values($found_names));
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$found_names = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$clean_name = utf8_new_clean_string($row['username']);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($clean_name != $row['username_clean'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$user_id = (int) $row['user_id'];
|
|
|
4c79b5 |
$found_names[$user_id] = $clean_name;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// impossible unique clean name
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . "
|
|
|
4c79b5 |
SET username_clean = ' {$user_id}'
|
|
|
4c79b5 |
WHERE user_id = {$user_id}";
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($found_names as $user_id => $clean_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . '
|
|
|
4c79b5 |
SET username_clean = \'' . $db->sql_escape($clean_name) . '\'
|
|
|
4c79b5 |
WHERE user_id = ' . $user_id;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
unset($found_names);
|
|
|
4c79b5 |
unset($colliding_users);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($exit)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
</body>
|
|
|
4c79b5 |
</html>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (function_exists('exit_handler'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
exit_handler();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Schema updates
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
::
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
flush();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// We go through the schema changes from the lowest to the highest version
|
|
|
4c79b5 |
// We try to also include versions 'in-between'...
|
|
|
4c79b5 |
$no_updates = true;
|
|
|
4c79b5 |
$versions = array_keys($database_update_info);
|
|
|
4c79b5 |
for ($i = 0; $i < sizeof($versions); $i++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$version = $versions[$i];
|
|
|
4c79b5 |
$schema_changes = $database_update_info[$version];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// If the installed version to be updated to is < than the current version, and if the current version is >= as the version to be updated to next, we will skip the process
|
|
|
4c79b5 |
if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/* if ($debug_from_version !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Applying update schema for version array with key '$version'
|
|
|
4c79b5 |
// for version '$version' to '$next_version'
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!sizeof($schema_changes))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Change columns?
|
|
|
4c79b5 |
if (!empty($schema_changes['change_columns']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($schema_changes['change_columns'] as $table => $columns)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($columns as $column_name => $column_data)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
sql_column_change($map_dbms, $table, $column_name, $column_data);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Add columns?
|
|
|
4c79b5 |
if (!empty($schema_changes['add_columns']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($schema_changes['add_columns'] as $table => $columns)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($columns as $column_name => $column_data)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Only add the column if it does not exist yet
|
|
|
4c79b5 |
if (!column_exists($map_dbms, $table, $column_name))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
sql_column_add($map_dbms, $table, $column_name, $column_data);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Remove keys?
|
|
|
4c79b5 |
if (!empty($schema_changes['drop_keys']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($schema_changes['drop_keys'] as $table => $indexes)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($indexes as $index_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
sql_index_drop($map_dbms, $index_name, $table);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Drop columns?
|
|
|
4c79b5 |
if (!empty($schema_changes['drop_columns']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($schema_changes['drop_columns'] as $table => $columns)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($columns as $column)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
sql_column_remove($map_dbms, $table, $column);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Add primary keys?
|
|
|
4c79b5 |
if (!empty($schema_changes['add_primary_keys']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($schema_changes['add_primary_keys'] as $table => $columns)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
sql_create_primary_key($map_dbms, $table, $columns);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Add unqiue indexes?
|
|
|
4c79b5 |
if (!empty($schema_changes['add_unique_index']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($schema_changes['add_unique_index'] as $table => $index_array)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($index_array as $index_name => $column)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
sql_create_unique_index($map_dbms, $index_name, $table, $column);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Add indexes?
|
|
|
4c79b5 |
if (!empty($schema_changes['add_index']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($schema_changes['add_index'] as $table => $index_array)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($index_array as $index_name => $column)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
sql_create_index($map_dbms, $index_name, $table, $column);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_write_result($no_updates, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Data updates
|
|
|
4c79b5 |
$error_ary = array();
|
|
|
4c79b5 |
$errored = $no_updates = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
::
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
flush();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = true;
|
|
|
4c79b5 |
$versions = array_keys($database_update_info);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// some code magic
|
|
|
4c79b5 |
for ($i = 0; $i < sizeof($versions); $i++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$version = $versions[$i];
|
|
|
4c79b5 |
$next_version = (isset($versions[$i + 1])) ? $versions[$i + 1] : $updates_to_version;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// If the installed version to be updated to is < than the current version, and if the current version is >= as the version to be updated to next, we will skip the process
|
|
|
4c79b5 |
if (version_compare($version, $current_version, '<') && version_compare($current_version, $next_version, '>='))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/* if ($debug_from_version !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Applying update schema for version array with key '$version'
|
|
|
4c79b5 |
// for version '$version' to '$next_version'
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
change_database_data($no_updates, $version);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_write_result($no_updates, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$error_ary = array();
|
|
|
4c79b5 |
$errored = $no_updates = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
::
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
flush();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
//if ($debug_from_version === false)
|
|
|
4c79b5 |
// {
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// update the version
|
|
|
4c79b5 |
$sql = "UPDATE " . CONFIG_TABLE . "
|
|
|
4c79b5 |
SET config_value = '$updates_to_version'
|
|
|
4c79b5 |
WHERE config_name = 'version'";
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Reset permissions
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . "
|
|
|
4c79b5 |
SET user_permissions = '',
|
|
|
4c79b5 |
user_perm_from = 0";
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// }
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/* Optimize/vacuum analyze the tables where appropriate
|
|
|
4c79b5 |
// this should be done for each version in future along with
|
|
|
4c79b5 |
// the version number update
|
|
|
4c79b5 |
switch ($db->sql_layer)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'mysql':
|
|
|
4c79b5 |
case 'mysqli':
|
|
|
4c79b5 |
case 'mysql4':
|
|
|
4c79b5 |
$sql = 'OPTIMIZE TABLE ' . $table_prefix . 'auth_access, ' . $table_prefix . 'banlist, ' . $table_prefix . 'categories, ' . $table_prefix . 'config, ' . $table_prefix . 'disallow, ' . $table_prefix . 'forum_prune, ' . $table_prefix . 'forums, ' . $table_prefix . 'groups, ' . $table_prefix . 'posts, ' . $table_prefix . 'posts_text, ' . $table_prefix . 'privmsgs, ' . $table_prefix . 'privmsgs_text, ' . $table_prefix . 'ranks, ' . $table_prefix . 'search_results, ' . $table_prefix . 'search_wordlist, ' . $table_prefix . 'search_wordmatch, ' . $table_prefix . 'sessions_keys' . $table_prefix . 'smilies, ' . $table_prefix . 'themes, ' . $table_prefix . 'themes_name, ' . $table_prefix . 'topics, ' . $table_prefix . 'topics_watch, ' . $table_prefix . 'user_group, ' . $table_prefix . 'users, ' . $table_prefix . 'vote_desc, ' . $table_prefix . 'vote_results, ' . $table_prefix . 'vote_voters, ' . $table_prefix . 'words';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'postgresql':
|
|
|
4c79b5 |
_sql("VACUUM ANALYZE", $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_write_result($no_updates, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$inline_update)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Purge the cache...
|
|
|
4c79b5 |
$cache->purge();
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
" class="button1">
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Add database update to log
|
|
|
4c79b5 |
add_log('admin', 'LOG_UPDATE_DATABASE', $orig_version, $updates_to_version);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Now we purge the session table as well as all cache files
|
|
|
4c79b5 |
$cache->purge();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
</body>
|
|
|
4c79b5 |
</html>
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
garbage_collection();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (function_exists('exit_handler'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
exit_handler();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Function where all data changes are executed
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function change_database_data(&$no_updates, $version)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db, $map_dbms, $errored, $error_ary, $config, $phpbb_root_path, $phpEx;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($version)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case '3.0.RC2':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$smileys = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT smiley_id, code
|
|
|
4c79b5 |
FROM ' . SMILIES_TABLE;
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$smileys[$row['smiley_id']] = $row['code'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($smileys as $id => $code)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// 2.0 only entitized lt and gt; We need to do something about double quotes.
|
|
|
4c79b5 |
if (strchr($code, '"') === false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$new_code = str_replace('&', '&', $code);
|
|
|
4c79b5 |
$new_code = str_replace('<', '<', $new_code);
|
|
|
4c79b5 |
$new_code = str_replace('>', '>', $new_code);
|
|
|
4c79b5 |
$new_code = utf8_htmlspecialchars($new_code);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . SMILIES_TABLE . '
|
|
|
4c79b5 |
SET code = \'' . $db->sql_escape($new_code) . '\'
|
|
|
4c79b5 |
WHERE smiley_id = ' . (int) $id;
|
|
|
4c79b5 |
$db->sql_query($sql);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$index_list = sql_list_index($map_dbms, ACL_ROLES_DATA_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (in_array('ath_opt_id', $index_list))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
sql_index_drop($map_dbms, 'ath_opt_id', ACL_ROLES_DATA_TABLE);
|
|
|
4c79b5 |
sql_create_index($map_dbms, 'ath_op_id', ACL_ROLES_DATA_TABLE, array('auth_option_id'));
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case '3.0.RC3':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($map_dbms === 'postgres')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "SELECT SETVAL('" . FORUMS_TABLE . "_seq',(select case when max(forum_id)>0 then max(forum_id)+1 else 1 end from " . FORUMS_TABLE . '));';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// we check for:
|
|
|
4c79b5 |
// ath_opt_id
|
|
|
4c79b5 |
// ath_op_id
|
|
|
4c79b5 |
// ACL_ROLES_DATA_TABLE_ath_opt_id
|
|
|
4c79b5 |
// we want ACL_ROLES_DATA_TABLE_ath_op_id
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$table_index_fix = array(
|
|
|
4c79b5 |
ACL_ROLES_DATA_TABLE => array(
|
|
|
4c79b5 |
'ath_opt_id' => 'ath_op_id',
|
|
|
4c79b5 |
'ath_op_id' => 'ath_op_id',
|
|
|
4c79b5 |
ACL_ROLES_DATA_TABLE . '_ath_opt_id' => 'ath_op_id'
|
|
|
4c79b5 |
),
|
|
|
4c79b5 |
STYLES_IMAGESET_DATA_TABLE => array(
|
|
|
4c79b5 |
'i_id' => 'i_d',
|
|
|
4c79b5 |
'i_d' => 'i_d',
|
|
|
4c79b5 |
STYLES_IMAGESET_DATA_TABLE . '_i_id' => 'i_d'
|
|
|
4c79b5 |
)
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// we need to create some indicies...
|
|
|
4c79b5 |
$needed_creation = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($table_index_fix as $table_name => $index_info)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$index_list = sql_list_fake($map_dbms, $table_name);
|
|
|
4c79b5 |
foreach ($index_info as $bad_index => $good_index)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (in_array($bad_index, $index_list))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// mysql is actually OK, it won't get a hand in this crud
|
|
|
4c79b5 |
switch ($map_dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// last version, mssql had issues with index removal
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
$sql = 'DROP INDEX ' . $table_name . '.' . $bad_index;
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// last version, firebird, oracle, postgresql and sqlite all got bad index names
|
|
|
4c79b5 |
// we got kinda lucky, tho: they all support the same syntax
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
$sql = 'DROP INDEX ' . $bad_index;
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// If the good index already exist we do not need to create it again...
|
|
|
4c79b5 |
if (($map_dbms == 'mysql_40' || $map_dbms == 'mysql_41') && $bad_index == $good_index)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$needed_creation[$table_name][$good_index] = 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$new_index_defs = array('ath_op_id' => array('auth_option_id'), 'i_d' => array('imageset_id'));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($needed_creation as $bad_table => $index_repair_list)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($index_repair_list as $new_index => $garbage)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
sql_create_index($map_dbms, $new_index, $bad_table, $new_index_defs[$new_index]);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Make sure empty smiley codes do not exist
|
|
|
4c79b5 |
$sql = 'DELETE FROM ' . SMILIES_TABLE . "
|
|
|
4c79b5 |
WHERE code = ''";
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
set_config('allow_birthdays', '1');
|
|
|
4c79b5 |
set_config('cron_lock', '0', true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case '3.0.RC4':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$update_auto_increment = array(
|
|
|
4c79b5 |
STYLES_TABLE => 'style_id',
|
|
|
4c79b5 |
STYLES_TEMPLATE_TABLE => 'template_id',
|
|
|
4c79b5 |
STYLES_THEME_TABLE => 'theme_id',
|
|
|
4c79b5 |
STYLES_IMAGESET_TABLE => 'imageset_id'
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_TABLE . '
|
|
|
4c79b5 |
WHERE style_id = 0';
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$bad_style_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($bad_style_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT MAX(style_id) as max_id
|
|
|
4c79b5 |
FROM ' . STYLES_TABLE;
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$proper_id = $row['max_id'] + 1;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_sql('UPDATE ' . STYLES_TABLE . " SET style_id = $proper_id WHERE style_id = 0", $errored, $error_ary);
|
|
|
4c79b5 |
_sql('UPDATE ' . FORUMS_TABLE . " SET forum_style = $proper_id WHERE forum_style = 0", $errored, $error_ary);
|
|
|
4c79b5 |
_sql('UPDATE ' . USERS_TABLE . " SET user_style = $proper_id WHERE user_style = 0", $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT config_value
|
|
|
4c79b5 |
FROM ' . CONFIG_TABLE . "
|
|
|
4c79b5 |
WHERE config_name = 'default_style'";
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$style_config = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($style_config['config_value'] === '0')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
set_config('default_style', (string) $proper_id);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_TABLE . '
|
|
|
4c79b5 |
WHERE template_id = 0';
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$bad_style_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($bad_style_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT MAX(template_id) as max_id
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_TABLE;
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$proper_id = $row['max_id'] + 1;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_sql('UPDATE ' . STYLES_TABLE . " SET template_id = $proper_id WHERE template_id = 0", $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_THEME_TABLE . '
|
|
|
4c79b5 |
WHERE theme_id = 0';
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$bad_style_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($bad_style_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT MAX(theme_id) as max_id
|
|
|
4c79b5 |
FROM ' . STYLES_THEME_TABLE;
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$proper_id = $row['max_id'] + 1;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_sql('UPDATE ' . STYLES_TABLE . " SET theme_id = $proper_id WHERE theme_id = 0", $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_IMAGESET_TABLE . '
|
|
|
4c79b5 |
WHERE imageset_id = 0';
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$bad_style_row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($bad_style_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT MAX(imageset_id) as max_id
|
|
|
4c79b5 |
FROM ' . STYLES_IMAGESET_TABLE;
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$proper_id = $row['max_id'] + 1;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_sql('UPDATE ' . STYLES_TABLE . " SET imageset_id = $proper_id WHERE imageset_id = 0", $errored, $error_ary);
|
|
|
4c79b5 |
_sql('UPDATE ' . STYLES_IMAGESET_DATA_TABLE . " SET imageset_id = $proper_id WHERE imageset_id = 0", $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($map_dbms == 'mysql_40' || $map_dbms == 'mysql_41')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($update_auto_increment as $auto_table_name => $auto_column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "SELECT MAX({$auto_column_name}) as max_id
|
|
|
4c79b5 |
FROM {$auto_table_name}";
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$max_id = ((int) $row['max_id']) + 1;
|
|
|
4c79b5 |
_sql("ALTER TABLE {$auto_table_name} AUTO_INCREMENT = {$max_id}", $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($map_dbms == 'postgres')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
foreach ($update_auto_increment as $auto_table_name => $auto_column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "SELECT SETVAL('" . $auto_table_name . "_seq',(select case when max({$auto_column_name})>0 then max({$auto_column_name})+1 else 1 end from " . $auto_table_name . '));';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DROP SEQUENCE ' . STYLES_TEMPLATE_DATA_TABLE . '_seq';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($map_dbms == 'firebird')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'DROP TRIGGER t_' . STYLES_TEMPLATE_DATA_TABLE;
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DROP GENERATOR ' . STYLES_TEMPLATE_DATA_TABLE . '_gen';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($map_dbms == 'oracle')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'DROP TRIGGER t_' . STYLES_TEMPLATE_DATA_TABLE;
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'DROP SEQUENCE ' . STYLES_TEMPLATE_DATA_TABLE . '_seq';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($map_dbms == 'mssql')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// we use transactions because we need to have a working DB at the end of all of this
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . STYLES_TEMPLATE_DATA_TABLE;
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
$old_style_rows = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$old_style_rows[] = $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// death to the table, it is evil!
|
|
|
4c79b5 |
$sql = 'DROP TABLE ' . STYLES_TEMPLATE_DATA_TABLE;
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// the table of awesomeness, praise be to it (or something)
|
|
|
4c79b5 |
$sql = 'CREATE TABLE [' . STYLES_TEMPLATE_DATA_TABLE . "] (
|
|
|
4c79b5 |
[template_id] [int] DEFAULT (0) NOT NULL ,
|
|
|
4c79b5 |
[template_filename] [varchar] (100) DEFAULT ('') NOT NULL ,
|
|
|
4c79b5 |
[template_included] [varchar] (8000) DEFAULT ('') NOT NULL ,
|
|
|
4c79b5 |
[template_mtime] [int] DEFAULT (0) NOT NULL ,
|
|
|
4c79b5 |
[template_data] [text] DEFAULT ('') NOT NULL
|
|
|
4c79b5 |
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]";
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// index? index
|
|
|
4c79b5 |
$sql = 'CREATE INDEX [tid] ON [' . STYLES_TEMPLATE_DATA_TABLE . ']([template_id]) ON [PRIMARY]';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// yet another index
|
|
|
4c79b5 |
$sql = 'CREATE INDEX [tfn] ON [' . STYLES_TEMPLATE_DATA_TABLE . ']([template_filename]) ON [PRIMARY]';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($old_style_rows as $return_row)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
_sql('INSERT INTO ' . STYLES_TEMPLATE_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $return_row), $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Setting this here again because new installations may not have it...
|
|
|
4c79b5 |
set_config('cron_lock', '0', true);
|
|
|
4c79b5 |
set_config('ldap_port', '');
|
|
|
4c79b5 |
set_config('ldap_user_filter', '');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case '3.0.RC5':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// In case the user is having the bot mediapartner google "as is", adjust it.
|
|
|
4c79b5 |
$sql = 'UPDATE ' . BOTS_TABLE . "
|
|
|
4c79b5 |
SET bot_agent = '" . $db->sql_escape('Mediapartners-Google') . "'
|
|
|
4c79b5 |
WHERE bot_agent = '" . $db->sql_escape('Mediapartners-Google/') . "'";
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
set_config('form_token_lifetime', '7200');
|
|
|
4c79b5 |
set_config('form_token_mintime', '0');
|
|
|
4c79b5 |
set_config('min_time_reg', '5');
|
|
|
4c79b5 |
set_config('min_time_terms', '2');
|
|
|
4c79b5 |
set_config('form_token_sid_guests', '1');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'SELECT forum_id, forum_password
|
|
|
4c79b5 |
FROM ' . FORUMS_TABLE;
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!empty($row['forum_password']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
_sql('UPDATE ' . FORUMS_TABLE . " SET forum_password = '" . md5($row['forum_password']) . "' WHERE forum_id = {$row['forum_id']}", $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case '3.0.0':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . TOPICS_TABLE . "
|
|
|
4c79b5 |
SET topic_last_view_time = topic_last_post_time
|
|
|
4c79b5 |
WHERE topic_last_view_time = 0";
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Update smiley sizes
|
|
|
4c79b5 |
$smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($smileys as $smiley)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (file_exists($phpbb_root_path . 'images/smilies/' . $smiley))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($width, $height) = getimagesize($phpbb_root_path . 'images/smilies/' . $smiley);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . SMILIES_TABLE . '
|
|
|
4c79b5 |
SET smiley_width = ' . $width . ', smiley_height = ' . $height . "
|
|
|
4c79b5 |
WHERE smiley_url = '" . $db->sql_escape($smiley) . "'";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// No changes from 3.0.1-RC1 to 3.0.1
|
|
|
4c79b5 |
case '3.0.1-RC1':
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// changes from 3.0.1 to 3.0.2-RC1
|
|
|
4c79b5 |
case '3.0.1':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
set_config('referer_validation', '1');
|
|
|
4c79b5 |
set_config('check_attachment_content', '1');
|
|
|
4c79b5 |
set_config('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// No changes from 3.0.2-RC1 to 3.0.2-RC2
|
|
|
4c79b5 |
case '3.0.2-RC1':
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// No changes from 3.0.2-RC2 to 3.0.2
|
|
|
4c79b5 |
case '3.0.2-RC2':
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Changes from 3.0.2 to 3.0.3-RC1
|
|
|
4c79b5 |
case '3.0.2':
|
|
|
4c79b5 |
set_config('enable_queue_trigger', '0');
|
|
|
4c79b5 |
set_config('queue_trigger_posts', '3');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
set_config('pm_max_recipients', '0');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Set maximum number of recipients for the registered users, bots, guests group
|
|
|
4c79b5 |
$sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5
|
|
|
4c79b5 |
WHERE ' . $db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS'));
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Not prefilling yet
|
|
|
4c79b5 |
set_config('dbms_version', '');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Add new permission u_masspm_group and duplicate settings from u_masspm
|
|
|
4c79b5 |
include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
|
|
|
4c79b5 |
$auth_admin = new auth_admin();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Only add the new permission if it does not already exist
|
|
|
4c79b5 |
if (empty($auth_admin->acl_options['id']['u_masspm_group']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$auth_admin->acl_add_option(array('global' => array('u_masspm_group')));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Now the tricky part, filling the permission
|
|
|
4c79b5 |
$old_id = $auth_admin->acl_options['id']['u_masspm'];
|
|
|
4c79b5 |
$new_id = $auth_admin->acl_options['id']['u_masspm_group'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($tables as $table)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT *
|
|
|
4c79b5 |
FROM ' . $table . '
|
|
|
4c79b5 |
WHERE auth_option_id = ' . $old_id;
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_ary = array();
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$row['auth_option_id'] = $new_id;
|
|
|
4c79b5 |
$sql_ary[] = $row;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (sizeof($sql_ary))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_multi_insert($table, $sql_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Remove any old permission entries
|
|
|
4c79b5 |
$auth_admin->acl_clear_prefetch();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Do not resync post counts here. An admin may do this later from the ACP
|
|
|
4c79b5 |
$start = 0;
|
|
|
4c79b5 |
$step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
do
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
|
|
|
4c79b5 |
FROM ' . POSTS_TABLE . '
|
|
|
4c79b5 |
WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
|
|
|
4c79b5 |
AND post_postcount = 1 AND post_approved = 1
|
|
|
4c79b5 |
GROUP BY poster_id';
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
do
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result));
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$start += $step;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$start = 0;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
while ($start);
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = 'UPDATE ' . MODULES_TABLE . '
|
|
|
4c79b5 |
SET module_auth = \'acl_a_email && cfg_email_enable\'
|
|
|
4c79b5 |
WHERE module_class = \'acp\'
|
|
|
4c79b5 |
AND module_basename = \'email\'';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Changes from 3.0.3-RC1 to 3.0.3
|
|
|
4c79b5 |
case '3.0.3-RC1':
|
|
|
4c79b5 |
$sql = 'UPDATE ' . LOG_TABLE . "
|
|
|
4c79b5 |
SET log_operation = 'LOG_DELETE_TOPIC'
|
|
|
4c79b5 |
WHERE log_operation = 'LOG_TOPIC_DELETED'";
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Changes from 3.0.3 to 3.0.4-RC1
|
|
|
4c79b5 |
case '3.0.3':
|
|
|
4c79b5 |
// Update the Custom Profile Fields based on previous settings to the new format
|
|
|
4c79b5 |
$sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide
|
|
|
4c79b5 |
FROM ' . PROFILE_FIELDS_TABLE;
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary = array(
|
|
|
4c79b5 |
'field_required' => 0,
|
|
|
4c79b5 |
'field_show_on_reg' => 0,
|
|
|
4c79b5 |
'field_hide' => 0,
|
|
|
4c79b5 |
'field_show_profile'=> 0,
|
|
|
4c79b5 |
);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($row['field_required'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($row['field_show_on_reg'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($row['field_hide'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module
|
|
|
4c79b5 |
$sql_ary['field_hide'] = 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// equivelant to "none", which is the "Display in user control panel" option
|
|
|
4c79b5 |
$sql_ary['field_show_profile'] = 1;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$no_updates = false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Changes from 3.0.4-RC1 to 3.0.4
|
|
|
4c79b5 |
case '3.0.4-RC1':
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Function for triggering an sql statement
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function _sql($sql, &$errored, &$error_ary, $echo_dot = true)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (defined('DEBUG_EXTRA'))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
echo " \n{$sql}\n ";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_return_on_error(true);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
if ($db->sql_error_triggered)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$errored = true;
|
|
|
4c79b5 |
$error_ary['sql'][] = $db->sql_error_sql;
|
|
|
4c79b5 |
$error_ary['error_code'][] = $db->_sql_error();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_return_on_error(false);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($echo_dot)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
echo ". \n";
|
|
|
4c79b5 |
flush();
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $result;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function _write_result($no_updates, $errored, $error_ary)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $lang;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($no_updates)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
echo ' ' . $lang['NO_UPDATES_REQUIRED'] . '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
echo ' ' . $lang['DONE'] . ' ' . $lang['RESULT'] . ' :: ';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($errored)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
echo ' ' . $lang['SOME_QUERIES_FAILED'] . '
|
|
|
4c79b5 |
|
|
|
4c79b5 |
for ($i = 0; $i < sizeof($error_ary['sql']); $i++)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
echo '' . $lang['ERROR'] . ' :: ' . htmlspecialchars($error_ary['error_code'][$i]['message']) . ' ';
|
|
|
4c79b5 |
echo $lang['SQL'] . ' :: ' . htmlspecialchars($error_ary['sql'][$i]) . '
';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
echo '
' . $lang['SQL_FAILURE_EXPLAIN'] . '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
echo '' . $lang['NO_ERRORS'] . '';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Check if a specified column exist
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function column_exists($dbms, $table, $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql = "SHOW COLUMNS
|
|
|
4c79b5 |
FROM $table";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// lower case just in case
|
|
|
4c79b5 |
if (strtolower($row['Field']) == $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// PostgreSQL has a way of doing this in a much simpler way but would
|
|
|
4c79b5 |
// not allow us to support all versions of PostgreSQL
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
$sql = "SELECT a.attname
|
|
|
4c79b5 |
FROM pg_class c, pg_attribute a
|
|
|
4c79b5 |
WHERE c.relname = '{$table}'
|
|
|
4c79b5 |
AND a.attnum > 0
|
|
|
4c79b5 |
AND a.attrelid = c.oid";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// lower case just in case
|
|
|
4c79b5 |
if (strtolower($row['attname']) == $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// same deal with PostgreSQL, we must perform more complex operations than
|
|
|
4c79b5 |
// we technically could
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
$sql = "SELECT c.name
|
|
|
4c79b5 |
FROM syscolumns c
|
|
|
4c79b5 |
LEFT JOIN sysobjects o ON c.id = o.id
|
|
|
4c79b5 |
WHERE o.name = '{$table}'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// lower case just in case
|
|
|
4c79b5 |
if (strtolower($row['name']) == $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
$sql = "SELECT column_name
|
|
|
4c79b5 |
FROM user_tab_columns
|
|
|
4c79b5 |
WHERE table_name = '{$table}'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// lower case just in case
|
|
|
4c79b5 |
if (strtolower($row['column_name']) == $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
$sql = "SELECT RDB\$FIELD_NAME as FNAME
|
|
|
4c79b5 |
FROM RDB\$RELATION_FIELDS
|
|
|
4c79b5 |
WHERE RDB\$RELATION_NAME = '{$table}'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// lower case just in case
|
|
|
4c79b5 |
if (strtolower($row['fname']) == $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// ugh, SQLite
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
$sql = "SELECT sql
|
|
|
4c79b5 |
FROM sqlite_master
|
|
|
4c79b5 |
WHERE type = 'table'
|
|
|
4c79b5 |
AND name = '{$table}'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$result)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
preg_match('#\((.*)\)#s', $row['sql'], $matches);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$cols = trim($matches[1]);
|
|
|
4c79b5 |
$col_array = preg_split('/,(?![\s\w]+\))/m', $cols);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($col_array as $declaration)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$entities = preg_split('#\s+#', trim($declaration));
|
|
|
4c79b5 |
if ($entities[0] == 'PRIMARY')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (strtolower($entities[0]) == $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
return true;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
return false;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Function to prepare some column information for better usage
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function prepare_column_data($dbms, $column_data, $table_name, $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $dbms_type_map, $unsigned_types;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Get type
|
|
|
4c79b5 |
if (strpos($column_data[0], ':') !== false)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
list($orig_column_type, $column_length) = explode(':', $column_data[0]);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!is_array($dbms_type_map[$dbms][$orig_column_type . ':']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$column_type = sprintf($dbms_type_map[$dbms][$orig_column_type . ':'], $column_length);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (isset($dbms_type_map[$dbms][$orig_column_type . ':']['rule']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'div':
|
|
|
4c79b5 |
$column_length /= $dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1];
|
|
|
4c79b5 |
$column_length = ceil($column_length);
|
|
|
4c79b5 |
$column_type = sprintf($dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($dbms_type_map[$dbms][$orig_column_type . ':']['limit']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'mult':
|
|
|
4c79b5 |
$column_length *= $dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1];
|
|
|
4c79b5 |
if ($column_length > $dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$column_type = $dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$column_type = sprintf($dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$orig_column_type .= ':';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$orig_column_type = $column_data[0];
|
|
|
4c79b5 |
$column_type = $dbms_type_map[$dbms][$column_data[0]];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Adjust default value if db-dependant specified
|
|
|
4c79b5 |
if (is_array($column_data[1]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = '';
|
|
|
4c79b5 |
$return_array = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
$sql .= " {$column_type} ";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!is_null($column_data[1]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' ';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql .= 'NOT NULL';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// This is a UNICODE column and thus should be given it's fair share
|
|
|
4c79b5 |
if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql .= ' COLLATE UNICODE';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
$sql .= " {$column_type} ";
|
|
|
4c79b5 |
$sql_default = " {$column_type} ";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// For adding columns we need the default definition
|
|
|
4c79b5 |
if (!is_null($column_data[1]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
// For hexadecimal values do not use single quotes
|
|
|
4c79b5 |
if (strpos($column_data[1], '0x') === 0)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_default .= 'DEFAULT (' . $column_data[1] . ') ';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_default .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') ';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql .= 'NOT NULL';
|
|
|
4c79b5 |
$sql_default .= 'NOT NULL';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$return_array['column_type_sql_default'] = $sql_default;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql .= " {$column_type} ";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// For hexadecimal values do not use single quotes
|
|
|
4c79b5 |
if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' ";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$sql .= 'NOT NULL';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($column_data[2]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($column_data[2] == 'auto_increment')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql .= ' auto_increment';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql .= ' COLLATE utf8_unicode_ci';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
$sql .= " {$column_type} ";
|
|
|
4c79b5 |
$sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : '';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// In Oracle empty strings ('') are treated as NULL.
|
|
|
4c79b5 |
// Therefore in oracle we allow NULL's for all DEFAULT '' entries
|
|
|
4c79b5 |
// Oracle does not like setting NOT NULL on a column that is already NOT NULL (this happens only on number fields)
|
|
|
4c79b5 |
if (preg_match('/number/i', $column_type))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql .= ($column_data[1] === '') ? '' : 'NOT NULL';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
$return_array['column_type'] = $column_type;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql .= " {$column_type} ";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$default_val = "nextval('{$table_name}_seq')";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if (!is_null($column_data[1]))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$default_val = "'" . $column_data[1] . "'";
|
|
|
4c79b5 |
$return_array['null'] = 'NOT NULL';
|
|
|
4c79b5 |
$sql .= 'NOT NULL ';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$return_array['default'] = $default_val;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql .= "DEFAULT {$default_val}";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Unsigned? Then add a CHECK contraint
|
|
|
4c79b5 |
if (in_array($orig_column_type, $unsigned_types))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$return_array['constraint'] = "CHECK ({$column_name} >= 0)";
|
|
|
4c79b5 |
$sql .= " CHECK ({$column_name} >= 0)";
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
if (isset($column_data[2]) && $column_data[2] == 'auto_increment')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql .= ' INTEGER PRIMARY KEY';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql .= ' ' . $column_type;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql .= ' NOT NULL ';
|
|
|
4c79b5 |
$sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : '';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$return_array['column_type_sql'] = $sql;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return $return_array;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Add new column
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_column_add($dbms, $table_name, $column_name, $column_data)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $errored, $error_ary;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$column_data = prepare_column_data($dbms, $column_data, $table_name, $column_name);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE "' . $table_name . '" ADD "' . $column_name . '" ' . $column_data['column_type_sql'];
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE [' . $table_name . '] ADD [' . $column_name . '] ' . $column_data['column_type_sql_default'];
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE `' . $table_name . '` ADD COLUMN `' . $column_name . '` ' . $column_data['column_type_sql'];
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . ' ADD ' . $column_name . ' ' . $column_data['column_type_sql'];
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . ' ADD COLUMN "' . $column_name . '" ' . $column_data['column_type_sql'];
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
if (version_compare(sqlite_libversion(), '3.0') == -1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
$sql = "SELECT sql
|
|
|
4c79b5 |
FROM sqlite_master
|
|
|
4c79b5 |
WHERE type = 'table'
|
|
|
4c79b5 |
AND name = '{$table_name}'
|
|
|
4c79b5 |
ORDER BY type DESC, name;";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$result)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Create a backup table and populate it, destroy the existing one
|
|
|
4c79b5 |
$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']));
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name);
|
|
|
4c79b5 |
$db->sql_query('DROP TABLE ' . $table_name);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
preg_match('#\((.*)\)#s', $row['sql'], $matches);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$new_table_cols = trim($matches[1]);
|
|
|
4c79b5 |
$old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
|
|
|
4c79b5 |
$column_list = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($old_table_cols as $declaration)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$entities = preg_split('#\s+#', trim($declaration));
|
|
|
4c79b5 |
if ($entities[0] == 'PRIMARY')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$column_list[] = $entities[0];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$columns = implode(',', $column_list);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$new_table_cols = $column_name . ' ' . $column_data['column_type_sql'] . ',' . $new_table_cols;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// create a new table and fill it up. destroy the temp one
|
|
|
4c79b5 |
$db->sql_query('CREATE TABLE ' . $table_name . ' (' . $new_table_cols . ');');
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;');
|
|
|
4c79b5 |
$db->sql_query('DROP TABLE ' . $table_name . '_temp');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . ' ADD ' . $column_name . ' [' . $column_data['column_type_sql'] . ']';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Drop column
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_column_remove($dbms, $table_name, $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $errored, $error_ary;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE "' . $table_name . '" DROP "' . $column_name . '"';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE [' . $table_name . '] DROP COLUMN [' . $column_name . ']';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE `' . $table_name . '` DROP COLUMN `' . $column_name . '`';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . ' DROP ' . $column_name;
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . ' DROP COLUMN "' . $column_name . '"';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
if (version_compare(sqlite_libversion(), '3.0') == -1)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $db;
|
|
|
4c79b5 |
$sql = "SELECT sql
|
|
|
4c79b5 |
FROM sqlite_master
|
|
|
4c79b5 |
WHERE type = 'table'
|
|
|
4c79b5 |
AND name = '{$table_name}'
|
|
|
4c79b5 |
ORDER BY type DESC, name;";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$result)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Create a backup table and populate it, destroy the existing one
|
|
|
4c79b5 |
$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']));
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name);
|
|
|
4c79b5 |
$db->sql_query('DROP TABLE ' . $table_name);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
preg_match('#\((.*)\)#s', $row['sql'], $matches);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$new_table_cols = trim($matches[1]);
|
|
|
4c79b5 |
$old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
|
|
|
4c79b5 |
$column_list = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($old_table_cols as $declaration)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$entities = preg_split('#\s+#', trim($declaration));
|
|
|
4c79b5 |
if ($entities[0] == 'PRIMARY' || $entities[0] === $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$column_list[] = $entities[0];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$columns = implode(',', $column_list);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$new_table_cols = $new_table_cols = preg_replace('/' . $column_name . '[^,]+(?:,|$)/m', '', $new_table_cols);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// create a new table and fill it up. destroy the temp one
|
|
|
4c79b5 |
$db->sql_query('CREATE TABLE ' . $table_name . ' (' . $new_table_cols . ');');
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;');
|
|
|
4c79b5 |
$db->sql_query('DROP TABLE ' . $table_name . '_temp');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . ' DROP COLUMN ' . $column_name;
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function sql_index_drop($dbms, $index_name, $table_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $dbms_type_map, $db;
|
|
|
4c79b5 |
global $errored, $error_ary;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
$sql = 'DROP INDEX ' . $table_name . '.' . $index_name;
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql = 'DROP INDEX ' . $index_name . ' ON ' . $table_name;
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
$sql = 'DROP INDEX ' . $table_name . '_' . $index_name;
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function sql_create_primary_key($dbms, $table_name, $column)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $dbms_type_map, $db;
|
|
|
4c79b5 |
global $errored, $error_ary;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . ' ADD PRIMARY KEY (' . implode(', ', $column) . ')';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
$sql = "ALTER TABLE [{$table_name}] WITH NOCHECK ADD ";
|
|
|
4c79b5 |
$sql .= "CONSTRAINT [PK_{$table_name}] PRIMARY KEY CLUSTERED (";
|
|
|
4c79b5 |
$sql .= '[' . implode("],\n\t\t[", $column) . ']';
|
|
|
4c79b5 |
$sql .= ') ON [PRIMARY]';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . ' ADD PRIMARY KEY (' . implode(', ', $column) . ')';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . 'add CONSTRAINT pk_' . $table_name . ' PRIMARY KEY (' . implode(', ', $column) . ')';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
$sql = "SELECT sql
|
|
|
4c79b5 |
FROM sqlite_master
|
|
|
4c79b5 |
WHERE type = 'table'
|
|
|
4c79b5 |
AND name = '{$table_name}'
|
|
|
4c79b5 |
ORDER BY type DESC, name;";
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$result)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Create a backup table and populate it, destroy the existing one
|
|
|
4c79b5 |
$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']));
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name);
|
|
|
4c79b5 |
$db->sql_query('DROP TABLE ' . $table_name);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
preg_match('#\((.*)\)#s', $row['sql'], $matches);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$new_table_cols = trim($matches[1]);
|
|
|
4c79b5 |
$old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
|
|
|
4c79b5 |
$column_list = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($old_table_cols as $declaration)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$entities = preg_split('#\s+#', trim($declaration));
|
|
|
4c79b5 |
if ($entities[0] == 'PRIMARY')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$column_list[] = $entities[0];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$columns = implode(',', $column_list);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// create a new table and fill it up. destroy the temp one
|
|
|
4c79b5 |
$db->sql_query('CREATE TABLE ' . $table_name . ' (' . $new_table_cols . ', PRIMARY KEY (' . implode(', ', $column) . '));');
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;');
|
|
|
4c79b5 |
$db->sql_query('DROP TABLE ' . $table_name . '_temp');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function sql_create_unique_index($dbms, $index_name, $table_name, $column)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $dbms_type_map, $db;
|
|
|
4c79b5 |
global $errored, $error_ary;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
$sql = 'CREATE UNIQUE INDEX ' . $table_name . '_' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql = 'CREATE UNIQUE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
$sql = 'CREATE UNIQUE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ') ON [PRIMARY]';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function sql_create_index($dbms, $index_name, $table_name, $column)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $dbms_type_map, $db;
|
|
|
4c79b5 |
global $errored, $error_ary;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
$sql = 'CREATE INDEX ' . $table_name . '_' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql = 'CREATE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
$sql = 'CREATE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ') ON [PRIMARY]';
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// List all of the indices that belong to a table,
|
|
|
4c79b5 |
// does not count:
|
|
|
4c79b5 |
// * UNIQUE indices
|
|
|
4c79b5 |
// * PRIMARY keys
|
|
|
4c79b5 |
function sql_list_index($dbms, $table_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $dbms_type_map, $db;
|
|
|
4c79b5 |
global $errored, $error_ary;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$index_array = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($dbms == 'mssql')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "EXEC sp_statistics '$table_name'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($row['TYPE'] == 3)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$index_array[] = $row['INDEX_NAME'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
$sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
|
|
|
4c79b5 |
FROM RDB\$INDICES
|
|
|
4c79b5 |
WHERE RDB\$RELATION_NAME = " . strtoupper($table_name) . "
|
|
|
4c79b5 |
AND RDB\$UNIQUE_FLAG IS NULL
|
|
|
4c79b5 |
AND RDB\$FOREIGN_KEY IS NULL";
|
|
|
4c79b5 |
$col = 'index_name';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
$sql = "SELECT ic.relname as index_name
|
|
|
4c79b5 |
FROM pg_class bc, pg_class ic, pg_index i
|
|
|
4c79b5 |
WHERE (bc.oid = i.indrelid)
|
|
|
4c79b5 |
AND (ic.oid = i.indexrelid)
|
|
|
4c79b5 |
AND (bc.relname = '" . $table_name . "')
|
|
|
4c79b5 |
AND (i.indisunique != 't')
|
|
|
4c79b5 |
AND (i.indisprimary != 't')";
|
|
|
4c79b5 |
$col = 'index_name';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql = 'SHOW KEYS
|
|
|
4c79b5 |
FROM ' . $table_name;
|
|
|
4c79b5 |
$col = 'Key_name';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
$sql = "SELECT index_name
|
|
|
4c79b5 |
FROM user_indexes
|
|
|
4c79b5 |
WHERE table_name = '" . $table_name . "'
|
|
|
4c79b5 |
AND generated = 'N'";
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
$sql = "PRAGMA index_info('" . $table_name . "');";
|
|
|
4c79b5 |
$col = 'name';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (($dbms == 'mysql_40' || $dbms == 'mysql_41') && !$row['Non_unique'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
$row[$col] = substr($row[$col], strlen($table_name) + 1);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$index_array[] = $row[$col];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return array_map('strtolower', $index_array);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// This is totally fake, never use it
|
|
|
4c79b5 |
// it exists only to mend bad update functions introduced
|
|
|
4c79b5 |
// * UNIQUE indices
|
|
|
4c79b5 |
// * PRIMARY keys
|
|
|
4c79b5 |
function sql_list_fake($dbms, $table_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $dbms_type_map, $db;
|
|
|
4c79b5 |
global $errored, $error_ary;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$index_array = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if ($dbms == 'mssql')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql = "EXEC sp_statistics '$table_name'";
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($row['TYPE'] == 3)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$index_array[] = $row['INDEX_NAME'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
$sql = "SELECT LOWER(RDB\$INDEX_NAME) as index_name
|
|
|
4c79b5 |
FROM RDB\$INDICES
|
|
|
4c79b5 |
WHERE RDB\$RELATION_NAME = " . strtoupper($table_name) . "
|
|
|
4c79b5 |
AND RDB\$UNIQUE_FLAG IS NULL
|
|
|
4c79b5 |
AND RDB\$FOREIGN_KEY IS NULL";
|
|
|
4c79b5 |
$col = 'index_name';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
$sql = "SELECT ic.relname as index_name
|
|
|
4c79b5 |
FROM pg_class bc, pg_class ic, pg_index i
|
|
|
4c79b5 |
WHERE (bc.oid = i.indrelid)
|
|
|
4c79b5 |
AND (ic.oid = i.indexrelid)
|
|
|
4c79b5 |
AND (bc.relname = '" . $table_name . "')
|
|
|
4c79b5 |
AND (i.indisunique != 't')
|
|
|
4c79b5 |
AND (i.indisprimary != 't')";
|
|
|
4c79b5 |
$col = 'index_name';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql = 'SHOW KEYS
|
|
|
4c79b5 |
FROM ' . $table_name;
|
|
|
4c79b5 |
$col = 'Key_name';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
$sql = "SELECT index_name
|
|
|
4c79b5 |
FROM user_indexes
|
|
|
4c79b5 |
WHERE table_name = '" . $table_name . "'
|
|
|
4c79b5 |
AND generated = 'N'";
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
$sql = "PRAGMA index_info('" . $table_name . "');";
|
|
|
4c79b5 |
$col = 'name';
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$result = $db->sql_query($sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (($dbms == 'mysql_40' || $dbms == 'mysql_41') && !$row['Non_unique'])
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
continue;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$index_array[] = $row[$col];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
return array_map('strtolower', $index_array);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
/**
|
|
|
4c79b5 |
* Change column type (not name!)
|
|
|
4c79b5 |
*/
|
|
|
4c79b5 |
function sql_column_change($dbms, $table_name, $column_name, $column_data)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $dbms_type_map, $db;
|
|
|
4c79b5 |
global $errored, $error_ary;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$column_data = prepare_column_data($dbms, $column_data, $table_name, $column_name);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
switch ($dbms)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
case 'firebird':
|
|
|
4c79b5 |
// Change type...
|
|
|
4c79b5 |
$sql = 'ALTER TABLE "' . $table_name . '" ALTER COLUMN "' . $column_name . '" TYPE ' . ' ' . $column_data['column_type_sql'];
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mssql':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE [' . $table_name . '] ALTER COLUMN [' . $column_name . '] ' . $column_data['column_type_sql'];
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'mysql_40':
|
|
|
4c79b5 |
case 'mysql_41':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE `' . $table_name . '` CHANGE `' . $column_name . '` `' . $column_name . '` ' . $column_data['column_type_sql'];
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'oracle':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . ' MODIFY ' . $column_name . ' ' . $column_data['column_type_sql'];
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'postgres':
|
|
|
4c79b5 |
$sql = 'ALTER TABLE ' . $table_name . ' ';
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql_array = array();
|
|
|
4c79b5 |
$sql_array[] = 'ALTER COLUMN ' . $column_name . ' TYPE ' . $column_data['column_type'];
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($column_data['null']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if ($column_data['null'] == 'NOT NULL')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_array[] = 'ALTER COLUMN ' . $column_name . ' SET NOT NULL';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else if ($column_data['null'] == 'NULL')
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_array[] = 'ALTER COLUMN ' . $column_name . ' DROP NOT NULL';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (isset($column_data['default']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_array[] = 'ALTER COLUMN ' . $column_name . ' SET DEFAULT ' . $column_data['default'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// we don't want to double up on constraints if we change different number data types
|
|
|
4c79b5 |
if (isset($column_data['constraint']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$constraint_sql = "SELECT consrc as constraint_data
|
|
|
4c79b5 |
FROM pg_constraint, pg_class bc
|
|
|
4c79b5 |
WHERE conrelid = bc.oid
|
|
|
4c79b5 |
AND bc.relname = '{$table_name}'
|
|
|
4c79b5 |
AND NOT EXISTS (
|
|
|
4c79b5 |
SELECT *
|
|
|
4c79b5 |
FROM pg_constraint as c, pg_inherits as i
|
|
|
4c79b5 |
WHERE i.inhrelid = pg_constraint.conrelid
|
|
|
4c79b5 |
AND c.conname = pg_constraint.conname
|
|
|
4c79b5 |
AND c.consrc = pg_constraint.consrc
|
|
|
4c79b5 |
AND c.conrelid = i.inhparent
|
|
|
4c79b5 |
)";
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$constraint_exists = false;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$result = $db->sql_query($constraint_sql);
|
|
|
4c79b5 |
while ($row = $db->sql_fetchrow($result))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (trim($row['constraint_data']) == trim($column_data['constraint']))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$constraint_exists = true;
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$constraint_exists)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$sql_array[] = 'ADD ' . $column_data['constraint'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql .= implode(', ', $sql_array);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
_sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
|
|
|
4c79b5 |
case 'sqlite':
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$sql = "SELECT sql
|
|
|
4c79b5 |
FROM sqlite_master
|
|
|
4c79b5 |
WHERE type = 'table'
|
|
|
4c79b5 |
AND name = '{$table_name}'
|
|
|
4c79b5 |
ORDER BY type DESC, name;";
|
|
|
4c79b5 |
$result = _sql($sql, $errored, $error_ary);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
if (!$result)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$row = $db->sql_fetchrow($result);
|
|
|
4c79b5 |
$db->sql_freeresult($result);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('begin');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// Create a temp table and populate it, destroy the existing one
|
|
|
4c79b5 |
$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . $table_name . '"?#i', 'CREATE TEMPORARY TABLE ' . $table_name . '_temp', $row['sql']));
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . $table_name . '_temp SELECT * FROM ' . $table_name);
|
|
|
4c79b5 |
$db->sql_query('DROP TABLE ' . $table_name);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
preg_match('#\((.*)\)#s', $row['sql'], $matches);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$new_table_cols = trim($matches[1]);
|
|
|
4c79b5 |
$old_table_cols = preg_split('/,(?![\s\w]+\))/m', $new_table_cols);
|
|
|
4c79b5 |
$column_list = array();
|
|
|
4c79b5 |
|
|
|
4c79b5 |
foreach ($old_table_cols as $key => $declaration)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$entities = preg_split('#\s+#', trim($declaration));
|
|
|
4c79b5 |
$column_list[] = $entities[0];
|
|
|
4c79b5 |
if ($entities[0] == $column_name)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$old_table_cols[$key] = $column_name . ' ' . $column_data['column_type_sql'];
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$columns = implode(',', $column_list);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// create a new table and fill it up. destroy the temp one
|
|
|
4c79b5 |
$db->sql_query('CREATE TABLE ' . $table_name . ' (' . implode(',', $old_table_cols) . ');');
|
|
|
4c79b5 |
$db->sql_query('INSERT INTO ' . $table_name . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . $table_name . '_temp;');
|
|
|
4c79b5 |
$db->sql_query('DROP TABLE ' . $table_name . '_temp');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$db->sql_transaction('commit');
|
|
|
4c79b5 |
|
|
|
4c79b5 |
break;
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function utf8_new_clean_string($text)
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
static $homographs = array();
|
|
|
4c79b5 |
static $utf8_case_fold_nfkc = '';
|
|
|
4c79b5 |
if (empty($homographs))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $phpbb_root_path, $phpEx;
|
|
|
4c79b5 |
if (!function_exists('utf8_case_fold_nfkc') || !file_exists($phpbb_root_path . 'includes/utf/data/confusables.' . $phpEx))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
if (!file_exists($phpbb_root_path . 'install/data/confusables.' . $phpEx))
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
global $lang;
|
|
|
4c79b5 |
trigger_error(sprintf($lang['UPDATE_REQUIRES_FILE'], $phpbb_root_path . 'install/data/confusables.' . $phpEx), E_USER_ERROR);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
$homographs = include($phpbb_root_path . 'install/data/confusables.' . $phpEx);
|
|
|
4c79b5 |
$utf8_case_fold_nfkc = 'utf8_new_case_fold_nfkc';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
else
|
|
|
4c79b5 |
{
|
|
|
4c79b5 |
$homographs = include($phpbb_root_path . 'includes/utf/data/confusables.' . $phpEx);
|
|
|
4c79b5 |
$utf8_case_fold_nfkc = 'utf8_case_fold_nfkc';
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$text = $utf8_case_fold_nfkc($text);
|
|
|
4c79b5 |
$text = strtr($text, $homographs);
|
|
|
4c79b5 |
// Other control characters
|
|
|
4c79b5 |
$text = preg_replace('#(?:[\x00-\x1F\x7F]+|(?:\xC2[\x80-\x9F])+)#', '', $text);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
$text = preg_replace('# {2,}#', ' ', $text);
|
|
|
4c79b5 |
|
|
|
4c79b5 |
// we can use trim here as all the other space characters should have been turned
|
|
|
4c79b5 |
// into normal ASCII spaces by now
|
|
|
4c79b5 |
return trim($text);
|
|
|
4c79b5 |
}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
?>
|