Bug 24788: Remove autoloaded column accessors in Koha::Object->store

Columns are accessed as methods, relying on AUTOLOAD, in
Koha::Object->store. This could be a source of strange bugs
if a column name clashes with an existing method name.

To test:

1) Apply patches for Bug 14957
2) Follow the testing instructions, when saving a new marc rule and
error is thrown.
3) Apply patch
4) Try saving a new rule once again, this should now work

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
This commit is contained in:
David Gustafsson 2020-03-03 14:32:31 +01:00 committed by Joy Nelson
parent 61e7f3bbd7
commit 508a6ad027
1 changed files with 8 additions and 6 deletions

View File

@ -129,24 +129,26 @@ sub store {
# Integers
if ( _numeric_column_type( $columns_info->{$col}->{data_type} ) ) {
# Has been passed but not a number, usually an empty string
if ( defined $self->$col and not looks_like_number( $self->$col ) ) {
my $value = $self->_result()->get_column($col);
if ( defined $value and not looks_like_number( $value ) ) {
if ( $columns_info->{$col}->{is_nullable} ) {
# If nullable, default to null
$self->$col(undef);
$self->_result()->set_column($col => undef);
} else {
# If cannot be null, get the default value
# What if cannot be null and does not have a default value? Possible?
$self->$col($columns_info->{$col}->{default_value});
$self->_result()->set_column($col => $columns_info->{$col}->{default_value});
}
}
}
elsif ( _date_or_datetime_column_type( $columns_info->{$col}->{data_type} ) ) {
# Set to null if an empty string (or == 0 but should not happen)
if ( defined $self->$col and not $self->$col ) {
my $value = $self->_result()->get_column($col);
if ( defined $value and not $value ) {
if ( $columns_info->{$col}->{is_nullable} ) {
$self->$col(undef);
$self->_result()->set_column($col => undef);
} else {
$self->$col($columns_info->{$col}->{default_value});
$self->_result()->set_column($col => $columns_info->{$col}->{default_value});
}
}
}