explicitly set charset / collation of database when installing + new integrity-check-function to validate the database charset / collation and optionally fix it; fixes #1426
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -567,7 +567,7 @@ class FroxlorInstall {
|
|||||||
|
|
||||||
// we have to create a new user and database for the froxlor unprivileged mysql access
|
// we have to create a new user and database for the froxlor unprivileged mysql access
|
||||||
$content .= $this->_status_message('begin', $this->_lng['install']['create_mysqluser_and_db']);
|
$content .= $this->_status_message('begin', $this->_lng['install']['create_mysqluser_and_db']);
|
||||||
$ins_stmt = $db_root->prepare("CREATE DATABASE `".str_replace('`', '', $this->_data['mysql_database'])."`");
|
$ins_stmt = $db_root->prepare("CREATE DATABASE `".str_replace('`', '', $this->_data['mysql_database'])."` CHARACTER SET=utf8 COLLATE=utf8_general_ci");
|
||||||
$ins_stmt->execute();
|
$ins_stmt->execute();
|
||||||
|
|
||||||
$mysql_access_host_array = array_map('trim', explode(',', $this->_data['mysql_access_host']));
|
$mysql_access_host_array = array_map('trim', explode(',', $this->_data['mysql_access_host']));
|
||||||
|
|||||||
@@ -58,6 +58,41 @@ class IntegrityCheck {
|
|||||||
return $integrityok;
|
return $integrityok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check whether the froxlor database and its tables are in utf-8 character-set
|
||||||
|
*
|
||||||
|
* @param bool $fix fix db charset/collation if not utf8
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function DatabaseCharset($fix = false) {
|
||||||
|
|
||||||
|
// get characterset
|
||||||
|
$cs_stmt = Database::prepare('SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = :dbname');
|
||||||
|
$resp = Database::pexecute_first($cs_stmt, array('dbname' => Database::getDbName()));
|
||||||
|
$charset = isset($resp['default_character_set_name']) ? $resp['default_character_set_name'] : null;
|
||||||
|
if (!empty($charset) && strtolower($charset) != 'utf8') {
|
||||||
|
if ($fix) {
|
||||||
|
// fix database
|
||||||
|
Database::query('ALTER DATABASE `' . Database::getDbName() . '` CHARACTER SET utf8 COLLATE utf8_general_ci');
|
||||||
|
// fix all tables
|
||||||
|
$handle = Database::query('SHOW TABLES');
|
||||||
|
while ($row = $handle->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
foreach ($row as $table) {
|
||||||
|
Database::query('ALTER TABLE `' . $table . '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fix) {
|
||||||
|
return $this->DatabaseCharset();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the integrity of the domain to ip/port - association
|
* Check the integrity of the domain to ip/port - association
|
||||||
* @param $fix Fix everything found directly
|
* @param $fix Fix everything found directly
|
||||||
|
|||||||
Reference in New Issue
Block a user