View | Details | Raw Unified | Return to bug 21610
Collapse All | Expand All

(-)a/Koha/Object.pm (-1 / +36 lines)
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 275-280 sub TO_JSON { Link Here
275
    return $unblessed;
300
    return $unblessed;
276
}
301
}
277
302
303
sub _date_or_datetime_column_type {
304
    my ($column_type) = @_;
305
306
    my @dt_types = (
307
        'timestamp',
308
        'date',
309
        'datetime'
310
    );
311
312
    return ( grep { $column_type eq $_ } @dt_types) ? 1 : 0;
313
}
278
sub _datetime_column_type {
314
sub _datetime_column_type {
279
    my ($column_type) = @_;
315
    my ($column_type) = @_;
280
316
281
- 

Return to bug 21610