[*] IN : removed the possibility to choose his own storage engine, automatically select the best one
This commit is contained in:
+3
-1
@@ -170,6 +170,8 @@ abstract class DbCore
|
|||||||
/* do not remove, useful for some modules */
|
/* do not remove, useful for some modules */
|
||||||
abstract public function set_db($db_name);
|
abstract public function set_db($db_name);
|
||||||
|
|
||||||
|
abstract public function getBestEngine();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Db object instance
|
* Get Db object instance
|
||||||
*
|
*
|
||||||
@@ -674,7 +676,7 @@ abstract class DbCore
|
|||||||
return call_user_func_array(array(Db::getClass(), 'hasTableWithSamePrefix'), array($server, $user, $pwd, $db, $prefix));
|
return call_user_func_array(array(Db::getClass(), 'hasTableWithSamePrefix'), array($server, $user, $pwd, $db, $prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkCreatePrivilege($server, $user, $pwd, $db, $prefix, $engine)
|
public static function checkCreatePrivilege($server, $user, $pwd, $db, $prefix, $engine = null)
|
||||||
{
|
{
|
||||||
return call_user_func_array(array(Db::getClass(), 'checkCreatePrivilege'), array($server, $user, $pwd, $db, $prefix, $engine));
|
return call_user_func_array(array(Db::getClass(), 'checkCreatePrivilege'), array($server, $user, $pwd, $db, $prefix, $engine));
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-11
@@ -172,21 +172,36 @@ class DbMySQLiCore extends Db
|
|||||||
if (!$link->real_connect($server, $user, $pwd, $db))
|
if (!$link->real_connect($server, $user, $pwd, $db))
|
||||||
return (mysqli_connect_errno() == 1049) ? 2 : 1;
|
return (mysqli_connect_errno() == 1049) ? 2 : 1;
|
||||||
|
|
||||||
if (strtolower($engine) == 'innodb')
|
|
||||||
{
|
|
||||||
$sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\'';
|
|
||||||
$result = $link->query($sql);
|
|
||||||
if (!$result)
|
|
||||||
return 4;
|
|
||||||
$row = $result->fetch_assoc();
|
|
||||||
if (!$row || strtolower($row['Value']) != 'yes')
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
$link->close();
|
$link->close();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkCreatePrivilege($server, $user, $pwd, $db, $prefix, $engine)
|
public function getBestEngine()
|
||||||
|
{
|
||||||
|
$value = 'InnoDB';
|
||||||
|
|
||||||
|
$sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\'';
|
||||||
|
$result = $link->query($sql);
|
||||||
|
if (!$result)
|
||||||
|
$value = 'MyISAM';
|
||||||
|
$row = $result->fetch_assoc();
|
||||||
|
if (!$row || strtolower($row['Value']) != 'yes')
|
||||||
|
$value = 'MyISAM';
|
||||||
|
|
||||||
|
/* MySQL >= 5.6 */
|
||||||
|
$sql = 'SHOW ENGINES';
|
||||||
|
$result = $link->query($sql);
|
||||||
|
while ($row = $result->fetch_assoc())
|
||||||
|
if ($row['Engine'] == 'InnoDB')
|
||||||
|
{
|
||||||
|
if (in_array($row['Support'], array('DEFAULT', 'YES')))
|
||||||
|
$value = 'InnoDB';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function checkCreatePrivilege($server, $user, $pwd, $db, $prefix, $engine = null)
|
||||||
{
|
{
|
||||||
$link = @new mysqli($server, $user, $pwd, $db);
|
$link = @new mysqli($server, $user, $pwd, $db);
|
||||||
if (mysqli_connect_error())
|
if (mysqli_connect_error())
|
||||||
|
|||||||
+26
-26
@@ -174,7 +174,7 @@ class DbPDOCore extends Db
|
|||||||
return (bool)$result->fetch();
|
return (bool)$result->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkCreatePrivilege($server, $user, $pwd, $db, $prefix, $engine)
|
public static function checkCreatePrivilege($server, $user, $pwd, $db, $prefix, $engine = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$link = DbPDO::_getPDO($server, $user, $pwd, $db, 5);
|
$link = DbPDO::_getPDO($server, $user, $pwd, $db, 5);
|
||||||
@@ -206,35 +206,35 @@ class DbPDOCore extends Db
|
|||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
return ($e->getCode() == 1049) ? 2 : 1;
|
return ($e->getCode() == 1049) ? 2 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strtolower($engine) == 'innodb')
|
|
||||||
{
|
|
||||||
$value = 0;
|
|
||||||
|
|
||||||
$sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\'';
|
|
||||||
$result = $link->query($sql);
|
|
||||||
if (!$result)
|
|
||||||
$value = 4;
|
|
||||||
$row = $result->fetch();
|
|
||||||
if (!$row || strtolower($row['Value']) != 'yes')
|
|
||||||
$value = 4;
|
|
||||||
|
|
||||||
/* MySQL >= 5.6 */
|
|
||||||
$sql = 'SHOW ENGINES';
|
|
||||||
$result = $link->query($sql);
|
|
||||||
while ($row = $result->fetch())
|
|
||||||
if ($row['Engine'] == 'InnoDB')
|
|
||||||
{
|
|
||||||
if (in_array($row['Support'], array('DEFAULT', 'YES')))
|
|
||||||
$value = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
unset($link);
|
unset($link);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getBestEngine()
|
||||||
|
{
|
||||||
|
$value = 'InnoDB';
|
||||||
|
|
||||||
|
$sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\'';
|
||||||
|
$result = $link->query($sql);
|
||||||
|
if (!$result)
|
||||||
|
$value = 'MyISAM';
|
||||||
|
$row = $result->fetch();
|
||||||
|
if (!$row || strtolower($row['Value']) != 'yes')
|
||||||
|
$value = 'MyISAM';
|
||||||
|
|
||||||
|
/* MySQL >= 5.6 */
|
||||||
|
$sql = 'SHOW ENGINES';
|
||||||
|
$result = $link->query($sql);
|
||||||
|
while ($row = $result->fetch())
|
||||||
|
if ($row['Engine'] == 'InnoDB')
|
||||||
|
{
|
||||||
|
if (in_array($row['Support'], array('DEFAULT', 'YES')))
|
||||||
|
$value = 'InnoDB';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Db::checkEncoding()
|
* @see Db::checkEncoding()
|
||||||
*/
|
*/
|
||||||
|
|||||||
+26
-26
@@ -165,36 +165,36 @@ class MySQLCore extends Db
|
|||||||
return 1;
|
return 1;
|
||||||
if (!@mysql_select_db($db, $link))
|
if (!@mysql_select_db($db, $link))
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
if (strtolower($engine) == 'innodb')
|
|
||||||
{
|
|
||||||
$value = 0;
|
|
||||||
|
|
||||||
$sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\'';
|
|
||||||
$result = mysql_query($sql);
|
|
||||||
if (!$result)
|
|
||||||
$value = 4;
|
|
||||||
$row = mysql_fetch_assoc($result);
|
|
||||||
if (!$row || strtolower($row['Value']) != 'yes')
|
|
||||||
$value = 4;
|
|
||||||
|
|
||||||
/* MySQL >= 5.6 */
|
|
||||||
$sql = 'SHOW ENGINES';
|
|
||||||
$result = mysql_query($sql);
|
|
||||||
while ($row = mysql_fetch_assoc($result))
|
|
||||||
if ($row['Engine'] == 'InnoDB')
|
|
||||||
{
|
|
||||||
if (in_array($row['Support'], array('DEFAULT', 'YES')))
|
|
||||||
$value = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
@mysql_close($link);
|
@mysql_close($link);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function checkCreatePrivilege($server, $user, $pwd, $db, $prefix, $engine)
|
public function getBestEngine()
|
||||||
|
{
|
||||||
|
$value = 'InnoDB';
|
||||||
|
|
||||||
|
$sql = 'SHOW VARIABLES WHERE Variable_name = \'have_innodb\'';
|
||||||
|
$result = mysql_query($sql);
|
||||||
|
if (!$result)
|
||||||
|
$value = 'MyISAM';
|
||||||
|
$row = mysql_fetch_assoc($result);
|
||||||
|
if (!$row || strtolower($row['Value']) != 'yes')
|
||||||
|
$value = 'MyISAM';
|
||||||
|
|
||||||
|
/* MySQL >= 5.6 */
|
||||||
|
$sql = 'SHOW ENGINES';
|
||||||
|
$result = mysql_query($sql);
|
||||||
|
while ($row = mysql_fetch_assoc($result))
|
||||||
|
if ($row['Engine'] == 'InnoDB')
|
||||||
|
{
|
||||||
|
if (in_array($row['Support'], array('DEFAULT', 'YES')))
|
||||||
|
$value = 'InnoDB';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function checkCreatePrivilege($server, $user, $pwd, $db, $prefix, $engine = null)
|
||||||
{
|
{
|
||||||
ini_set('mysql.connect_timeout', 5);
|
ini_set('mysql.connect_timeout', 5);
|
||||||
if (!$link = @mysql_connect($server, $user, $pwd, true))
|
if (!$link = @mysql_connect($server, $user, $pwd, true))
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ class InstallControllerHttpDatabase extends InstallControllerHttp
|
|||||||
$this->session->database_login = trim(Tools::getValue('dbLogin'));
|
$this->session->database_login = trim(Tools::getValue('dbLogin'));
|
||||||
$this->session->database_password = trim(Tools::getValue('dbPassword'));
|
$this->session->database_password = trim(Tools::getValue('dbPassword'));
|
||||||
$this->session->database_prefix = trim(Tools::getValue('db_prefix'));
|
$this->session->database_prefix = trim(Tools::getValue('db_prefix'));
|
||||||
$this->session->database_engine = Tools::getValue('dbEngine');
|
|
||||||
$this->session->database_clear = Tools::getValue('database_clear');
|
$this->session->database_clear = Tools::getValue('database_clear');
|
||||||
|
|
||||||
// Save email config
|
// Save email config
|
||||||
@@ -81,13 +80,15 @@ class InstallControllerHttpDatabase extends InstallControllerHttp
|
|||||||
$this->session->database_login,
|
$this->session->database_login,
|
||||||
$this->session->database_password,
|
$this->session->database_password,
|
||||||
$this->session->database_prefix,
|
$this->session->database_prefix,
|
||||||
$this->session->database_engine,
|
|
||||||
|
|
||||||
// We do not want to validate table prefix if we are already in install process
|
// We do not want to validate table prefix if we are already in install process
|
||||||
($this->session->step == 'process') ? true : $this->session->database_clear
|
($this->session->step == 'process') ? true : $this->session->database_clear
|
||||||
);
|
);
|
||||||
|
if (count($this->errors))
|
||||||
|
return false;
|
||||||
|
|
||||||
return count($this->errors) ? false : true;
|
if (!isset($this->session->database_engine))
|
||||||
|
$this->session->database_engine = $this->model_database->getBestEngine($this->session->database_server, $this->session->database_name, $this->session->database_login, $this->session->database_password);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function process()
|
public function process()
|
||||||
@@ -108,10 +109,9 @@ class InstallControllerHttpDatabase extends InstallControllerHttp
|
|||||||
$login = Tools::getValue('dbLogin');
|
$login = Tools::getValue('dbLogin');
|
||||||
$password = Tools::getValue('dbPassword');
|
$password = Tools::getValue('dbPassword');
|
||||||
$prefix = Tools::getValue('db_prefix');
|
$prefix = Tools::getValue('db_prefix');
|
||||||
$engine = Tools::getValue('dbEngine');
|
|
||||||
$clear = Tools::getValue('clear');
|
$clear = Tools::getValue('clear');
|
||||||
|
|
||||||
$errors = $this->model_database->testDatabaseSettings($server, $database, $login, $password, $prefix, $engine, $clear);
|
$errors = $this->model_database->testDatabaseSettings($server, $database, $login, $password, $prefix, $clear);
|
||||||
|
|
||||||
$this->ajaxJsonAnswer(
|
$this->ajaxJsonAnswer(
|
||||||
(count($errors)) ? false : true,
|
(count($errors)) ? false : true,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class InstallModelDatabase extends InstallAbstractModel
|
|||||||
* @param bool $clear
|
* @param bool $clear
|
||||||
* @return array List of errors
|
* @return array List of errors
|
||||||
*/
|
*/
|
||||||
public function testDatabaseSettings($server, $database, $login, $password, $prefix, $engine, $clear = false)
|
public function testDatabaseSettings($server, $database, $login, $password, $prefix, $clear = false)
|
||||||
{
|
{
|
||||||
$errors = array();
|
$errors = array();
|
||||||
|
|
||||||
@@ -55,14 +55,11 @@ class InstallModelDatabase extends InstallAbstractModel
|
|||||||
if ($prefix && !Validate::isTablePrefix($prefix))
|
if ($prefix && !Validate::isTablePrefix($prefix))
|
||||||
$errors[] = $this->language->l('Tables prefix is invalid');
|
$errors[] = $this->language->l('Tables prefix is invalid');
|
||||||
|
|
||||||
if (!Validate::isMySQLEngine($engine))
|
|
||||||
$errors[] = $this->language->l('Wrong engine chosen for MySQL');
|
|
||||||
|
|
||||||
if (!$errors)
|
if (!$errors)
|
||||||
{
|
{
|
||||||
$dbtype = ' ('.Db::getClass().')';
|
$dbtype = ' ('.Db::getClass().')';
|
||||||
// Try to connect to database
|
// Try to connect to database
|
||||||
switch (Db::checkConnection($server, $login, $password, $database, true, $engine))
|
switch (Db::checkConnection($server, $login, $password, $database, true))
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if (!Db::checkEncoding($server, $login, $password))
|
if (!Db::checkEncoding($server, $login, $password))
|
||||||
@@ -71,28 +68,33 @@ class InstallModelDatabase extends InstallAbstractModel
|
|||||||
// Check if a table with same prefix already exists
|
// Check if a table with same prefix already exists
|
||||||
if (!$clear && Db::hasTableWithSamePrefix($server, $login, $password, $database, $prefix))
|
if (!$clear && Db::hasTableWithSamePrefix($server, $login, $password, $database, $prefix))
|
||||||
$errors[] = $this->language->l('At least one table with same prefix was already found, please change your prefix or drop your database');
|
$errors[] = $this->language->l('At least one table with same prefix was already found, please change your prefix or drop your database');
|
||||||
if (($create_error = Db::checkCreatePrivilege($server, $login, $password, $database, $prefix, $engine)) !== true)
|
if (($create_error = Db::checkCreatePrivilege($server, $login, $password, $database, $prefix)) !== true)
|
||||||
{
|
{
|
||||||
$errors[] = $this->language->l(sprintf('Your database login don\'t have the privileges to create table on the database "%s". Ask your hosting provider:', $database));
|
$errors[] = $this->language->l(sprintf('Your database login don\'t have the privileges to create table on the database "%s". Ask your hosting provider:', $database));
|
||||||
if ($create_error != false)
|
if ($create_error != false)
|
||||||
$errors[] = $create_error;
|
$errors[] = $create_error;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
$errors[] = $this->language->l('Database Server is not found. Please verify the login, password and server fields').$dbtype;
|
$errors[] = $this->language->l('Database Server is not found. Please verify the login, password and server fields').$dbtype;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
$errors[] = $this->language->l('Connection to MySQL server succeeded, but database "%s" not found', $database).$dbtype;
|
$errors[] = $this->language->l('Connection to MySQL server succeeded, but database "%s" not found', $database).$dbtype;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
|
||||||
$errors[] = $this->language->l('Engine innoDB is not supported by your MySQL server, please use MyISAM').$dbtype;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getBestEngine($server, $database, $login, $password)
|
||||||
|
{
|
||||||
|
$class = Db::getClass();
|
||||||
|
$instance = new $class($server, $login, $password, $database, true);
|
||||||
|
$engine = $instance->getBestEngine();
|
||||||
|
unset($instance);
|
||||||
|
return $engine;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,13 +27,14 @@
|
|||||||
<label for="dbPassword"><?php echo $this->l('Database password:') ?> </label>
|
<label for="dbPassword"><?php echo $this->l('Database password:') ?> </label>
|
||||||
<input class="text" size="10" type="password" id="dbPassword" name="dbPassword" value="<?php echo htmlspecialchars($this->database_password) ?>" />
|
<input class="text" size="10" type="password" id="dbPassword" name="dbPassword" value="<?php echo htmlspecialchars($this->database_password) ?>" />
|
||||||
</p>
|
</p>
|
||||||
|
<!--
|
||||||
<p>
|
<p>
|
||||||
<label for="dbEngine"><?php echo $this->l('Database Engine:') ?></label>
|
<label for="dbEngine"><?php echo $this->l('Database Engine:') ?></label>
|
||||||
<select id="dbEngine" name="dbEngine">
|
<select id="dbEngine" name="dbEngine">
|
||||||
<option value="InnoDB" <?php if ($this->database_engine == 'InnoDB'): ?>selected="selected"<?php endif; ?>>InnoDB</option>
|
<option value="InnoDB" <?php if ($this->database_engine == 'InnoDB'): ?>selected="selected"<?php endif; ?>>InnoDB</option>
|
||||||
<option value="MyISAM" <?php if ($this->database_engine == 'MyISAM'): ?>selected="selected"<?php endif; ?>>MyISAM</option>
|
<option value="MyISAM" <?php if ($this->database_engine == 'MyISAM'): ?>selected="selected"<?php endif; ?>>MyISAM</option>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>-->
|
||||||
<p>
|
<p>
|
||||||
<label for="db_prefix"><?php echo $this->l('Tables prefix:')?></label>
|
<label for="db_prefix"><?php echo $this->l('Tables prefix:')?></label>
|
||||||
<input class="text" type="text" id="db_prefix" name="db_prefix" value="<?php echo htmlspecialchars($this->database_prefix) ?>" />
|
<input class="text" type="text" id="db_prefix" name="db_prefix" value="<?php echo htmlspecialchars($this->database_prefix) ?>" />
|
||||||
|
|||||||
Reference in New Issue
Block a user