Skip to content

Commit

Permalink
FIX Only select columns from the current database
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 6, 2024
1 parent 392d019 commit eaece0a
Showing 1 changed file with 4 additions and 1 deletion.
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

0 comments on commit eaece0a

Please sign in to comment.