Handle update when fields doesnt exist

This commit is contained in:
Félix Suárez 2024-04-04 15:27:47 -06:00
parent 42737a38a1
commit 96a6c4fd22
1 changed files with 9 additions and 1 deletions

View File

@ -4067,8 +4067,16 @@ sub pandora_check_type_custom_field_for_itsm ($) {
##########################################################################
sub pandora_update_agent_custom_field ($$$$) {
my ($dbh, $token, $field, $id_agent) = @_;
my $exist_field = get_db_value($dbh, 'SELECT count(*) FROM tagent_custom_data WHERE id_field = ? AND id_agent = ?', $field, $id_agent);
my $result = undef;
$result = db_update ($dbh, 'UPDATE tagent_custom_data SET description = ? WHERE id_field = ? AND id_agent = ?', safe_input($token), $field, $id_agent);
$token = safe_input($token);
if (!$exist_field) {
$result = defined(db_insert ($dbh, 'id_field', 'INSERT INTO tagent_custom_data (`description`, `id_field`, `id_agent`) VALUES (?, ?, ?)', $token, $field, $id_agent)) ? 1 : 0;
} else {
$result = db_update ($dbh, 'UPDATE tagent_custom_data SET description = ? WHERE id_field = ? AND id_agent = ?', $token, $field, $id_agent);
}
return $result;
}