Lines 121-126
Returns:
Link Here
|
121 |
sub store { |
121 |
sub store { |
122 |
my ($self) = @_; |
122 |
my ($self) = @_; |
123 |
|
123 |
|
|
|
124 |
my $columns_info = Koha::Database->new->schema->resultset( $self->_type ) |
125 |
->result_source->{_columns}; |
126 |
|
127 |
# Handle not null and default values for integers and dates |
128 |
foreach my $col ( keys %{$columns_info} ) { |
129 |
# Integers |
130 |
if ( _numeric_column_type( $columns_info->{$col}->{data_type} ) ) { |
131 |
# Has been passed but not a number, usually an empty string |
132 |
if ( defined $self->$col and not looks_like_number( $self->$col ) ) { |
133 |
if ( $columns_info->{$col}->{is_nullable} ) { |
134 |
# If nullable, default to null |
135 |
$self->$col(undef); |
136 |
} else { |
137 |
# If cannot be null, get the default value |
138 |
# What if cannot be null and does not have a default value? Possible? |
139 |
$self->$col($columns_info->{$col}->{default_value}); |
140 |
} |
141 |
} |
142 |
} |
143 |
elsif ( _date_or_datetime_column_type( $columns_info->{$col}->{data_type} ) ) { |
144 |
# Set to null if an empty string (or == 0 but should not happen) |
145 |
$self->$col(undef) unless $self->$col; |
146 |
} |
147 |
} |
148 |
|
124 |
try { |
149 |
try { |
125 |
return $self->_result()->update_or_insert() ? $self : undef; |
150 |
return $self->_result()->update_or_insert() ? $self : undef; |
126 |
} |
151 |
} |
Lines 282-287
sub TO_JSON {
Link Here
|
282 |
return $unblessed; |
307 |
return $unblessed; |
283 |
} |
308 |
} |
284 |
|
309 |
|
|
|
310 |
sub _date_or_datetime_column_type { |
311 |
my ($column_type) = @_; |
312 |
|
313 |
my @dt_types = ( |
314 |
'timestamp', |
315 |
'date', |
316 |
'datetime' |
317 |
); |
318 |
|
319 |
return ( grep { $column_type eq $_ } @dt_types) ? 1 : 0; |
320 |
} |
285 |
sub _datetime_column_type { |
321 |
sub _datetime_column_type { |
286 |
my ($column_type) = @_; |
322 |
my ($column_type) = @_; |
287 |
|
323 |
|
288 |
- |
|
|