#901 node_ip time_last can be before time_first

This commit is contained in:
Oliver Gorwits
2023-03-03 15:34:16 +00:00
parent 1d00ebc91e
commit 4bb9b25ae9
3 changed files with 35 additions and 18 deletions

View File

@@ -158,20 +158,27 @@ sub store_nbt {
my ( $hash_ref, $now ) = @_;
$now ||= 'LOCALTIMESTAMP';
schema(vars->{'tenant'})->resultset('NodeNbt')->update_or_create(
{ mac => $hash_ref->{'mac'},
ip => $hash_ref->{'ip'},
nbname => $hash_ref->{'nbname'},
domain => $hash_ref->{'domain'},
server => $hash_ref->{'server'},
nbuser => $hash_ref->{'nbuser'},
active => \'true',
time_last => \$now,
},
{ key => 'primary',
for => 'update',
}
);
schema(vars->{'tenant'})->txn_do(sub {
my $row = schema(vars->{'tenant'})->resultset('NodeNbt')->update_or_new(
{ mac => $hash_ref->{'mac'},
ip => $hash_ref->{'ip'},
nbname => $hash_ref->{'nbname'},
domain => $hash_ref->{'domain'},
server => $hash_ref->{'server'},
nbuser => $hash_ref->{'nbuser'},
active => \'true',
time_last => \$now,
},
{ key => 'primary',
for => 'update',
}
);
if (! $row->in_storage) {
$row->set_column(time_first => \$now);
$row->insert;
}
});
return;
}