Remove unused code.

1.10.x
Julio Montoya 11 years ago
parent c72ead310d
commit c670521de3
  1. 44
      main/inc/global.inc.php
  2. 621
      main/inc/lib/database.lib.php
  3. 6
      main/inc/lib/diagnoser.lib.php
  4. 4
      main/inc/lib/session_handler.class.php
  5. 3
      main/inc/lib/session_handler_memcache.class.php
  6. 13
      main/install/i_database.class.php
  7. 2
      main/install/index.php
  8. 8
      main/install/install.lib.php
  9. 2
      main/install/install_db.inc.php
  10. 6
      main/install/update-db-1.9.0-1.10.0.inc.php
  11. 1289
      main/install/update-db-scorm-1.6.x-1.8.0.inc.php

@ -54,18 +54,6 @@ if (!isset($GLOBALS['_configuration'])) {
$GLOBALS['_configuration'] = $_configuration;
}
// Code for trnasitional purposes, it can be removed right before the 1.8.7 release.
if (empty($_configuration['system_version'])) {
$_configuration['system_version'] = $_configuration['dokeos_version'];
$_configuration['system_stable'] = $_configuration['dokeos_stable'];
$_configuration['software_url'] = 'http://www.chamilo.org/';
}
// For backward compatibility.
$_configuration['dokeos_version'] = $_configuration['system_version'];
$_configuration['dokeos_stable'] = $_configuration['system_stable'];
$userPasswordCrypted = $_configuration['password_encryption'];
// Include the main Chamilo platform library file.
require_once $includePath.'/lib/api.lib.php';
@ -130,19 +118,8 @@ $params = array(
'client_flags' => $dbFlags,
);
if (!$_configuration['db_host']) {
$global_error_code = 4;
// A configuration option about database server is missing.
require $includePath.'/global_error_message.inc.php';
die();
}
// Doctrine ORM configuration
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => $_configuration['db_host'],
@ -204,16 +181,6 @@ if (!empty($_configuration['multiple_access_urls'])) {
$_configuration['access_url'] = 1;
}
// The system has not been designed to use special SQL modes that were introduced since MySQL 5.
Database::query("set session sql_mode='';");
/*if (!Database::select_db($_configuration['main_database'], $database_connection)) {
$global_error_code = 5;
// Connection to the main Chamilo database is impossible, it might be missing or restricted or its configuration option might be incorrect.
require $includePath.'/global_error_message.inc.php';
die();
}*/
/* Initialization of the default encodings */
// The platform's character set must be retrieved at this early moment.
$sql = "SELECT selected_value FROM settings_current WHERE variable = 'platform_charset';";
@ -232,17 +199,6 @@ api_initialize_internationalization();
// Initialization of the default encoding that will be used by the multibyte string routines in the internationalization library.
api_set_internationalization_default_encoding($charset);
// Initialization of the database encoding to be used.
Database::query("SET SESSION character_set_server='utf8';");
Database::query("SET SESSION collation_server='utf8_general_ci';");
if (api_is_utf8($charset)) {
// See Bug #1802: For UTF-8 systems we prefer to use "SET NAMES 'utf8'" statement in order to avoid a bizarre problem with Chinese language.
Database::query("SET NAMES 'utf8';");
} else {
Database::query("SET CHARACTER SET '" . Database::to_db_encoding($charset) . "';");
}
// Start session after the internationalization library has been initialized.
Chamilo::session()->start($already_installed);

