From a9c4b0bda368cf19fb10962da0d2b8daf98c82c0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 4 Jan 2022 14:28:26 +0100 Subject: [PATCH] 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 Signed-off-by: Marcel de Rooy Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall (cherry picked from commit 30b9270bd9dfd773821d5ca17c924e8f7b56c45c) Signed-off-by: Andrew Fuerste-Henry --- Koha/Account.pm | 2 +- Koha/Object.pm | 6 +++--- acqui/basket.pl | 2 +- acqui/cancelorder.pl | 2 +- catalogue/detail.pl | 1 - t/db_dependent/Koha/Account/Line.t | 2 +- t/db_dependent/Koha/Acquisition/Order.t | 14 +++++++------- t/db_dependent/Koha/Object.t | 10 +++++----- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index 73bf2c3608..500d99f2dc 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -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; } diff --git a/Koha/Object.pm b/Koha/Object.pm index b8cea8a8ab..2b8b6bcfa3 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -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} = [] diff --git a/acqui/basket.pl b/acqui/basket.pl index 0c89b1fab7..be020195fe 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -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 ) { diff --git a/acqui/cancelorder.pl b/acqui/cancelorder.pl index d5b57f81d6..b4c229e38b 100755 --- a/acqui/cancelorder.pl +++ b/acqui/cancelorder.pl @@ -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 ) diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 10352625e5..f81d1436f4 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -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( diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t index 232a56720e..0ee19efaaf 100755 --- a/t/db_dependent/Koha/Account/Line.t +++ b/t/db_dependent/Koha/Account/Line.t @@ -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' ); diff --git a/t/db_dependent/Koha/Acquisition/Order.t b/t/db_dependent/Koha/Acquisition/Order.t index 8919fe29af..4ae3da62db 100755 --- a/t/db_dependent/Koha/Acquisition/Order.t +++ b/t/db_dependent/Koha/Acquisition/Order.t @@ -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' ); diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index b50074f9ba..5e9d78af8b 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -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; }; -- 2.39.5