Skip to content

Commit

Permalink
data_dictionary_builder.php unique constraint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
laemtl committed Apr 11, 2024
1 parent d3e7bf2 commit 812ec37
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tools/exporters/data_dictionary_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@
$instrumentParameterTypeCategoryIDs = [];
$instrumentParameterTypeIDs = [];


$parameter_types = $DB->pselectColWithIndexKey(
"Select Name, ParameterTypeID from parameter_type",
"SELECT
CONCAT(`Name`, '-', `SourceFrom`) AS paramkey,
ParameterTypeID
FROM parameter_type",
[],
"Name"
"paramkey"
);

// 2 query to clear all old parameter_type data associated to instruments.
Expand Down Expand Up @@ -205,11 +207,12 @@
"Queryable" => "1",
];

$key = "$Name-$testname";
// Check if the same element existed in the parameter_type table
// before deleting the data.
if (array_key_exists($Name, $parameter_types)) {
if (array_key_exists($key, $parameter_types)) {
//If element existed, reuse the same id
$ParameterTypeID = $parameter_types[$Name];
$ParameterTypeID = $parameter_types[$key];
$query_params["ParameterTypeID"] = $ParameterTypeID;
} else {
//If it's new set it to empty string
Expand Down Expand Up @@ -265,8 +268,9 @@
"Queryable" => "1",
];

if (array_key_exists($Name, $parameter_types)) {
$ParameterTypeID = $parameter_types[$Name];
$key = "$Name-$testname";
if (array_key_exists($key, $parameter_types)) {
$ParameterTypeID = $parameter_types[$key];
$query_params["ParameterTypeID"] = $ParameterTypeID;
} else {
$ParameterTypeID = "";
Expand Down Expand Up @@ -309,8 +313,9 @@
"Queryable" => "1",
];

if (array_key_exists($Name, $parameter_types)) {
$ParameterTypeID = $parameter_types[$Name];
$key = "$Name-$testname";
if (array_key_exists($key, $parameter_types)) {
$ParameterTypeID = $parameter_types[$key];
$query_params["ParameterTypeID"] = $ParameterTypeID;
} else {
$ParameterTypeID = "";
Expand Down

0 comments on commit 812ec37

Please sign in to comment.