Permalink
Browse files

cherry-pick Checking MySQL version to set sql_mode automatically thel…

  • Loading branch information...
roadster31 authored and gillesbourgeat committed Feb 25, 2016
1 parent b1329d4 commit f4d253af24c587de21c6f10049074c4ab20f3e11
Showing with 28 additions and 0 deletions.
  1. +1 −0 CHANGELOG.md
  2. +27 −0 core/lib/Thelia/Core/Thelia.php
View
@@ -1,5 +1,6 @@
# 2.2.3
- (related to #2012) Checking MySQL version to set sql_mode automatically, this fixed the compatibility with MySQL > 5.6 for modes `STRICT_TRANS_TABLES`, `NO_ENGINE_SUBSTITUTION`
- (related to #2010) Improve product price edition tab
- (related to #2005) Use a wider version requirement on thelia/installer for setup/
- (related to #1999) Fix Folder breadcrumb, the parent url was not good if you edit a picture in a folder or a content
@@ -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 f4d253a

Please sign in to comment.