Bug 29785: Rename Koha::Object->message with ->object_messages

It will conflict with other ->messages methods, it's too generic.

Bug 29230 needs Koha::Patron->messages to return Koha::Patron::Messages for instance.

Test plan:
Confirm that the tests modified by this patch still pass

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit 30b9270bd9)

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2022-01-04 14:28:26 +01:00 committed by Andrew Fuerste-Henry
parent 6ccbdce5c0
commit a9c4b0bda3
8 changed files with 19 additions and 20 deletions

View File

@ -148,7 +148,7 @@ sub pay {
}
my $renew_outcomes = [];
for my $message ( @{$payment->messages} ) {
for my $message ( @{$payment->object_messages} ) {
push @{$renew_outcomes}, $message->payload;
}

View File

@ -334,15 +334,15 @@ sub get_from_storage {
return $object_class->_new_from_dbic($stored_object);
}
=head3 $object->messages
=head3 $object->object_messages
my @messages = @{ $object->messages };
my @messages = @{ $object->object_messages };
Returns the (probably non-fatal) messages that were recorded on the object.
=cut
sub messages {
sub object_messages {
my ( $self ) = @_;
$self->{_messages} = []

View File

@ -139,7 +139,7 @@ if ( $op eq 'delete_confirm' ) {
while ( my $order = $orders->next ) {
# cancel the order
$order->cancel({ delete_biblio => $delbiblio });
my @messages = @{ $order->messages };
my @messages = @{ $order->object_messages };
if ( scalar @messages > 0 ) {

View File

@ -58,7 +58,7 @@ if( $action and $action eq "confirmcancel" ) {
my $reason = $input->param('reason');
my $order = Koha::Acquisition::Orders->find($ordernumber);
$order->cancel({ reason => $reason, delete_biblio => $delete_biblio });
my @messages = @{ $order->messages };
my @messages = @{ $order->object_messages };
if ( scalar @messages > 0 ) {
$template->param( error_delitem => 1 )

View File

@ -239,7 +239,6 @@ foreach my $subscription (@subscriptions) {
push @subs, \%cell;
}
# Get acquisition details
if ( C4::Context->preference('AcquisitionDetails') ) {
my $orders = Koha::Acquisition::Orders->search(

View File

@ -355,7 +355,7 @@ subtest 'apply() tests' => sub {
$credit_renew = $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } );
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
my @messages = @{$credit_renew->messages};
my @messages = @{$credit_renew->object_messages};
is( $messages[0]->type, 'info', 'Info message added for renewal' );
is( $messages[0]->message, 'renewal', 'Message is "renewal"' );
is( $messages[0]->payload->{itemnumber}, $item->id, 'itemnumber found in payload' );

View File

@ -638,7 +638,7 @@ subtest 'cancel() tests' => sub {
is( $order->cancellationreason, $reason, 'cancellationreason is set' );
is( ref(Koha::Items->find($item->id)), 'Koha::Item', 'The item is present' );
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is present' );
my @messages = @{ $order->messages };
my @messages = @{ $order->object_messages };
is( $messages[0]->message, 'error_delitem', 'An error message is attached to the order' );
# Scenario:
@ -660,7 +660,7 @@ subtest 'cancel() tests' => sub {
is( $order->cancellationreason, $reason, 'cancellationreason is undef' );
is( Koha::Items->find($item->id), undef, 'The item is no longer present' );
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is present' );
@messages = @{ $order->messages };
@messages = @{ $order->object_messages };
is( scalar @messages, 0, 'No messages' );
# Scenario:
@ -696,7 +696,7 @@ subtest 'cancel() tests' => sub {
is( Koha::Items->find($item_1->id), undef, 'The item is no longer present' );
is( ref(Koha::Items->find($item_2->id)), 'Koha::Item', 'The item is still present' );
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
@messages = @{ $order->messages };
@messages = @{ $order->object_messages };
is( $messages[0]->message, 'error_delbiblio_items', 'Cannot delete biblio and it gets notified' );
# Scenario:
@ -743,7 +743,7 @@ subtest 'cancel() tests' => sub {
is( $order->cancellationreason, $reason, 'cancellationreason is undef' );
is( Koha::Items->find($item->id), undef, 'The item is no longer present' );
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
@messages = @{ $order->messages };
@messages = @{ $order->object_messages };
is( $messages[0]->message, 'error_delbiblio_active_orders', 'Cannot delete biblio and it gets notified' );
# Scenario:
@ -787,7 +787,7 @@ subtest 'cancel() tests' => sub {
is( $order->cancellationreason, $reason, 'cancellationreason is undef' );
is( Koha::Items->find($item->id), undef, 'The item is no longer present' );
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
@messages = @{ $order->messages };
@messages = @{ $order->object_messages };
is( $messages[0]->message, 'error_delbiblio_subscriptions', 'Cannot delete biblio and it gets notified' );
# Scenario:
@ -820,7 +820,7 @@ subtest 'cancel() tests' => sub {
is( $order->cancellationreason, $reason, 'cancellationreason is set' );
is( Koha::Items->find($item->id), undef, 'The item is not present' );
is( Koha::Biblios->find($biblio_id), undef, 'The biblio is not present' );
@messages = @{ $order->messages };
@messages = @{ $order->object_messages };
is( scalar @messages, 0, 'No errors' );
# Scenario:
@ -873,7 +873,7 @@ subtest 'cancel() tests' => sub {
is( Koha::Items->find($item_1->id), undef, 'The item is no longer present' );
is( ref(Koha::Items->find($item_2->id)), 'Koha::Item', 'The on loan item is still present' );
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' );
@messages = @{ $order->messages };
@messages = @{ $order->object_messages };
is( $messages[0]->message, 'error_delitem', 'Cannot delete on loan item' );
is( $messages[0]->payload->{item}->id, $item_2->id, 'Cannot delete on loan item' );
is( $messages[0]->payload->{reason}, 'book_on_loan', 'Item on loan notified' );

View File

@ -927,13 +927,13 @@ subtest 'messages() and add_message() tests' => sub {
my $patron = Koha::Patron->new;
my @messages = @{ $patron->messages };
my @messages = @{ $patron->object_messages };
is( scalar @messages, 0, 'No messages' );
$patron->add_message({ message => "message_1" });
$patron->add_message({ message => "message_2" });
@messages = @{ $patron->messages };
@messages = @{ $patron->object_messages };
is( scalar @messages, 2, 'Messages are returned' );
is( ref($messages[0]), 'Koha::Object::Message', 'Right type returned' );
@ -941,11 +941,11 @@ subtest 'messages() and add_message() tests' => sub {
is( $messages[0]->message, 'message_1', 'Right message recorded' );
my $patron_id = $builder->build_object({ class => 'Koha::Patrons' })->id;
# get a patron from the DB, ->new is not called, ->messages should initialize _messages as an empty arrayref
# get a patron from the DB, ->new is not called, ->object_messages should initialize _messages as an empty arrayref
$patron = Koha::Patrons->find( $patron_id );
isnt( $patron->messages, undef, '->messages initializes the array if required' );
is( scalar @{ $patron->messages }, 0, '->messages returns an empty arrayref' );
isnt( $patron->object_messages, undef, '->messages initializes the array if required' );
is( scalar @{ $patron->object_messages }, 0, '->messages returns an empty arrayref' );
$schema->storage->txn_rollback;
};