Fixed a bug where duplicate variables were being created in some cases.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 1 year ago
parent a11b87458e
commit ed269aa450
  1. 73
      Anvil/Tools/Database.pm
  2. 1
      share/words.xml

@ -18150,6 +18150,79 @@ sub resync_databases
# We're done with the table data, clear it. # We're done with the table data, clear it.
delete $anvil->data->{sys}{database}{table}; delete $anvil->data->{sys}{database}{table};
# Look for duplicate entries in variables. This is done here as it's too generic to tag elsewhere
if (1)
{
my $query = "
SELECT
variable_uuid,
variable_section,
variable_name,
variable_source_table,
variable_source_uuid,
variable_value,
modified_date
FROM
variables
ORDER BY
modified_date DESC;
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $variable_uuid = $row->[0];
my $variable_section = $row->[1];
my $variable_name = $row->[2];
my $variable_source_table = $row->[3];
my $variable_source_uuid = $row->[4] // "none";
my $variable_value = $row->[5];
my $modified_date = $row->[6];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
variable_uuid => $variable_uuid,
variable_section => $variable_section,
variable_name => $variable_name,
variable_source_table => $variable_source_table,
variable_source_uuid => $variable_source_uuid,
variable_value => $variable_value,
modified_date => $modified_date,
}});
if (not exists $anvil->data->{duplicate_variables}{$variable_section}{$variable_name}{$variable_source_table}{$variable_source_uuid})
{
# Save it.
$anvil->data->{duplicate_variables}{$variable_section}{$variable_name}{$variable_source_table}{$variable_source_uuid}{variable_value} = $variable_value;
$anvil->data->{duplicate_variables}{$variable_section}{$variable_name}{$variable_source_table}{$variable_source_uuid}{variable_uuid} = $variable_uuid;
}
else
{
# Duplicate! This is older, so delete it.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "warning_0165", variables => {
section => $variable_section,
name => $variable_name,
source_table => $variable_source_table,
source_uuid => $variable_source_uuid,
value => $variable_value,
}});
my $queries = [];
push @{$queries}, "DELETE FROM history.variables WHERE variable_uuid = ".$anvil->Database->quote($variable_uuid).";";
push @{$queries}, "DELETE FROM variables WHERE variable_uuid = ".$anvil->Database->quote($variable_uuid).";";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
}
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
}
}
}
# Clear the variable that indicates we need a resync. # Clear the variable that indicates we need a resync.
$anvil->data->{sys}{database}{resync_needed} = 0; $anvil->data->{sys}{database}{resync_needed} = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 'sys::database::resync_needed' => $anvil->data->{sys}{database}{resync_needed} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 'sys::database::resync_needed' => $anvil->data->{sys}{database}{resync_needed} }});

@ -3953,6 +3953,7 @@ We will try to proceed anyway.</key>
</key> </key>
<key name="warning_0163"><![CDATA[Failed to read the definition file: [#!variable!file!#] for the server: [#!variable!server_name!#] on the host: [#!variable!host_name!#]. If the host is online, it should update the next time scan-server runs.]]></key> <key name="warning_0163"><![CDATA[Failed to read the definition file: [#!variable!file!#] for the server: [#!variable!server_name!#] on the host: [#!variable!host_name!#]. If the host is online, it should update the next time scan-server runs.]]></key>
<key name="warning_0164"><![CDATA[Failed to update the definition file: [#!variable!file!#] for the server: [#!variable!server_name!#] on the host: [#!variable!host_name!#]. If the host is online, it should update the next time scan-server runs.]]></key> <key name="warning_0164"><![CDATA[Failed to update the definition file: [#!variable!file!#] for the server: [#!variable!server_name!#] on the host: [#!variable!host_name!#]. If the host is online, it should update the next time scan-server runs.]]></key>
<key name="warning_0165"><![CDATA[A duplicate variable was found! Section: [#!variable!section!#], name: [#!variable!name!#], source table: [#!variable!source_table!#], source_uuid: [#!variable!source_uuid!#], value: [#!variable!value!#]. This is older, so it will be deleted.]]></key>
</language> </language>
<!-- 日本語 --> <!-- 日本語 -->

Loading…
Cancel
Save