From 049a6bf0dc01ed5666d25ac97207a3581781c178 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 --- Koha/Account.pm | 2 +- Koha/Object.pm | 6 +++--- acqui/basket.pl | 2 +- acqui/cancelorder.pl | 2 +- catalogue/detail.pl | 4 ++-- t/db_dependent/Koha/Account/Line.t | 2 +- t/db_dependent/Koha/Acquisition/Order.t | 14 +++++++------- t/db_dependent/Koha/Biblio.t | 2 +- t/db_dependent/Koha/Object.t | 10 +++++----- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index f5798d23b8..c7cf9e58db 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -140,7 +140,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 54edbd38a0..f0a0ea8166 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -335,15 +335,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 f0cbb840fc..bdc3a4d455 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -134,7 +134,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 b0eb8edb07..2d0d36741e 100755 --- a/acqui/cancelorder.pl +++ b/acqui/cancelorder.pl @@ -57,7 +57,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 1146aa78d8..75aeed0e96 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -199,7 +199,7 @@ my $show_analytics; if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { if ( my $components = $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) ) { $show_analytics = 1 if @{$components}; # just show link when having results - $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->messages}; + $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->object_messages}; my $parts; for my $part ( @{$components} ) { $part = C4::Search::new_record_from_zebra( 'biblioserver', $part ); @@ -220,7 +220,7 @@ if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { } } else { # check if we should show analytics anyway $show_analytics = 1 if $marc_record && @{$biblio->get_marc_components(1)}; # count matters here, results does not - $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->messages}; + $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->object_messages}; } # XSLT processing of some stuff diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t index ee82a21038..fe593ae17b 100755 --- a/t/db_dependent/Koha/Account/Line.t +++ b/t/db_dependent/Koha/Account/Line.t @@ -383,7 +383,7 @@ subtest 'apply() tests' => sub { $credit_renew = $credit_renew->apply( { debits => $debits_renew } ); 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 dd2138405f..44f3c89845 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/Biblio.t b/t/db_dependent/Koha/Biblio.t index f57bb0cb36..01a94dae81 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -547,7 +547,7 @@ subtest 'get_marc_components() tests' => sub { qr{^Warning from simple_search_compat: 'error searching analytics'}; is_deeply( - $host_biblio->messages, + $host_biblio->object_messages, [ { type => 'error', diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index 0da041f596..0f5343005d 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -974,13 +974,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' ); @@ -988,11 +988,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