Permalink
Browse files

cherry-pick: Checking MySQL version to set sql_mode automatically the…

  • Loading branch information...
roadster31 authored and gillesbourgeat committed Feb 25, 2016
1 parent 292b0db commit e61c5e67154362d3e3c13b491f5bcfce5a242c90
Showing with 27 additions and 0 deletions.
  1. +27 −0 core/lib/Thelia/Core/Thelia.php
@@ -96,6 +96,33 @@ protected function initPropel()
$serviceContainer->setLogger('defaultLogger', Tlog::getInstance());
$con->useDebug(true);
}
// MySQL 5.6+ compatibility
$result = $con->query("SELECT VERSION() as version, @@GLOBAL.sql_mode as global_sql_mode, @@SESSION.sql_mode as session_sql_mode");
if ($result && $data = $result->fetch(\PDO::FETCH_ASSOC)) {
// MariaDB is not impacted by this problem
if (false === strpos($data['version'], 'MariaDB') && version_compare($data['version'], '5.6.0', '>=')) {
Tlog::getInstance()->addInfo("Setting global and session sql_mode to NO_ENGINE_SUBSTITUTION");
$setQuery = '';
if ($data['global_sql_mode'] != 'NO_ENGINE_SUBSTITUTION') {
$setQuery .= "SET GLOBAL sql_mode='NO_ENGINE_SUBSTITUTION';";
}
if ($data['session_sql_mode'] != 'NO_ENGINE_SUBSTITUTION') {
$setQuery .= "SET SESSION sql_mode='NO_ENGINE_SUBSTITUTION';";
}
if (! empty($setQuery)) {
if (null === $con->query($setQuery)) {
throw new \RuntimeException('Failed to set MySQL 5.6+ global sql_mode to NO_ENGINE_SUBSTITUTION');
}
}
}
} else {
Tlog::getInstance()->addWarning("Failed to get MySQL version and sql_mode");
}
}
/**

0 comments on commit e61c5e6

Please sign in to comment.