From 571a13f667336d03f6a400a5585a4108971aecd2 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 11 Jan 2022 09:42:00 -0300 Subject: [PATCH] Bug 29844: Some more uncaught cases Some more cases found using $ git grep '\->search(' | grep -v -e '\->as_list' -e '\->get_column' \ | grep '@' and then manually looking at them. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- C4/Items.pm | 2 +- Koha/ItemType.pm | 2 +- Koha/Patron/HouseboundProfile.pm | 2 +- reports/guided_reports.pl | 4 ++-- t/db_dependent/Acquisition.t | 10 +++++----- t/db_dependent/Koha/Acquisition/Basket.t | 2 +- t/db_dependent/Patron/HouseboundProfiles.t | 2 +- t/db_dependent/Patron/HouseboundRoles.t | 2 +- t/db_dependent/Patron/HouseboundVisits.t | 6 +++--- t/db_dependent/Patron/Relationships.t | 15 ++++----------- t/db_dependent/Template/Plugin/Categories.t | 4 ++-- t/db_dependent/Utils/Datatables_Virtualshelves.t | 2 +- 12 files changed, 23 insertions(+), 30 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index ce285577bd..502ccb6793 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -636,7 +636,7 @@ sub GetItemsForInventory { '+select' => [ 'marc_subfield_structures.kohafield', 'marc_subfield_structures.frameworkcode', 'me.authorised_value', 'me.lib' ], '+as' => [ 'kohafield', 'frameworkcode', 'authorised_value', 'lib' ], } - ); + )->as_list; my $avmapping = { map { $_->get_column('kohafield') . ',' . $_->get_column('frameworkcode') . ',' . $_->get_column('authorised_value') => $_->get_column('lib') } @avs }; diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 258ce91c1c..4b77433e8e 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -80,7 +80,7 @@ sub translated_descriptions { { entity => 'itemtypes', code => $self->itemtype, } - ); + )->as_list; return [ map { { lang => $_->lang, diff --git a/Koha/Patron/HouseboundProfile.pm b/Koha/Patron/HouseboundProfile.pm index 94b42647f4..612cb9afce 100644 --- a/Koha/Patron/HouseboundProfile.pm +++ b/Koha/Patron/HouseboundProfile.pm @@ -51,7 +51,7 @@ Returns an arrayref of all visits associated this houseboundProfile. sub housebound_visits { my ( $self ) = @_; my @visits = Koha::Patron::HouseboundVisits - ->special_search({ borrowernumber => $self->borrowernumber }); + ->special_search({ borrowernumber => $self->borrowernumber })->as_list; return \@visits; } diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index b081954df5..b7b588adca 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -749,7 +749,7 @@ elsif ($phase eq 'Run this report'){ } } elsif ( $authorised_value eq "biblio_framework" ) { - my @frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); + my @frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] })->as_list; my $default_source = ''; push @authorised_values,$default_source; $authorised_lib{$default_source} = 'Default'; @@ -769,7 +769,7 @@ elsif ($phase eq 'Run this report'){ } } elsif ( $authorised_value eq "categorycode" ) { - my @patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description']}); + my @patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description']})->as_list; %authorised_lib = map { $_->categorycode => $_->description } @patron_categories; push @authorised_values, $_->categorycode for @patron_categories; } diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 402e222d79..ae8855d7b7 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -911,12 +911,12 @@ subtest 'Acquisition logging' => sub { Koha::ActionLogs->delete; my $basketno = NewBasket( $booksellerid, 1 ); - my @create_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'ADD_BASKET', object => $basketno }); + my @create_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'ADD_BASKET', object => $basketno })->as_list; is (scalar @create_logs, 1, 'Basket creation is logged'); Koha::ActionLogs->delete; C4::Acquisition::ReopenBasket($basketno); - my @reopen_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'REOPEN_BASKET', object => $basketno }); + my @reopen_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'REOPEN_BASKET', object => $basketno })->as_list; is (scalar @reopen_logs, 1, 'Basket reopen is logged'); Koha::ActionLogs->delete; @@ -924,17 +924,17 @@ subtest 'Acquisition logging' => sub { basketno => $basketno, booksellerid => $booksellerid }); - my @mod_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'MODIFY_BASKET', object => $basketno }); + my @mod_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'MODIFY_BASKET', object => $basketno })->as_list; is (scalar @mod_logs, 1, 'Basket modify is logged'); Koha::ActionLogs->delete; C4::Acquisition::ModBasketHeader($basketno,"Test","","","",$booksellerid); - my @mod_header_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'MODIFY_BASKET_HEADER', object => $basketno }); + my @mod_header_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'MODIFY_BASKET_HEADER', object => $basketno })->as_list; is (scalar @mod_header_logs, 1, 'Basket header modify is logged'); Koha::ActionLogs->delete; C4::Acquisition::ModBasketUsers($basketno,(1)); - my @mod_users_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'MODIFY_BASKET_USERS', object => $basketno }); + my @mod_users_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'MODIFY_BASKET_USERS', object => $basketno })->as_list; is (scalar @mod_users_logs, 1, 'Basket users modify is logged'); t::lib::Mocks::mock_preference('AcquisitionLog', 0); diff --git a/t/db_dependent/Koha/Acquisition/Basket.t b/t/db_dependent/Koha/Acquisition/Basket.t index 0a237f8443..c3dc128513 100755 --- a/t/db_dependent/Koha/Acquisition/Basket.t +++ b/t/db_dependent/Koha/Acquisition/Basket.t @@ -425,7 +425,7 @@ subtest 'close() tests' => sub { 'Koha::Exceptions::Acquisition::Basket::AlreadyClosed', 'Trying to close an already closed basket throws an exception'; - my @close_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'CLOSE_BASKET', object => $basket->id }); + my @close_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'CLOSE_BASKET', object => $basket->id })->as_list; is (scalar @close_logs, 1, 'Basket closure is logged'); $schema->storage->txn_rollback; diff --git a/t/db_dependent/Patron/HouseboundProfiles.t b/t/db_dependent/Patron/HouseboundProfiles.t index 0a24cf5083..88a766fcc2 100755 --- a/t/db_dependent/Patron/HouseboundProfiles.t +++ b/t/db_dependent/Patron/HouseboundProfiles.t @@ -41,7 +41,7 @@ is( ); my @profiles = Koha::Patron::HouseboundProfiles - ->search({ day => $profile->{day} }); + ->search({ day => $profile->{day} })->as_list; my $found_profile = shift @profiles; is( $found_profile->borrowernumber, diff --git a/t/db_dependent/Patron/HouseboundRoles.t b/t/db_dependent/Patron/HouseboundRoles.t index 7ed46b7dc5..797a2d7437 100755 --- a/t/db_dependent/Patron/HouseboundRoles.t +++ b/t/db_dependent/Patron/HouseboundRoles.t @@ -42,7 +42,7 @@ is( ); my @roles = Koha::Patron::HouseboundRoles - ->search({ borrowernumber_id => $role->{borrowernumber_id} }); + ->search({ borrowernumber_id => $role->{borrowernumber_id} })->as_list; my $found_role = shift @roles; is( $found_role->borrowernumber_id, diff --git a/t/db_dependent/Patron/HouseboundVisits.t b/t/db_dependent/Patron/HouseboundVisits.t index eee3f00613..23e8ddca18 100755 --- a/t/db_dependent/Patron/HouseboundVisits.t +++ b/t/db_dependent/Patron/HouseboundVisits.t @@ -45,7 +45,7 @@ is( # Does it work implicitly? my @visits = Koha::Patron::HouseboundVisits - ->special_search({ borrowernumber => $visit->{borrowernumber} }); + ->special_search({ borrowernumber => $visit->{borrowernumber} })->as_list; my $found_visit = shift @visits; is( $found_visit->borrowernumber, @@ -55,7 +55,7 @@ is( # Does it work Explicitly? @visits = Koha::Patron::HouseboundVisits - ->special_search({ 'me.borrowernumber' => $visit->{borrowernumber} }); + ->special_search({ 'me.borrowernumber' => $visit->{borrowernumber} })->as_list; $found_visit = shift @visits; is( $found_visit->borrowernumber, @@ -65,7 +65,7 @@ is( # Does it work without prefetcing? @visits = Koha::Patron::HouseboundVisits - ->special_search({ borrowernumber => $visit->{borrowernumber} }, { prefetch => [] }); + ->special_search({ borrowernumber => $visit->{borrowernumber} }, { prefetch => [] })->as_list; $found_visit = shift @visits; is( $found_visit->borrowernumber, diff --git a/t/db_dependent/Patron/Relationships.t b/t/db_dependent/Patron/Relationships.t index 8e4fc8d8ec..d73e7ef796 100755 --- a/t/db_dependent/Patron/Relationships.t +++ b/t/db_dependent/Patron/Relationships.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 59; +use Test::More tests => 54; use C4::Context; @@ -90,7 +90,7 @@ Koha::Patron::Relationship->new({ guarantor_id => $chelsea->id, guarantee_id => my @gr; -@gr = $kyle->guarantee_relationships(); +@gr = $kyle->guarantee_relationships()->as_list; is( @gr, 2, 'Found 2 guarantee relationships for father' ); is( $gr[0]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' ); is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' ); @@ -108,7 +108,7 @@ is( $gr[1]->guarantee->id, $kylie->id, 'Koha::Patron returned is the correct gua is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' ); is( $gr[1]->guarantor->id, $kyle->id, 'Koha::Patron returned is the correct guarantor' ); -@gr = $chelsea->guarantee_relationships(); +@gr = $chelsea->guarantee_relationships()->as_list; is( @gr, 2, 'Found 2 guarantee relationships for mother' ); is( $gr[0]->guarantor_id, $chelsea->id, 'Guarantor matches for first relationship' ); is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' ); @@ -126,7 +126,7 @@ is( $gr[1]->guarantee->id, $kylie->id, 'Koha::Patron returned is the correct gua is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' ); is( $gr[1]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' ); -@gr = $daria->guarantor_relationships(); +@gr = $daria->guarantor_relationships()->as_list; is( @gr, 2, 'Found 4 guarantor relationships for child' ); is( $gr[0]->guarantor_id, $kyle->id, 'Guarantor matches for first relationship' ); is( $gr[0]->guarantee_id, $daria->id, 'Guarantee matches for first relationship' ); @@ -144,13 +144,6 @@ is( $gr[1]->guarantee->id, $daria->id, 'Koha::Patron returned is the correct gua is( ref($gr[1]->guarantor), 'Koha::Patron', 'Method guarantor returns a Koha::Patron' ); is( $gr[1]->guarantor->id, $chelsea->id, 'Koha::Patron returned is the correct guarantor' ); -my @siblings = $daria->siblings; -is( @siblings, 1, 'Method siblings called in list context returns list' ); -is( ref($siblings[0]), 'Koha::Patron', 'List contains a Koha::Patron' ); -is( $siblings[0]->firstname, 'Kylie', 'Sibling from list first name matches correctly' ); -is( $siblings[0]->surname, 'Hall', 'Sibling from list surname matches correctly' ); -is( $siblings[0]->id, $kylie->id, 'Sibling from list patron id matches correctly' ); - my $siblings = $daria->siblings; my $sibling = $siblings->next(); is( ref($siblings), 'Koha::Patrons', 'Calling siblings in scalar context results in a Koha::Patrons object' ); diff --git a/t/db_dependent/Template/Plugin/Categories.t b/t/db_dependent/Template/Plugin/Categories.t index 0d99a85465..e4579846df 100755 --- a/t/db_dependent/Template/Plugin/Categories.t +++ b/t/db_dependent/Template/Plugin/Categories.t @@ -36,11 +36,11 @@ my $nb_categories = Koha::Patron::Categories->count; # Create sample categories my $category_1 = $builder->build( { source => 'Category' } ); -my @categories = Koha::Template::Plugin::Categories->new->all; +my @categories = Koha::Template::Plugin::Categories->new->all->as_list; is( scalar(@categories), 1 + $nb_categories, '->all returns all defined categories' ); my $category_2 = $builder->build( { source => 'Category' } ); -@categories = Koha::Template::Plugin::Categories->new->all; +@categories = Koha::Template::Plugin::Categories->new->all->as_list; is( scalar(@categories), 2 + $nb_categories, '->all returns all defined categories' ); is( Koha::Template::Plugin::Categories->GetName( diff --git a/t/db_dependent/Utils/Datatables_Virtualshelves.t b/t/db_dependent/Utils/Datatables_Virtualshelves.t index 889448a94d..183ed92224 100755 --- a/t/db_dependent/Utils/Datatables_Virtualshelves.t +++ b/t/db_dependent/Utils/Datatables_Virtualshelves.t @@ -38,7 +38,7 @@ my $dbh = C4::Context->dbh; $dbh->do(q|DELETE FROM virtualshelves|); # Pick a categorycode from the DB -my @categories = Koha::Patron::Categories->search_with_library_limits; +my @categories = Koha::Patron::Categories->search_with_library_limits->as_list; my $categorycode = $categories[0]->categorycode; my $branchcode = "ABC"; my $branch_data = { -- 2.39.5