@ -53,7 +53,7 @@ class Database
* Please, define table names as constants in this library and use them
* instead of directly using magic words in your tool code.
*
* @param string $short_table_name, the name of the table
* @param string $table, the name of the table
*/
public static function get_main_table($table)
{
@ -67,37 +67,23 @@ class Database
* Please, define table names as constants in this library and use them
* instead of directly using magic words in your tool code.
*
* @param string $short_table_name, the name of the table
* @param string $database_name, optional, name of the course database
* - if you don't specify this, you work on the current course.
* @param string $table, the name of the table
*/
public static function get_course_table($table, $extra = null)
public static function get_course_table($table)
{
return DB_COURSE_PREFIX.$table;
/*
//forces fatal errors so we can debug more easily
if (!empty($extra)) {
var_dump($extra);
//@todo remove this
echo "<h3>Dev Message: get_course_table() doesn't have a 2nd parameter</h3>";
//exit;
}
return self::format_table_name(self::get_main_database(), DB_COURSE_PREFIX.$short_table_name);*/
}
/*
Query methods
These methods execute a query and return the result(s).
*/
/**
* Counts the number of rows in a table
* @param string $table The table of which the rows should be counted
* @return int The number of rows in the given table.
* @deprecated
*/
public static function count_rows($table) {
public static function count_rows($table)
{
$obj = self::fetch_object(self::query("SELECT COUNT(*) AS n FROM $table"));
return $obj->n;
}
@ -107,29 +93,21 @@ class Database
/**
* Returns the number of affected rows in the last database operation.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return int Returns the number of affected rows on success, and -1 if the last query failed.
* @param Statement $result
*
* @return int
*/
public static function affected_rows(Statement $result)
{
return $result->rowCount();
//return self::use_default_connection($connection) ? mysql_affected_rows() : mysql_affected_rows($connection);
}
/**
* Closes non-persistent database connection.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return bool Returns TRUE on success or FALSE on failure.
*/
public static function close($connection = null) {
return self::use_default_connection($connection) ? mysql_close() : mysql_close($connection);
}
/**
* @param array $params
*
* @throws \Doctrine\ORM\ORMException
*/
public function connect($params = array())
public function connect($params = [])
{
$config = self::getDoctrineConfig();
$config->setEntityNamespaces(
@ -140,6 +118,7 @@ class Database
)
);
$params['charset'] = 'utf8';
$entityManager = EntityManager::create($params, $config);
// Registering Constraints
@ -192,16 +171,6 @@ class Database
: mysql_connect($server, $username, $password, $new_link, $client_flags);*/
}
/**
* Returns error number from the last operation done on the database server.
* @param resource $connection (optional) The database server connection,
* for detailed description see the method query().
* @return int Returns the error number from the last database (operation, or 0 (zero) if no error occurred.
*/
public static function errno($connection = null) {
return self::use_default_connection($connection) ? mysql_errno() : mysql_errno($connection);
}
/**
* Returns error text from the last operation done on the database server.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
@ -226,28 +195,17 @@ class Database
/**
* Escapes a string to insert into the database as text
* @param string $string The string to escape
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @param bool $addFix
* @return string he escaped string
* @author Yannick Warnier <yannick.warnier@beeznest.com>
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
* @param $string
*
* @return string
*/
public static function escape_string($string, $connection = null, $addFix = true)
public static function escape_string($string)
{
$string = self::getManager()->getConnection()->quote($string);
return trim($string, "'");
/*return get_magic_quotes_gpc()
? (self::use_default_connection($connection)
? mysql_real_escape_string(stripslashes($string))
: mysql_real_escape_string(stripslashes($string), $connection))
: (self::use_default_connection($connection)
? mysql_real_escape_string($string)
: mysql_real_escape_string($string, $connection));-*/
return trim($string, "'");
}
/**
* Gets the array from a SQL result (as returned by Database::query) - help achieving database independence
* @param resource The result from a call to sql_query (e.g. Database::query)
@ -260,9 +218,8 @@ class Database
if ($result === false) {
return array();
}
return $result->fetch(self::customOptionToDoctrineOption($option));
//if ($result === false) { return array(); }
//return $option == 'ASSOC' ? mysql_fetch_array($result, MYSQL_ASSOC) : ($option == 'NUM' ? mysql_fetch_array($result, MYSQL_NUM) : mysql_fetch_array($result));
}
/**
@ -274,33 +231,28 @@ class Database
public static function fetch_assoc(Statement $result)
{
return $result->fetch(PDO::FETCH_ASSOC);
//return mysql_fetch_assoc($result);
}
/**
* Gets the next row of the result of the SQL query (as returned by Database::query) in an object form
* @param resource The result from a call to sql_query (e.g. Database::query)
* @param string Optional class name to instanciate
* @param array Optional array of parameters
* @return object Object of class StdClass or the required class, containing the query result row
* @author Yannick Warnier <yannick.warnier@beeznest.com>
*
* @param Statement $result
* @return mixed
*/
//public static function fetch_object($result, $class = null, $params = null) {
public static function fetch_object(Statement $result)
{
return $result->fetch(PDO::FETCH_OBJ);
//return !empty($class) ? (is_array($params) ? mysql_fetch_object($result, $class, $params) : mysql_fetch_object($result, $class)) : mysql_fetch_object($result);
}
/**
* Gets the array from a SQL result (as returned by Database::query) - help achieving database independence
* @param resource The result from a call to sql_query (see Database::query()).
* @return array Array of results as returned by php (mysql_fetch_row)
* @param Statement $result
*
* @return mixed
*/
public static function fetch_row(Statement $result)
{
return $result->fetch(PDO::FETCH_NUM);
//return mysql_fetch_row($result);
}
/**
@ -312,288 +264,62 @@ class Database
public static function free_result(Statement $result)
{
$result->closeCursor();
//return mysql_free_result($result);
}
/**
* Returns the database client library version.
* @return strung Returns a string that represents the client library version.
*/
public static function get_client_info() {
return mysql_get_client_info();
}
/**
* Returns a list of databases created on the server. The list may contain all of the
* available database names or filtered database names by using a pattern.
* @param string $pattern (optional) A pattern for filtering database names as if it was needed for the SQL's LIKE clause, for example 'chamilo_%'.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return array Returns in an array the retrieved list of database names.
*/
public static function get_databases($pattern = '', $connection = null) {
$result = array();
$query_result = Database::query(!empty($pattern) ? "SHOW DATABASES LIKE '".self::escape_string($pattern, $connection)."'" : "SHOW DATABASES", $connection);
while ($row = Database::fetch_row($query_result)) {
$result[] = $row[0];
}
return $result;
}
/**
* Returns information about the type of the current connection and the server host name.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return string/boolean Returns string data on success or FALSE on failure.
*/
public static function get_host_info($connection = null) {
return self::use_default_connection($connection) ? mysql_get_host_info() : mysql_get_host_info($connection);
}
/**
* Retrieves database client/server protocol version.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return int/boolean Returns the protocol version on success or FALSE on failure.
*/
public static function get_proto_info($connection = null) {
return self::use_default_connection($connection) ? mysql_get_proto_info() : mysql_get_proto_info($connection);
}
/**
* Retrieves the database server version.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return string/boolean Returns the MySQL server version on success or FALSE on failure.
*/
public static function get_server_info($connection = null) {
return self::use_default_connection($connection) ? mysql_get_server_info() : mysql_get_server_info($connection);
}
/**
* Returns a list of tables within a database. The list may contain all of the
* available table names or filtered table names by using a pattern.
* @param string $database (optional) The name of the examined database. If it is omited, the current database is assumed, see Database::select_db().
* @param string $pattern (optional) A pattern for filtering table names as if it was needed for the SQL's LIKE clause, for example 'access_%'.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return array Returns in an array the retrieved list of table names.
*/
public static function get_tables($database = '', $pattern = '', $connection = null) {
$result = array();
$query = "SHOW TABLES";
if (!empty($database)) {
$query .= " FROM `".self::escape_string($database, $connection)."`";
}
if (!empty($pattern)) {
$query .= " LIKE '".self::escape_string($pattern, $connection)."'";
}
$query_result = Database::query($query, $connection);
while ($row = Database::fetch_row($query_result)) {
$result[] = $row[0];
}
return $result;
}
/**
* Gets the ID of the last item inserted into the database
* This should be updated to use ADODB at some point
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return int The last ID as returned by the DB function
* @return string
*/
public static function insert_id()
{
return self::getManager()->getConnection()->lastInsertId();
//return self::use_default_connection($connection) ? mysql_insert_id() : mysql_insert_id($connection);
}
/**
* Gets the number of rows from the last query result - help achieving database independence
* @param resource The result
* @return integer The number of rows contained in this result
* @author Yannick Warnier <yannick.warnier@beeznest.com>
**/
* @param Statement $result
*
* @return int
*/
public static function num_rows(Statement $result)
{
return $result->rowCount();
//return is_resource($result) ? mysql_num_rows($result) : false;
}
/**
* Acts as the relative *_result() function of most DB drivers and fetches a
* specific line and a field
* @param resource The database resource to get data from
* @param integer The row number
* @param string Optional field name or number
* @return mixed One cell of the result, or FALSE on error
*
* @param Statement $resource
* @param int $row
* @param string $field
*
* @return mixed
*/
public static function result(Statement $resource, $row, $field = '')
{
if ($resource->rowCount() > 0) {
$result = $resource->fetchAll(PDO::FETCH_BOTH);
return $result[$row][$field];
}
//return self::num_rows($resource) > 0 ? (!empty($field) ? mysql_result($resource, $row, $field) : mysql_result($resource, $row)) : null;
}
/**
* This method returns a resource
* Documentation has been added by Arthur Portugal
* Some adaptations have been implemented by Ivan Tcholakov, 2009, 2010
* @author Olivier Brouckaert
* @param string $query The SQL query
* @param resource $connection (optional) The database server (MySQL) connection.
* If it is not specified, the connection opened by mysql_connect() is assumed.
* If no connection is found, the server will try to create one as if mysql_connect() was called with no arguments.
* If no connection is found or established, an E_WARNING level error is generated.
* @param string $file (optional) On error it shows the file in which the error has been trigerred (use the "magic" constant __FILE__ as input parameter)
* @param string $line (optional) On error it shows the line in which the error has been trigerred (use the "magic" constant __LINE__ as input parameter)
* @param $query
* @return Statement
*
* @return Statement The returned result from the query
*
* Note: The parameter $connection could be skipped. Here are examples of this method usage:
* Database::query($query);
* $result = Database::query($query);
* Database::query($query, $connection);
* $result = Database::query($query, $connection);
* The following ways for calling this method are obsolete:
* Database::query($query, __FILE__, __LINE__);
* $result = Database::query($query, __FILE__, __LINE__);
* Database::query($query, $connection, __FILE__, __LINE__);
* $result = Database::query($query, $connection, __FILE__, __LINE__);
* @throws \Doctrine\DBAL\DBALException
*/
public static function query($query, $connection = null, $file = null, $line = null)
public static function query($query)
{
$result = self::getManager()->getConnection()->executeQuery($query);
return $result;
$use_default_connection = self::use_default_connection($connection);
if ($use_default_connection) {
// Let us do parameter shifting, thus the method would be similar
// (in regard to parameter order) to the original function mysql_query().
$line = $file;
$file = $connection;
$connection = null;
}
// Check if the table contains a c_ (means a course id)
if (api_get_setting('server_type') === 'test' && strpos($query, 'c_')) {
//Check if the table contains inner joins
if (
strpos($query, 'assoc_handle') === false &&
strpos($query, 'olpc_peru_filter') === false &&
strpos($query, 'allow_public_certificates') === false &&
strpos($query, 'DROP TABLE IF EXISTS') === false &&
strpos($query, 'thematic_advance') === false &&
strpos($query, 'thematic_plan') === false &&
strpos($query, 'track_c_countries') === false &&
strpos($query, 'track_c_os') === false &&
strpos($query, 'track_c_providers') === false &&
strpos($query, 'track_c_referers') === false &&
strpos($query, 'track_c_browsers') === false &&
strpos($query, 'settings_current') === false &&
strpos($query, 'dokeos_classic_2D') === false &&
strpos($query, 'cosmic_campus') === false &&
strpos($query, 'static_') === false &&
strpos($query, 'public_admin') === false &&
strpos($query, 'chamilo_electric_blue') === false &&
strpos($query, 'specific_field') === false &&
strpos($query, 'down_doc_path') === false &&
strpos($query, 'INNER JOIN') === false &&
strpos($query, 'inner join') === false &&
strpos($query, 'left join') === false &&
strpos($query, 'LEFT JOIN') === false &&
strpos($query, 'insert') === false &&
strpos($query, 'INSERT') === false &&
strpos($query, 'ALTER') === false &&
strpos($query, 'alter') === false &&
strpos($query, 'c_id') === false &&
strpos($query, 'create table') === false &&
strpos($query, 'CREATE TABLE') === false &&
strpos($query, 'AUTO_INCREMENT') === false
) {
//@todo remove this
echo '<pre>';
$message = '<h4>Dev message: please add the c_id field in this query or report this error in support.chamilo.org </h4>';
$message .= $query;
echo $message;
echo '</pre>';
//error_log($message);
}
}
if (!($result = $use_default_connection ? mysql_query($query) : mysql_query($query, $connection))) {
$backtrace = debug_backtrace(); // Retrieving information about the caller statement.
if (isset($backtrace[0])) {
$caller = & $backtrace[0];
} else {
$caller = array();
}
if (isset($backtrace[1])) {
$owner = & $backtrace[1];
} else {
$owner = array();
}
if (empty($file)) {
$file = $caller['file'];
}
if (empty($line) && $line !== false) {
$line = $caller['line'];
}
$type = isset($owner['type']) ? $owner['type'] : null;
$function = $owner['function'];
$class = isset($owner['class']) ? $owner['class'] : null;
$server_type = api_get_setting('server_type');
if (!empty($line) && !empty($server_type) && $server_type != 'production') {
$info = '<pre>' .
'<strong>DATABASE ERROR #'.self::errno($connection).':</strong><br /> ' .
self::remove_XSS(self::error($connection)) . '<br />' .
'<strong>QUERY :</strong><br /> ' .
self::remove_XSS($query) . '<br />' .
'<strong>FILE :</strong><br /> ' .
(empty($file) ? ' unknown ' : $file) . '<br />' .
'<strong>LINE :</strong><br /> ' .
(empty($line) ? ' unknown ' : $line) . '<br />';
if (empty($type)) {
if (!empty($function)) {
$info .= '<strong>FUNCTION :</strong><br /> ' . $function;
}
} else {
if (!empty($class) && !empty($function)) {
$info .= '<strong>CLASS :</strong><br /> ' . $class . '<br />';
$info .= '<strong>METHOD :</strong><br /> ' . $function;
}
}
$info .= '</pre>';
echo $info;
}
if (isset(self::$log_queries) && self::$log_queries) {
error_log("---------------- SQL error ---------------- ");
error_log($query);
error_log('error #'.self::errno($connection));
error_log('error: '.self::error($connection));
$info = 'FILE: ' .(empty($file) ? ' unknown ' : $file);
$info .= ' +'.(empty($line) ? ' unknown ' : $line);
error_log($info);
if (empty($type)) {
if (!empty($function)) {
$info = 'FUNCTION: ' . $function;
error_log($info);
}
} else {
if (!empty($class) && !empty($function)) {
$info = 'CLASS: ' . $class.' METHOD: '.$function;
error_log($info);
}
}
error_log("---------------- end ----------------");
}
}
return $result;
}
/**
* @param string $option
*
* @return int
*/
public static function customOptionToDoctrineOption($option)
@ -612,16 +338,6 @@ class Database
}
}
/**
* Selects a database.
* @param string $database_name The name of the database that is to be selected.
* @param resource $connection (optional) The database server connection, for detailed description see the method query().
* @return bool Returns TRUE on success or FALSE on failure.
*/
public static function select_db($database_name, $connection = null) {
return self::use_default_connection($connection) ? mysql_select_db($database_name) : mysql_select_db($database_name, $connection);
}
/**
* Stores a query result into an array.
*
@ -633,238 +349,6 @@ class Database
public static function store_result(Statement $result, $option = 'BOTH')
{
return $result->fetchAll(self::customOptionToDoctrineOption($option));
$array = array();
if ($result !== false) { // For isolation from database engine's behaviour.
while ($row = self::fetch_array($result, $option)) {
$array[] = $row;
}
}
return $array;
}
/*
Encodings and collations supported by MySQL database server
*/
/**
* Checks whether a given encoding is supported by the database server.
* @param string $encoding The encoding (a system conventional id, for example 'UTF-8') to be checked.
* @return bool Returns a boolean value as a check-result.
* @author Ivan Tcholakov
*/
public static function is_encoding_supported($encoding) {
static $supported = array();
if (!isset($supported[$encoding])) {
$supported[$encoding] = false;
if (strlen($db_encoding = self::to_db_encoding($encoding)) > 0) {
if (self::num_rows(self::query("SHOW CHARACTER SET WHERE Charset = '".self::escape_string($db_encoding)."';")) > 0) {
$supported[$encoding] = true;
}
}
}
return $supported[$encoding];
}
/**
* Constructs a SQL clause about default character set and default collation for newly created databases and tables.
* Example: Database::make_charset_clause('UTF-8', 'bulgarian') returns
* DEFAULT CHARACTER SET `utf8` DEFAULT COLLATE `utf8_general_ci`
* @param string $encoding (optional) The default database/table encoding (a system conventional id) to be used.
* @param string $language (optional) Language (a system conventional id) used for choosing language sensitive collation (if it is possible).
* @return string Returns the constructed SQL clause or empty string if $encoding is not correct or is not supported.
* @author Ivan Tcholakov
*/
public static function make_charset_clause($encoding = null, $language = null) {
if (empty($encoding)) {
$encoding = api_get_system_encoding();
}
if (empty($language)) {
$language = api_get_interface_language();
}
$charset_clause = '';
if (self::is_encoding_supported($encoding)) {
$db_encoding = Database::to_db_encoding($encoding);
$charset_clause .= " DEFAULT CHARACTER SET `".$db_encoding."`";
$db_collation = Database::to_db_collation($encoding, $language);
if (!empty($db_collation)) {
$charset_clause .= " DEFAULT COLLATE `".$db_collation."`";
}
}
return $charset_clause;
}
/**
* Converts an encoding identificator to MySQL-specific encoding identifictor,
* i.e. 'UTF-8' --> 'utf8'.
* @param string $encoding The conventional encoding identificator.
* @return string Returns the corresponding MySQL-specific encoding identificator if any, otherwise returns NULL.
* @author Ivan Tcholakov
*/
public static function to_db_encoding($encoding) {
static $result = array();
if (!isset($result[$encoding])) {
$result[$encoding] = null;
$encoding_map = & self::get_db_encoding_map();
foreach ($encoding_map as $key => $value) {
if (api_equal_encodings($encoding, $key)) {
$result[$encoding] = $value;
break;
}
}
}
return $result[$encoding];
}
/**
* Converts a MySQL-specific encoding identifictor to conventional encoding identificator,
* i.e. 'utf8' --> 'UTF-8'.
* @param string $encoding The MySQL-specific encoding identificator.
* @return string Returns the corresponding conventional encoding identificator if any, otherwise returns NULL.
* @author Ivan Tcholakov
*/
public static function from_db_encoding($db_encoding) {
static $result = array();
if (!isset($result[$db_encoding])) {
$result[$db_encoding] = null;
$encoding_map = & self::get_db_encoding_map();
foreach ($encoding_map as $key => $value) {
if (strtolower($db_encoding) == $value) {
$result[$db_encoding] = $key;
break;
}
}
}
return $result[$db_encoding];
}
/**
* Chooses the default MySQL-specific collation from given encoding and language.
* @param string $encoding A conventional encoding id, i.e. 'UTF-8'
* @param string $language (optional) A conventional for the system language id, i.e. 'bulgarian'. If it is empty, the chosen collation is the default server value corresponding to the given encoding.
* @return string Returns a suitable default collation, for example 'utf8_general_ci', or NULL if collation was not found.
* @author Ivan Tcholakov
*/
public static function to_db_collation($encoding, $language = null) {
static $result = array();
if (!isset($result[$encoding][$language])) {
$result[$encoding][$language] = null;
if (self::is_encoding_supported($encoding)) {
$db_encoding = self::to_db_encoding($encoding);
if (!empty($language)) {
$lang = api_purify_language_id($language);
$res = self::check_db_collation($db_encoding, $lang);
if (empty($res)) {
$db_collation_map = & self::get_db_collation_map();
if (isset($db_collation_map[$lang])) {
$res = self::check_db_collation($db_encoding, $db_collation_map[$lang]);
}
}
if (empty($res)) {
$res = self::check_db_collation($db_encoding, null);
}
$result[$encoding][$language] = $res;
} else {
$result[$encoding][$language] = self::check_db_collation($db_encoding, null);
}
}
}
return $result[$encoding][$language];
}
/*
Private methods
You should not access these from outside the class
No effort is made to keep the names / results the same.
*/
/**
* This private method is to be used by the other methods in this class for
* checking whether the input parameter $connection actually has been provided.
* If the input parameter connection is not a resource or if it is not FALSE (in case of error)
* then the default opened connection should be used by the called method.
* @param resource/boolean $connection The checked parameter $connection.
* @return boolean TRUE means that calling method should use the default connection.
* FALSE means that (valid) parameter $connection has been provided and it should be used.
*/
private static function use_default_connection($connection) {
return !is_resource($connection) && $connection !== false;
}
/**
* This private method encapsulates a table with relations between
* conventional and MuSQL-specific encoding identificators.
* @author Ivan Tcholakov
*/
private static function & get_db_encoding_map() {
static $encoding_map = array(
'ARMSCII-8' => 'armscii8',
'BIG5' => 'big5',
'BINARY' => 'binary',
'CP866' => 'cp866',
'EUC-JP' => 'ujis',
'EUC-KR' => 'euckr',
'GB2312' => 'gb2312',
'GBK' => 'gbk',
'ISO-8859-1' => 'latin1',
'ISO-8859-2' => 'latin2',
'ISO-8859-7' => 'greek',
'ISO-8859-8' => 'hebrew',
'ISO-8859-9' => 'latin5',
'ISO-8859-13' => 'latin7',
'ISO-8859-15' => 'latin1',
'KOI8-R' => 'koi8r',
'KOI8-U' => 'koi8u',
'SHIFT-JIS' => 'sjis',
'TIS-620' => 'tis620',
'US-ASCII' => 'ascii',
'UTF-8' => 'utf8',
'WINDOWS-1250' => 'cp1250',
'WINDOWS-1251' => 'cp1251',
'WINDOWS-1252' => 'latin1',
'WINDOWS-1256' => 'cp1256',
'WINDOWS-1257' => 'cp1257'
);
return $encoding_map;
}
/**
* A helper language id translation table for choosing some collations.
* @author Ivan Tcholakov
*/
private static function & get_db_collation_map() {
static $db_collation_map = array(
'german' => 'german2',
'simpl_chinese' => 'chinese',
'trad_chinese' => 'chinese',
'turkce' => 'turkish'
);
return $db_collation_map;
}
/**
* Constructs a MySQL-specific collation and checks whether it is supported by the database server.
* @param string $db_encoding A MySQL-specific encoding id, i.e. 'utf8'
* @param string $language A MySQL-compatible language id, i.e. 'bulgarian'
* @return string Returns a suitable default collation, for example 'utf8_general_ci', or NULL if collation was not found.
* @author Ivan Tcholakov
*/
private static function check_db_collation($db_encoding, $language) {
if (empty($db_encoding)) {
return null;
}
if (empty($language)) {
$result = self::fetch_array(self::query("SHOW COLLATION WHERE Charset = '".self::escape_string($db_encoding)."' AND `Default` = 'Yes';"), 'NUM');
return $result ? $result[0] : null;
}
$collation = $db_encoding.'_'.$language.'_ci';
$query_result = self::query("SHOW COLLATION WHERE Charset = '".self::escape_string($db_encoding)."';");
while ($result = self::fetch_array($query_result, 'NUM')) {
if ($result[0] == $collation) {
return $collation;
}
}
return null;
}
/**
@ -878,31 +362,9 @@ class Database
{
$result = self::getManager()->getConnection()->insert($table_name, $attributes);
if ($result) {
return self::insert_id();
}
return false;
if (empty($attributes) || empty($table_name)) {
return false;
}
$filtred_attributes = array();
foreach($attributes as $key => $value) {
$filtred_attributes[$key] = "'".self::escape_string($value)."'";
}
//@todo check if the field exists in the table we should use a describe of that table
$params = array_keys($filtred_attributes);
$values = array_values($filtred_attributes);
if (!empty($params) && !empty($values)) {
$sql = 'INSERT INTO '.$table_name.' ('.implode(',',$params).') VALUES ('.implode(',',$values).')';
self::query($sql);
if ($show_query) {
var_dump($sql);
error_log($sql);
}
return self::insert_id();
}
return false;
}
/**
@ -943,6 +405,7 @@ class Database
} else {
$array = self::fetch_array($result, $option);
}
return $array;
}

@ -225,13 +225,13 @@ class Diagnoser
// A note: Maybe it would be better if all "MySQL"-like variable names and words on the page to be replaced with "Database"-like ones.
$array[] = $this->build_setting(self :: STATUS_INFORMATION, '[MySQL]', 'mysql_get_host_info()', 'http://www.php.net/manual/en/function.mysql-get-host-info.php', Database::get_host_info(), null, null, get_lang('MysqlHostInfo'));
$array[] = $this->build_setting(self :: STATUS_INFORMATION, '[MySQL]', 'host', 'http://www.php.net/manual/en/function.mysql-get-host-info.php', Database::get_host_info(), null, null, get_lang('MysqlHostInfo'));
/*
$array[] = $this->build_setting(self :: STATUS_INFORMATION, '[MySQL]', 'mysql_get_server_info()', 'http://www.php.net/manual/en/function.mysql-get-server-info.php', Database::get_server_info(), null, null, get_lang('MysqlServerInfo'));
$array[] = $this->build_setting(self :: STATUS_INFORMATION, '[MySQL]', 'mysql_get_proto_info()', 'http://www.php.net/manual/en/function.mysql-get-proto-info.php', Database::get_proto_info(), null, null, get_lang('MysqlProtoInfo'));
$array[] = $this->build_setting(self :: STATUS_INFORMATION, '[MySQL]', 'mysql_get_client_info()', 'http://www.php.net/manual/en/function.mysql-get-client-info.php', Database::get_client_info(), null, null, get_lang('MysqlClientInfo'));
$array[] = $this->build_setting(self :: STATUS_INFORMATION, '[MySQL]', 'mysql_get_client_info()', 'http://www.php.net/manual/en/function.mysql-get-client-info.php', Database::get_client_info(), null, null, get_lang('MysqlClientInfo'));*/
return $array;
}

