X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=Koha%2FObject.pm;h=08602da67f9a27418b325fc8ae8e2deff1b41a94;hb=96adb7373ab3b39a42dc3a8304f050ee81c991c4;hp=c6ae91e4efd2cdbdf32900d9c63df95a36ffe07f;hpb=f4f3c8f18b5587ad8629b77b457e9593d781dac6;p=koha-ffzg.git diff --git a/Koha/Object.pm b/Koha/Object.pm index c6ae91e4ef..08602da67f 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -20,14 +20,15 @@ package Koha::Object; use Modern::Perl; -use Carp; +use Carp qw( croak ); use Mojo::JSON; use Scalar::Util qw( blessed looks_like_number ); -use Try::Tiny; +use Try::Tiny qw( catch try ); use Koha::Database; use Koha::Exceptions::Object; -use Koha::DateUtils; +use Koha::DateUtils qw( dt_from_string output_pref ); +use Koha::Object::Message; =head1 NAME @@ -77,6 +78,8 @@ sub new { $schema->resultset( $class->_type() )->new($attributes); } + $self->{_messages} = []; + croak("No _type found! Koha::Object must be subclassed!") unless $class->_type(); @@ -219,9 +222,8 @@ sub update { Removes the object from storage. Returns: - 1 if the deletion was a success - 0 if the deletion failed - -1 if the object was never in storage + The item object if deletion was a success + The DBIX::Class error if deletion failed =cut @@ -332,6 +334,50 @@ sub get_from_storage { return $object_class->_new_from_dbic($stored_object); } +=head3 $object->messages + + my @messages = @{ $object->messages }; + +Returns the (probably non-fatal) messages that were recorded on the object. + +=cut + +sub messages { + my ( $self ) = @_; + + $self->{_messages} = [] + unless defined $self->{_messages}; + + return $self->{_messages}; +} + +=head3 $object->add_message + + try { + + } + catch { + if ( ) { + Koha::Exception->throw... + } + + # This is a non fatal error, notify the caller + $self->add_message({ message => $error, type => 'error' }); + } + return $self; + +Adds a message. + +=cut + +sub add_message { + my ( $self, $params ) = @_; + + push @{ $self->{_messages} }, Koha::Object::Message->new($params); + + return $self; +} + =head3 $object->TO_JSON Returns an unblessed representation of the object, suitable for JSON output. @@ -360,8 +406,9 @@ sub TO_JSON { ) { # TODO: Remove once the solution for - # https://rt.cpan.org/Ticket/Display.html?id=119904 + # https://github.com/perl5-dbi/DBD-mysql/issues/212 # is ported to whatever distro we support by that time + # or we move to DBD::MariaDB $unblessed->{$col} += 0; } elsif ( _decimal_column_type( $columns_info->{$col}->{data_type} ) @@ -369,8 +416,9 @@ sub TO_JSON { ) { # TODO: Remove once the solution for - # https://rt.cpan.org/Ticket/Display.html?id=119904 + # https://github.com/perl5-dbi/DBD-mysql/issues/212 # is ported to whatever distro we support by that time + # or we move to DBD::MariaDB $unblessed->{$col} += 0.00; } elsif ( _datetime_column_type( $columns_info->{$col}->{data_type} ) ) { @@ -410,8 +458,9 @@ sub _datetime_column_type { sub _numeric_column_type { # TODO: Remove once the solution for - # https://rt.cpan.org/Ticket/Display.html?id=119904 + # https://github.com/perl5-dbi/DBD-mysql/issues/212 # is ported to whatever distro we support by that time + # or we move to DBD::MariaDB my ($column_type) = @_; my @numeric_types = ( @@ -428,8 +477,9 @@ sub _numeric_column_type { sub _decimal_column_type { # TODO: Remove once the solution for - # https://rt.cpan.org/Ticket/Display.html?id=119904 + # https://github.com/perl5-dbi/DBD-mysql/issues/212 # is ported to whatever distro we support by that time + # or we move to DBD::MariaDB my ($column_type) = @_; my @decimal_types = (