From eaece0a7e1c8e3a4492d3d290c84993b52c82b4c Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 6 Jun 2024 18:08:34 +1200 Subject: [PATCH 1/3] FIX Only select columns from the current database --- src/Extension/FluentVersionedExtension.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Extension/FluentVersionedExtension.php b/src/Extension/FluentVersionedExtension.php index 65ca59fa..a8306aba 100644 --- a/src/Extension/FluentVersionedExtension.php +++ b/src/Extension/FluentVersionedExtension.php @@ -1044,8 +1044,11 @@ public function onAfterDuplicate($original, $doWrite, $relations): void // Remove existing versions from duplicated object, created by onBeforeWrite DB::prepared_query("DELETE FROM \"$versionsTableName\" WHERE \"RecordID\" = ?", [$toID]); + // Dynamicaly select the current database, which will be a temporary database in case of unit tests + $currentDB = DB::query('SELECT DATABASE() as DB')->column('DB')[0]; + // Copy all versions of base record, todo: optimize to only copy needed versions - $fields = DB::query("SELECT \"COLUMN_NAME\" FROM \"INFORMATION_SCHEMA\".\"COLUMNS\" WHERE \"TABLE_NAME\" = '$versionsTableName' AND \"COLUMN_NAME\" NOT IN('ID','RecordID')"); + $fields = DB::query("SELECT \"COLUMN_NAME\" FROM \"INFORMATION_SCHEMA\".\"COLUMNS\" WHERE \"TABLE_SCHEMA\" = '$currentDB' AND \"TABLE_NAME\" = '$versionsTableName' AND \"COLUMN_NAME\" NOT IN('ID','RecordID')"); $fields_str = '"' . implode('","', $fields->column()) . '"'; DB::prepared_query("INSERT INTO \"$versionsTableName\" ( \"RecordID\", $fields_str) SELECT ? AS \"RecordID\", $fields_str From 2714bff77c5baebcabf63e5aa281be57f9b05dbf Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 6 Jun 2024 18:15:46 +1200 Subject: [PATCH 2/3] FIX Create a temp locale if there is not a default --- src/Extension/FluentExtension.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Extension/FluentExtension.php b/src/Extension/FluentExtension.php index 06ab9507..b829c0ef 100644 --- a/src/Extension/FluentExtension.php +++ b/src/Extension/FluentExtension.php @@ -1055,6 +1055,14 @@ public function LocaleInformation($locale = null) $localeObj = Locale::getDefault(); } + if (!$locale && !$localeObj) { + // There is no default locale, this can happen when if fluent is installed though locales have been setup + // This will happen when doing integration unit testing, though can also happen during + // regular website operation + // This temporary Locale is created to prevent a invalid argument exception in RecordLocale::__construct() + $localeObj = Locale::create(['Title' => 'Temp locale']); + } + return RecordLocale::create($this->owner, $localeObj); } From b14687a9d09eb8ad8ef54c722e87895e4d256939 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 7 Jun 2024 09:54:50 +1200 Subject: [PATCH 3/3] . --- src/Extension/FluentExtension.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Extension/FluentExtension.php b/src/Extension/FluentExtension.php index b829c0ef..6980ee57 100644 --- a/src/Extension/FluentExtension.php +++ b/src/Extension/FluentExtension.php @@ -3,6 +3,7 @@ namespace TractorCow\Fluent\Extension; use LogicException; +use SilverStripe\i18n\i18n; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Convert; @@ -1055,12 +1056,13 @@ public function LocaleInformation($locale = null) $localeObj = Locale::getDefault(); } - if (!$locale && !$localeObj) { - // There is no default locale, this can happen when if fluent is installed though locales have been setup - // This will happen when doing integration unit testing, though can also happen during - // regular website operation - // This temporary Locale is created to prevent a invalid argument exception in RecordLocale::__construct() - $localeObj = Locale::create(['Title' => 'Temp locale']); + if (!$localeObj) { + // There is no default locale, this can happen if no locales have been setup + // This will happen when doing integration unit testing, though can also happen during regular + // website operation + // This temporary Locale is created to prevent a invalid argument exception in + // RecordLocale::__construct() + $localeObj = Locale::create(['Locale' => i18n::get_locale()]); } return RecordLocale::create($this->owner, $localeObj);