Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #12557 #12560

Merged
merged 5 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Fixed a bug where accessing a custom field’s magic property on an element would return the field’s raw database value rather than `null`, if it didn’t belong to the element’s field layout anymore. ([#12539](https://github.com/craftcms/cms/issues/12539), [#12578](https://github.com/craftcms/cms/pull/12578))
- Fixed a bug where `craft\image\Raster::getIsTransparent()` wasn’t working. ([#12565](https://github.com/craftcms/cms/issues/12565))
- Fixed a bug where the component name comments in project config YAML files would always lag behind the current project config a little. ([#12576](https://github.com/craftcms/cms/issues/12576), ([#12581](https://github.com/craftcms/cms/pull/12581)))
- Fixed a MySQL error that occurred when creating a database backup using the default backup command, when running MySQL 5.7.41+ or 8.0.32+. ([#12557](https://github.com/craftcms/cms/issues/12557), [#12560](https://github.com/craftcms/cms/pull/12560))
- Added `craft\helpers\Db::escapeForLike()`.
- `craft\services\Assets::getAllDescendantFolders()` now has a `$withParent` argument, which can be passed `false` to omit the parent folder from the results. ([#12536](https://github.com/craftcms/cms/issues/12536))
- Deprecated `craft\helpers\DateTimeHelper::timeZoneAbbreviation()`.
Expand Down
19 changes: 17 additions & 2 deletions src/db/mysql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ public function createColumnSchemaBuilder($type, $length = null)
*/
public function getDefaultBackupCommand(array $ignoreTables = null): string
{
$useSingleTransaction = true;
$serverVersion = App::normalizeVersion(Craft::$app->getDb()->getSchema()->getServerVersion());

$isMySQL5 = version_compare($serverVersion, '8', '<');
$isMySQL8 = version_compare($serverVersion, '8', '>=');

// https://bugs.mysql.com/bug.php?id=109685
if (($isMySQL5 && version_compare($serverVersion, '5.7.41', '>=')) ||
($isMySQL8 && version_compare($serverVersion, '8.0.32', '>='))) {
$useSingleTransaction = false;
}

$defaultArgs =
' --defaults-extra-file="' . $this->_createDumpConfigFile() . '"' .
' --add-drop-table' .
Expand All @@ -163,8 +175,12 @@ public function getDefaultBackupCommand(array $ignoreTables = null): string
' --triggers' .
' --no-tablespaces';

if ($useSingleTransaction) {
$defaultArgs .= ' --single-transaction';
}

// If the server is MySQL 5.x, we need to see what version of mysqldump is installed (5.x or 8.x)
if (version_compare(App::normalizeVersion(Craft::$app->getDb()->getSchema()->getServerVersion()), "8", "<")) {
if ($isMySQL5) {
// Find out if the db supports column-statistics
$shellCommand = new ShellCommand();

Expand Down Expand Up @@ -198,7 +214,6 @@ public function getDefaultBackupCommand(array $ignoreTables = null): string

$schemaDump = 'mysqldump' .
$defaultArgs .
' --single-transaction' .
' --no-data' .
' --result-file="{file}"' .
' {database}';
Expand Down