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 Issues when running with other modules installed #860

Merged
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
10 changes: 10 additions & 0 deletions src/Extension/FluentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1055,6 +1056,15 @@ public function LocaleInformation($locale = null)
$localeObj = Locale::getDefault();
}

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);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Extension/FluentVersionedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading