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
$schema->resultset( $class->_type() )->new($attributes);
}
+ $self->{_messages} = [];
+
croak("No _type found! Koha::Object must be subclassed!")
unless $class->_type();
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
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 {
+ <some action that might fail>
+ }
+ catch {
+ if ( <fatal condition> ) {
+ 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.
) {
# 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} )
) {
# 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} ) ) {
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 = (
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 = (