@ -31,6 +31,10 @@ class SessionHandlerDatabase {
$this->connection_handler = false;
}
/**
* @deprecated don't use
* @return bool
*/
public function sqlConnect() {
if (!$this->connection_handler) {

@ -45,6 +45,9 @@ class SessionHandlerMemcache
$this->connection_handler = false;
}
/**
*@deprecated
* */
public function sqlConnect()
{
if (!$this->connection_handler) {

@ -1,8 +1,8 @@
<?php
/**
* Install database. Provides access to the Database class and allows to add
* hooks for logging, testing, etc during installation.
* Install database. Provides access to the Database class and allows to add
* hooks for logging, testing, etc during installation.
*
* @license see /license.txt
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
@ -22,13 +22,6 @@ class iDatabase extends Database
self::$is_logging = $value;
}
static function select_db($database_name, $connection = null)
{
if (self::is_logging()) {
Log::notice(__FUNCTION__ . ' ' . $database_name, Log::frame(1));
}
return parent::select_db($database_name, $connection);
}
static function query($query, $connection = null, $file = null, $line = null)
{
@ -54,7 +47,7 @@ class iDatabase extends Database
* Returns true if the table exists in the database, false otherwise.
* @param string $database
* @param string table
* @return boolean
* @return boolean
*/
static

@ -768,8 +768,6 @@ if (@$_POST['step2']) {
// Initialization of the database connection encoding intentionaly is not done.
// This is the old style for connecting to the database server, that is implemented here.
// Inializing global variables that are to be used by the included scripts.
$dblist = Database::get_databases();
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();

@ -604,7 +604,6 @@ function get_config_param_from_db($host, $login, $pass, $dbName, $param = '')
{
Database::connect(array('server' => $host, 'username' => $login, 'password' => $pass));
Database::query("set session sql_mode='';"); // Disabling special SQL modes (MySQL 5)
Database::select_db($dbName);
if (($res = Database::query("SELECT * FROM settings_current WHERE variable = '$param'")) !== false) {
if (Database::num_rows($res) > 0) {
@ -1932,9 +1931,8 @@ function display_database_settings_form(
<?php echo $database_exists_text ?>
<div id="db_status" class="confirmation-message">
Database host: <strong><?php echo $manager->getConnection()->getHost(); ?></strong><br />
Database server version: <strong><?php //echo Database::get_server_info(); ?></strong><br />
Database client version: <strong><?php //echo Database::get_client_info(); ?></strong><br />
Database protocol version: <strong><?php //echo Database::get_proto_info(); ?></strong>
Database port: <strong><?php echo $manager->getConnection()->getPort(); ?></strong><br />
Database platform: <strong><?php echo $manager->getConnection()->getDatabasePlatform()->getName(); ?></strong><br />
<div style="clear:both;"></div>
</div>
</td>
@ -1944,8 +1942,6 @@ function display_database_settings_form(
<div id="db_status" style="float:left;" class="error-message">
<div style="float:left;">
<strong><?php echo get_lang('FailedConectionDatabase'); ?></strong><br />
<strong>Database error: <?php echo Database::errno(); ?></strong><br />
<?php echo Database::error().'<br />'; ?>
</div>
</div>
</td>

@ -101,8 +101,6 @@ if (!defined('CLI_INSTALLATION')) {
}
}
//Database::select_db($mysqlMainDb) or die(Database::error());
$installation_settings = array();
$installation_settings['{ORGANISATIONNAME}'] = $institutionForm;
$installation_settings['{ORGANISATIONURL}'] = $institutionUrlForm;

@ -71,7 +71,6 @@ if (defined('SYSTEM_INSTALLATION')) {
} elseif (!in_array($dbNameForm, $dblist)) {
Log::error('Database ' . $dbNameForm . ' was not found, skipping');
} else {
iDatabase::select_db($dbNameForm);
foreach ($mainQueriesList as $query) {
if ($onlyTest) {
Log::notice("iDatabase::query($dbNameForm,$query)");
@ -104,7 +103,6 @@ if (defined('SYSTEM_INSTALLATION')) {
} elseif (!in_array($dbNameForm, $dblist)) {
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
iDatabase::select_db($dbNameForm);
$res = iDatabase::query(
"SELECT id, code, db_name, directory, course_language, id as real_id "
." FROM course WHERE target_course_code IS NULL ORDER BY code"
@ -124,9 +122,6 @@ if (defined('SYSTEM_INSTALLATION')) {
}
foreach ($list as $rowCourse) {
if (!$singleDbForm) { // otherwise just use the main one
iDatabase::select_db($rowCourse['db_name']);
}
Log::notice('Course db ' . $rowCourse['db_name']);
// Now use the $c_q_list
@ -165,7 +160,6 @@ if (defined('SYSTEM_INSTALLATION')) {
} elseif (!in_array($dbNameForm, $dblist)) {
Log::error('Database ' . $dbNameForm . ' was not found, skipping');
} else {
iDatabase::select_db($dbNameForm);
foreach ($mainQueriesList as $query) {
if ($onlyTest) {
Log::notice("iDatabase::query($dbNameForm,$query)");

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save