From 2b2a8bcf44add5e25031ec11cedd97a6cc23916f Mon Sep 17 00:00:00 2001 From: Bernard Hamlin Date: Tue, 6 Oct 2020 10:38:57 +1300 Subject: [PATCH 1/5] Allow setting sql_mode via config --- src/ORM/Connect/MySQLDatabase.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ORM/Connect/MySQLDatabase.php b/src/ORM/Connect/MySQLDatabase.php index 942c7bd1697..811078bb5b4 100644 --- a/src/ORM/Connect/MySQLDatabase.php +++ b/src/ORM/Connect/MySQLDatabase.php @@ -49,6 +49,14 @@ class MySQLDatabase extends Database implements TransactionManager */ private static $charset = 'utf8'; + /** + * Default sql_mode + * + * @config + * @var string + */ + private static $sql_mode = 'ANSI'; + /** * Cache for getTransactionManager() * @@ -84,8 +92,8 @@ public function connect($parameters) // Notify connector of parameters $this->connector->connect($parameters); - // This is important! - $this->setSQLMode('ANSI'); + // Set sql_mode + $this->setSQLMode(static::config()->get('sql_mode')); if (isset($parameters['timezone'])) { $this->selectTimezone($parameters['timezone']); From 2e96fb23c7257bc48ee0e56882c545608210b095 Mon Sep 17 00:00:00 2001 From: Bernard Hamlin <948122+blueo@users.noreply.github.com> Date: Tue, 20 Oct 2020 15:13:03 +1300 Subject: [PATCH 2/5] Add sql_mode usage docs Co-authored-by: Garion Herman --- src/ORM/Connect/MySQLDatabase.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ORM/Connect/MySQLDatabase.php b/src/ORM/Connect/MySQLDatabase.php index 811078bb5b4..7f5d3547711 100644 --- a/src/ORM/Connect/MySQLDatabase.php +++ b/src/ORM/Connect/MySQLDatabase.php @@ -50,7 +50,8 @@ class MySQLDatabase extends Database implements TransactionManager private static $charset = 'utf8'; /** - * Default sql_mode + * SQL Mode used on connections to MySQL. Defaults to ANSI. For basic ORM + * compatibility, this setting must always include ANSI or ANSI_QUOTES. * * @config * @var string From f0459fc06354c62a7d30931c3da0c698c1b7ce39 Mon Sep 17 00:00:00 2001 From: Bernard Hamlin Date: Tue, 20 Oct 2020 16:07:46 +1300 Subject: [PATCH 3/5] Update server requirements doc --- .../00_Getting_Started/00_Server_Requirements.md | 16 ++++++++++------ docs/en/04_Changelogs/4.7.0.md | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/en/00_Getting_Started/00_Server_Requirements.md b/docs/en/00_Getting_Started/00_Server_Requirements.md index 51a7424ab24..39facaf15a8 100644 --- a/docs/en/00_Getting_Started/00_Server_Requirements.md +++ b/docs/en/00_Getting_Started/00_Server_Requirements.md @@ -1,7 +1,7 @@ --- title: Server Requirements icon: server -summary: What you will need to run Silverstripe CMS on a web server +summary: What you will need to run Silverstripe CMS on a web server --- @@ -27,7 +27,11 @@ Use [phpinfo()](http://php.net/manual/en/function.phpinfo.php) to inspect your c * PostgreSQL ([third party module](https://addons.silverstripe.org/add-ons/silverstripe/postgresql), community supported) * SQL Server ([third party module](https://addons.silverstripe.org/add-ons/silverstripe/mssql), community supported) * SQLite ([third party module](https://addons.silverstripe.org/add-ons/silverstripe/sqlite3), community supported) - + + ### Connection mode (sql_mode) when using MySQL server >=5.7.5 + + MySQL versions >=5.7.5 the `ANSI` sql_mode setting behaves differently and includes the `ONLY_FULL_GROUP_BY` setting. In most cases it is recommended to leave this setting as-is because it results in deterministic SQL. However for some advanced cases the sql_mode can be configured on the database connection via the configuration API. + ## Webserver Configuration ### Overview @@ -138,14 +142,14 @@ See [silverstripe/vendor-plugin](https://github.com/silverstripe/vendor-plugin) The default installation includes [silverstripe/errorpage](https://addons.silverstripe.org/add-ons/silverstripe/errorpage), which generates static error pages that bypass PHP execution when those pages are published in the CMS. Once published, the static files are located in `public/assets/error-404.html` and `public/assets/error-500.html`. -The default `public/.htaccess` file is configured to have Apache serve those pages based on their HTTP status code. +The default `public/.htaccess` file is configured to have Apache serve those pages based on their HTTP status code. ### Other webservers (Nginx, IIS, Lighttpd) Serving through webservers other than Apache requires more manual configuration, since the defaults configured through `.htaccess` don't apply. Please apply the considerations above to your webserver to ensure a secure hosting environment. -In particular, configure protected assets correctly to avoid exposing draft or protected files uploaded through the CMS. +In particular, configure protected assets correctly to avoid exposing draft or protected files uploaded through the CMS. There are various community supported installation instructions for different environments. Nginx is a popular choice, see [Nginx webserver configuration](https://forum.silverstripe.org/t/nginx-webserver-configuration/2246). @@ -182,9 +186,9 @@ SilverStripe's PHP support has changed over time and if you are looking to upgra SilverStripe CMS supports the following web browsers: * Google Chrome * Internet Explorer 11 -* Microsoft Edge +* Microsoft Edge * Mozilla Firefox - + We aim to provide satisfactory experiences in Apple Safari. SilverStripe CMS works well across Windows, Linux, and Mac operating systems. ## End user requirements diff --git a/docs/en/04_Changelogs/4.7.0.md b/docs/en/04_Changelogs/4.7.0.md index 050180cc786..f3daf994991 100644 --- a/docs/en/04_Changelogs/4.7.0.md +++ b/docs/en/04_Changelogs/4.7.0.md @@ -5,6 +5,7 @@ - [Experimental support for PHP 8](#experimental-support-for-php-8) - [Support for Symfony 4 Components](#support-for-symfony-4-components) - [Default MySQL collation updated](#default-mysql-collation-updated) +- [MySQL connection mode configurable](#mysql-connection-mode-now-configurable) - [Flysystem dependency shifted](#flysystem-dependency-shifted) ## New features @@ -59,6 +60,10 @@ You can rectify this by upgrading MySQL, enabling the `innodb_large_prefix` sett reducing the size of affected fields. If none of these solutions are currently suitable, you can remove the new collation configuration to default back to the previous default collation. +### MySQL connection mode now configurable + +MySQL versions >=5.7.5 the `ANSI` sql_mode setting behaves differently and includes the `ONLY_FULL_GROUP_BY` setting. In most cases it is recommended to leave this setting as-is because it results in deterministic SQL. However for some advanced cases the sql_mode can be configured on the database connection via the configuration API. + ### Flysystem dependency shifted Previously the Flysystem package was pulled in via the `silverstripe/framework` module, but only From e3ff7a0bd717b40c61519777bbe3f3290018113d Mon Sep 17 00:00:00 2001 From: Bernard Hamlin <948122+blueo@users.noreply.github.com> Date: Wed, 21 Oct 2020 12:05:07 +1300 Subject: [PATCH 4/5] Update docs/en/04_Changelogs/4.7.0.md Co-authored-by: Garion Herman --- docs/en/04_Changelogs/4.7.0.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/en/04_Changelogs/4.7.0.md b/docs/en/04_Changelogs/4.7.0.md index f3daf994991..c2a6b6df542 100644 --- a/docs/en/04_Changelogs/4.7.0.md +++ b/docs/en/04_Changelogs/4.7.0.md @@ -62,7 +62,7 @@ remove the new collation configuration to default back to the previous default c ### MySQL connection mode now configurable -MySQL versions >=5.7.5 the `ANSI` sql_mode setting behaves differently and includes the `ONLY_FULL_GROUP_BY` setting. In most cases it is recommended to leave this setting as-is because it results in deterministic SQL. However for some advanced cases the sql_mode can be configured on the database connection via the configuration API. +In MySQL versions >=5.7.5, the `ANSI` sql_mode setting behaves differently and includes the `ONLY_FULL_GROUP_BY` setting. It is generally recommended to leave this setting as-is because it results in deterministic SQL. However, for some advanced cases, the sql_mode can now be configured on the database connection via the configuration API (see `MySQLDatabase::$sql_mode` for more details.) ### Flysystem dependency shifted @@ -76,4 +76,3 @@ An edgecase exists where a project can update to `silverstripe/framework 4.7.0` `silverstripe/assets 1.6.x`, and lose the Flysystem dependency entirely. The best way to avoid this is by ensuring you update all core modules to the new minor release at once, ideally through a core recipe like `silverstripe/recipe-core`. - From dab8631015a70d1ed694787852d301cfa1afcb60 Mon Sep 17 00:00:00 2001 From: Bernard Hamlin <948122+blueo@users.noreply.github.com> Date: Wed, 21 Oct 2020 12:05:26 +1300 Subject: [PATCH 5/5] Update docs/en/00_Getting_Started/00_Server_Requirements.md Co-authored-by: Garion Herman --- docs/en/00_Getting_Started/00_Server_Requirements.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/00_Getting_Started/00_Server_Requirements.md b/docs/en/00_Getting_Started/00_Server_Requirements.md index 39facaf15a8..c873a7e4f5f 100644 --- a/docs/en/00_Getting_Started/00_Server_Requirements.md +++ b/docs/en/00_Getting_Started/00_Server_Requirements.md @@ -30,7 +30,7 @@ Use [phpinfo()](http://php.net/manual/en/function.phpinfo.php) to inspect your c ### Connection mode (sql_mode) when using MySQL server >=5.7.5 - MySQL versions >=5.7.5 the `ANSI` sql_mode setting behaves differently and includes the `ONLY_FULL_GROUP_BY` setting. In most cases it is recommended to leave this setting as-is because it results in deterministic SQL. However for some advanced cases the sql_mode can be configured on the database connection via the configuration API. +In MySQL versions >=5.7.5, the `ANSI` sql_mode setting behaves differently and includes the `ONLY_FULL_GROUP_BY` setting. It is generally recommended to leave this setting as-is because it results in deterministic SQL. However, for some advanced cases, the sql_mode can be configured on the database connection via the configuration API (see `MySQLDatabase::$sql_mode` for more details.) This setting is only available in Silverstripe CMS 4.7 and later. ## Webserver Configuration