X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FCVar.pm;h=a905edee7b7d70fd203dfc8aaec66ec734f4bf2f;hb=393cef65daf67853ed468b4778b7c738773d48f1;hp=37d865ae9b4faacb757401841604bc3b454a021b;hpb=9df5680a46013d7c013f5f572111d3646c9c76bf;p=kivitendo-erp.git diff --git a/SL/CVar.pm b/SL/CVar.pm index 37d865ae9..a905edee7 100644 --- a/SL/CVar.pm +++ b/SL/CVar.pm @@ -244,6 +244,29 @@ sub _save_custom_variables { my $sth = prepare_query($form, $dbh, $query); foreach my $config (@configs) { + if ($params{save_validity}) { + my $valid_index = "$params{name_prefix}cvar_$config->{name}$params{name_postfix}_valid"; + my $new_valid = $params{variables}{$valid_index} || $params{always_valid} ? 1 : 0; + my $old_valid = $self->get_custom_variables_validity(trans_id => $params{trans_id}, config_id => $config->{id}); + + $self->save_custom_variables_validity(trans_id => $params{trans_id}, + config_id => $config->{id}, + validity => $new_valid, + ); + + if (!$new_valid || !$old_valid) { + # When activating a cvar (old_valid == 0 && new_valid == 1) + # the input to hold the variable's value wasn't actually + # rendered, meaning saving the value now would only save an + # empty value/the value 0. This means that the next time the + # form is rendered, an existing value is found and used + # instead of the variable's default value from the + # configuration. Therefore don't save the values in such + # cases. + next; + } + } + my @values = (conv_i($config->{id}), "$params{sub_module}", conv_i($params{trans_id})); my $value = $params{variables}->{"$params{name_prefix}cvar_$config->{name}$params{name_postfix}"}; @@ -264,14 +287,6 @@ sub _save_custom_variables { } do_statement($form, $sth, $query, @values); - - if ($params{save_validity}) { - my $valid_index = "$params{name_prefix}cvar_$config->{name}$params{name_postfix}_valid"; - $self->save_custom_variables_validity(trans_id => $params{trans_id}, - config_id => $config->{id}, - validity => ($params{variables}{$valid_index} || $params{always_valid} ? 1 : 0) - ); - } } $sth->finish();