From ef410fd62f279a10687636a4f26babb2c91ecadc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 22 Feb 2018 13:06:59 -0300 Subject: [PATCH] Bug 20287: Replace occurrences of AddMember with Koha::Patron->new->store->borrowernumber Signed-off-by: Josef Moravec Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- C4/Auth_with_ldap.pm | 1 - C4/Members.pm | 14 ++++---- Koha/NorwegianPatronDB.pm | 2 +- Koha/Patrons/Import.pm | 25 +++++++------- installer/onboarding.pl | 10 +++--- members/memberentry.pl | 12 +++++-- members/nl-search.pl | 9 ++--- misc/devel/create_superlibrarian.pl | 6 ++-- opac/svc/auth/googleopenidconnect | 8 ++--- t/db_dependent/Acquisition/OrderUsers.t | 5 +-- t/db_dependent/Budgets.t | 10 +++--- t/db_dependent/Circulation.t | 33 +++++++++---------- t/db_dependent/Circulation/Branch.t | 7 ++-- t/db_dependent/Circulation/Chargelostitem.t | 5 +-- .../Circulation/CheckIfIssuedToPatron.t | 6 ++-- t/db_dependent/Circulation/GetTopIssues.t | 5 ++- t/db_dependent/Circulation/IsItemIssued.t | 5 ++- .../IssuingRules/maxsuspensiondays.t | 6 ++-- .../Circulation/MarkIssueReturned.t | 4 +-- t/db_dependent/Circulation/issue.t | 9 +++-- t/db_dependent/Holds.t | 5 ++- t/db_dependent/Holds/LocalHoldsPriority.t | 6 ++-- t/db_dependent/Holds/RevertWaitingStatus.t | 5 ++- t/db_dependent/Koha/Object.t | 5 ++- t/db_dependent/Koha/Patrons.t | 16 ++++----- t/db_dependent/Letters.t | 15 +++++---- t/db_dependent/Members.t | 28 ++++++++-------- t/db_dependent/Members/GetAllIssues.t | 4 +-- t/db_dependent/Members/IssueSlip.t | 2 +- t/db_dependent/Patron/Borrower_Debarments.t | 5 ++- t/db_dependent/Patron/Borrower_Discharge.t | 2 +- t/db_dependent/Patron/Borrower_Files.t | 6 ++-- t/db_dependent/Reserves.t | 20 +++++------ t/db_dependent/Serials_2.t | 6 ++-- t/db_dependent/Suggestions.t | 5 ++- .../Utils/Datatables_Virtualshelves.t | 9 +++-- 36 files changed, 161 insertions(+), 160 deletions(-) diff --git a/C4/Auth_with_ldap.pm b/C4/Auth_with_ldap.pm index 03fab46da8..83b0072eca 100644 --- a/C4/Auth_with_ldap.pm +++ b/C4/Auth_with_ldap.pm @@ -23,7 +23,6 @@ use Carp; use C4::Debug; use C4::Context; -use C4::Members qw(AddMember); use C4::Members::Attributes; use C4::Members::AttributeTypes; use C4::Members::Messaging; diff --git a/C4/Members.pm b/C4/Members.pm index cacccc781c..20e4f47168 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -746,10 +746,9 @@ sub IssueSlip { sub AddMember_Auto { my ( %borrower ) = @_; - $borrower{'borrowernumber'} = AddMember(%borrower); - my $patron = Koha::Patrons->find( $borrower{borrowernumber} )->unblessed; - $patron->{password} = $borrower{password}; - return %$patron; + my $patron = Koha::Patron->new(\%borrower)->store; + + return %{ $patron->unblessed }; } =head2 AddMember_Opac @@ -760,16 +759,17 @@ sub AddMember_Opac { my ( %borrower ) = @_; $borrower{'categorycode'} //= C4::Context->preference('PatronSelfRegistrationDefaultCategory'); - if (not defined $borrower{'password'}){ + my $password = $borrower{password}; + if (not defined $password){ my $sr = new String::Random; $sr->{'A'} = [ 'A'..'Z', 'a'..'z' ]; - my $password = $sr->randpattern("AAAAAAAAAA"); + $password = $sr->randpattern("AAAAAAAAAA"); $borrower{'password'} = $password; } %borrower = AddMember_Auto(%borrower); - return ( $borrower{'borrowernumber'}, $borrower{'password'} ); + return ( $borrower{'borrowernumber'}, $password ); } =head2 DeleteExpiredOpacRegistrations diff --git a/Koha/NorwegianPatronDB.pm b/Koha/NorwegianPatronDB.pm index 237ddd7d54..f6155a8fd1 100644 --- a/Koha/NorwegianPatronDB.pm +++ b/Koha/NorwegianPatronDB.pm @@ -566,7 +566,7 @@ sub _format_soap_error { =head2 _soap_to_koha_patron -Convert a SOAP object of type "Laaner" into a hash that can be sent to AddMember or ModMember. +Convert a SOAP object of type "Laaner" into a hash that can be sent to Koha::Patron =cut diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm index dbf945c632..e9c1f80ddb 100644 --- a/Koha/Patrons/Import.pm +++ b/Koha/Patrons/Import.pm @@ -295,39 +295,42 @@ sub import_patrons { ); } else { - if ( $borrowernumber = AddMember(%borrower) ) { + my $patron = eval { + Koha::Patron->new(\%borrower)->store; + }; + unless ( $@ ) { - if ( $borrower{debarred} ) { + if ( $patron->is_debarred ) { AddDebarment( { - borrowernumber => $borrowernumber, - expiration => $borrower{debarred}, - comment => $borrower{debarredcomment} + borrowernumber => $patron->borrowernumber, + expiration => $patron->debarred, + comment => $patron->debarredcomment, } ); } if ($extended) { - SetBorrowerAttributes( $borrowernumber, $patron_attributes ); + SetBorrowerAttributes( $patron->borrowernumber, $patron_attributes ); } if ($set_messaging_prefs) { C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { - borrowernumber => $borrowernumber, - categorycode => $borrower{categorycode} + borrowernumber => $patron->borrowernumber, + categorycode => $patron->categorycode, } ); } $imported++; - push @imported_borrowers, $borrowernumber; #for patronlist + push @imported_borrowers, $patron->borrowernumber; #for patronlist push( @feedback, { feedback => 1, name => 'lastimported', - value => $borrower{'surname'} . ' / ' . $borrowernumber + value => $patron->surname . ' / ' . $patron->borrowernumber, } ); } @@ -338,7 +341,7 @@ sub import_patrons { @errors, { name => 'lastinvalid', - value => $borrower{'surname'} . ' / AddMember', + value => $borrower{'surname'} . ' / Create patron', } ); } diff --git a/installer/onboarding.pl b/installer/onboarding.pl index 83859e77c2..f8bd84e8a2 100755 --- a/installer/onboarding.pl +++ b/installer/onboarding.pl @@ -22,15 +22,13 @@ use C4::Context; use C4::InstallAuth; use CGI qw ( -utf8 ); use C4::Output; -use C4::Members; use Koha::Patrons; use Koha::Libraries; use Koha::Database; use Koha::DateUtils; +use Koha::Patrons; use Koha::Patron::Categories; -use Koha::Patron::Category; use Koha::ItemTypes; -use Koha::IssuingRule; use Koha::IssuingRules; #Setting variables @@ -187,10 +185,12 @@ if ( $step == 3 ) { $patron_data->{dateexpiry} = $patron_category->get_expiry_date( $patron_data->{dateenrolled} ); - my $borrowernumber = C4::Members::AddMember(%$patron_data); + eval { + Koha::Patron->new($patron_data)->store; + }; #Error handling checking if the patron was created successfully - if ($borrowernumber) { + unless ($@) { push @messages, { code => 'success_on_insert_patron' }; } else { diff --git a/members/memberentry.pl b/members/memberentry.pl index f10002a80b..e97f085c94 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -222,6 +222,7 @@ if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) qr/^\d+$/, qr/^\d+-DAYS/, qr/^patron_attr_/, + qr/^csrf_token$/, ); for my $regexp (@keys_to_delete) { for (keys %newdata) { @@ -422,8 +423,15 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ $debug and warn "$op dates: " . join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry); if ($op eq 'insert'){ # we know it's not a duplicate borrowernumber or there would already be an error - $borrowernumber = &AddMember(%newdata); - $newdata{'borrowernumber'} = $borrowernumber; + delete $newdata{password2}; + my $patron = eval { Koha::Patron->new(\%newdata)->store }; + if ( $@ ) { + # FIXME Urgent error handling here, we cannot fail without relevant feedback + # Lot of code will need to be removed from this script to handle exceptions raised by Koha::Patron->store + warn "Patron creation failed! - $@"; # Maybe we must die instead of just warn + } else { + $borrowernumber = $patron->borrowernumber; + } # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode. if ( C4::Context->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) { diff --git a/members/nl-search.pl b/members/nl-search.pl index 2ff2177f86..a873fd9663 100755 --- a/members/nl-search.pl +++ b/members/nl-search.pl @@ -39,12 +39,12 @@ use CGI; use C4::Auth; use C4::Context; use C4::Output; -use C4::Members; use C4::Members::Attributes qw( SetBorrowerAttributes ); use C4::Utils::DataTables::Members; use Koha::NorwegianPatronDB qw( NLCheckSysprefs NLSearch NLDecodePin NLGetFirstname NLGetSurname NLSync ); use Koha::Database; use Koha::DateUtils; +use Koha::Patrons; use Koha::Patron::Categories; my $cgi = CGI->new; @@ -134,13 +134,14 @@ if ( $op && $op eq 'search' ) { 'categorycode' => scalar $cgi->param('categorycode'), ); # Add the new patron - my $borrowernumber = &AddMember(%borrower); - if ( $borrowernumber ) { + my $patron = eval { Koha::Patron->new(\%borrower)->store; }; + unless ( $@) { + my $borrowernumber = $patron->borrowernumber; # Add extended patron attributes SetBorrowerAttributes($borrowernumber, [ { code => 'fnr', value => scalar $cgi->param('fnr_hash') }, ], 'no_branch_limit' ); - # Override the default sync data created by AddMember + # Override the default sync data created by Koha::Patron->store my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({ 'synctype' => 'norwegianpatrondb', 'borrowernumber' => $borrowernumber, diff --git a/misc/devel/create_superlibrarian.pl b/misc/devel/create_superlibrarian.pl index 9a8d0ff984..89b738783f 100755 --- a/misc/devel/create_superlibrarian.pl +++ b/misc/devel/create_superlibrarian.pl @@ -21,7 +21,7 @@ use Modern::Perl; use Getopt::Long; use Pod::Usage; -use C4::Members; +use Koha::Patrons; my ( $help, $surname, $userid, $password, $branchcode, $categorycode, $cardnumber ); GetOptions( @@ -40,7 +40,7 @@ pod2usage("branchcode is mandatory") unless $branchcode; pod2usage("categorycode is mandatory") unless $categorycode; pod2usage("cardnumber is mandatory") unless $cardnumber; -C4::Members::AddMember( +Koha::Patron->new({ surname => $surname, userid => $userid, cardnumber => $cardnumber, @@ -48,7 +48,7 @@ C4::Members::AddMember( categorycode => $categorycode, password => $password, flags => 1, -); +})->store; =head1 NAME diff --git a/opac/svc/auth/googleopenidconnect b/opac/svc/auth/googleopenidconnect index 64d703ea7b..2804005f8e 100755 --- a/opac/svc/auth/googleopenidconnect +++ b/opac/svc/auth/googleopenidconnect @@ -34,7 +34,6 @@ use Modern::Perl; use CGI qw ( -utf8 escape ); use C4::Auth qw{ checkauth get_session get_template_and_user }; use C4::Context; -use C4::Members; use C4::Output; use Koha::Patrons; @@ -196,7 +195,8 @@ elsif ( defined $query->param('code') ) { my $library = Koha::Libraries->find( $branchcode ); if (defined $patron_category && defined $library) { my $password = undef; - my $borrowernumber = C4::Members::AddMember( + # TODO errors handling! + my $borrower = Koha::Patron->new( firstname => $firstname, surname => $surname, email => $email, @@ -204,9 +204,7 @@ elsif ( defined $query->param('code') ) { branchcode => $branchcode, userid => $userid, password => $password - ); - $borrower = Koha::Patrons->find( { - borrowernumber => $borrowernumber } ); + )->store; } else { $error_feedback = 'The GoogleOpenIDConnectDefaultBranch or GoogleOpenIDConnectDefaultCategory system preferences are not configured properly. Please contact the library with this error message.'; } diff --git a/t/db_dependent/Acquisition/OrderUsers.t b/t/db_dependent/Acquisition/OrderUsers.t index 5b142f75b4..9d88734d95 100644 --- a/t/db_dependent/Acquisition/OrderUsers.t +++ b/t/db_dependent/Acquisition/OrderUsers.t @@ -7,6 +7,7 @@ use C4::Letters; use Koha::Database; use Koha::Acquisition::Booksellers; use Koha::Acquisition::Orders; +use Koha::Patrons; use t::lib::TestBuilder; @@ -65,7 +66,7 @@ my $invoiceid = AddInvoice( unknown => "unknown" ); -my $borrowernumber = C4::Members::AddMember( +my $borrowernumber = Koha::Patron->new({ cardnumber => 'TESTCARD', firstname => 'TESTFN', surname => 'TESTSN', @@ -74,7 +75,7 @@ my $borrowernumber = C4::Members::AddMember( dateofbirth => '', dateexpiry => '9999-12-31', userid => 'TESTUSERID' -); +})->store->borrowernumber; C4::Acquisition::ModOrderUsers( $ordernumber, $borrowernumber ); diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 21f2d59b1f..a583d9be72 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -8,10 +8,10 @@ BEGIN { use C4::Context; use C4::Biblio; use C4::Acquisition; -use C4::Members qw( AddMember ); use Koha::Acquisition::Booksellers; use Koha::Acquisition::Orders; +use Koha::Patrons; use t::lib::TestBuilder; @@ -681,7 +681,7 @@ for my $new_budget ( @new_budgets ) { my $patron_category = $builder->build({ source => 'Category' }); my $branchcode = $library->{branchcode}; -my $john_doe = C4::Members::AddMember( +my $john_doe = Koha::Patron->new({ cardnumber => '123456', firstname => 'John', surname => 'Doe', @@ -690,7 +690,7 @@ my $john_doe = C4::Members::AddMember( dateofbirth => '', dateexpiry => '9999-12-31', userid => 'john.doe' -); +})->store->borrowernumber; C4::Budgets::SetOwnerToFundHierarchy( $budget_id1, $john_doe ); is( C4::Budgets::GetBudget($budget_id1)->{budget_owner_id}, @@ -706,7 +706,7 @@ is( C4::Budgets::GetBudget($budget_id2)->{budget_owner_id}, is( C4::Budgets::GetBudget($budget_id21)->{budget_owner_id}, undef, "SetOwnerToFundHierarchy should not have set an owner for budget 21 ($budget_id21)" ); -my $jane_doe = C4::Members::AddMember( +my $jane_doe = Koha::Patron->new({ cardnumber => '789012', firstname => 'Jane', surname => 'Doe', @@ -715,7 +715,7 @@ my $jane_doe = C4::Members::AddMember( dateofbirth => '', dateexpiry => '9999-12-31', userid => 'jane.doe' -); +})->store->borrowernumber; C4::Budgets::SetOwnerToFundHierarchy( $budget_id11, $jane_doe ); is( C4::Budgets::GetBudget($budget_id1)->{budget_owner_id}, diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 9f0791a491..7cb5529718 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -29,7 +29,6 @@ use C4::Circulation; use C4::Biblio; use C4::Items; use C4::Log; -use C4::Members; use C4::Reserves; use C4::Overdues qw(UpdateFine CalcFine); use Koha::DateUtils; @@ -307,11 +306,11 @@ C4::Context->dbh->do("DELETE FROM accountlines"); dateexpiry => dt_from_string->subtract( months => 1 ), ); - my $renewing_borrowernumber = AddMember(%renewing_borrower_data); - my $reserving_borrowernumber = AddMember(%reserving_borrower_data); - my $hold_waiting_borrowernumber = AddMember(%hold_waiting_borrower_data); - my $restricted_borrowernumber = AddMember(%restricted_borrower_data); - my $expired_borrowernumber = AddMember(%expired_borrower_data); + my $renewing_borrowernumber = Koha::Patron->new(\%renewing_borrower_data)->store->borrowernumber; + my $reserving_borrowernumber = Koha::Patron->new(\%reserving_borrower_data)->store->borrowernumber; + my $hold_waiting_borrowernumber = Koha::Patron->new(\%hold_waiting_borrower_data)->store->borrowernumber; + my $restricted_borrowernumber = Koha::Patron->new(\%restricted_borrower_data)->store->borrowernumber; + my $expired_borrowernumber = Koha::Patron->new(\%expired_borrower_data)->store->borrowernumber; my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed; my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed; @@ -936,7 +935,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); branchcode => $branch, ); - my $a_borrower_borrowernumber = AddMember(%a_borrower_data); + my $a_borrower_borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber; my $a_borrower = Koha::Patrons->find( $a_borrower_borrowernumber )->unblessed; my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 ); @@ -1015,7 +1014,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); branchcode => $branch, ); - my $borrowernumber = AddMember(%a_borrower_data); + my $borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber; my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $issue = AddIssue( $borrower, $barcode ); @@ -1074,18 +1073,18 @@ C4::Context->dbh->do("DELETE FROM accountlines"); $biblionumber ); - my $borrowernumber1 = AddMember( + my $borrowernumber1 = Koha::Patron->new({ firstname => 'Kyle', surname => 'Hall', categorycode => $patron_category->{categorycode}, branchcode => $library2->{branchcode}, - ); - my $borrowernumber2 = AddMember( + })->store->borrowernumber; + my $borrowernumber2 = Koha::Patron->new({ firstname => 'Chelsea', surname => 'Hall', categorycode => $patron_category->{categorycode}, branchcode => $library2->{branchcode}, - ); + })->store->borrowernumber; my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed; my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed; @@ -1146,12 +1145,12 @@ C4::Context->dbh->do("DELETE FROM accountlines"); $biblionumber ); - my $borrowernumber = AddMember( + my $borrowernumber = Koha::Patron->new({ firstname => 'fn', surname => 'dn', categorycode => $patron_category->{categorycode}, branchcode => $branch, - ); + })->store->borrowernumber; my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; @@ -1507,7 +1506,7 @@ subtest 'MultipleReserves' => sub { categorycode => $patron_category->{categorycode}, branchcode => $branch, ); - my $renewing_borrowernumber = AddMember(%renewing_borrower_data); + my $renewing_borrowernumber = Koha::Patron->new(\%renewing_borrower_data)->store->borrowernumber; my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed; my $issue = AddIssue( $renewing_borrower, $barcode1); my $datedue = dt_from_string( $issue->date_due() ); @@ -1520,7 +1519,7 @@ subtest 'MultipleReserves' => sub { categorycode => $patron_category->{categorycode}, branchcode => $branch, ); - my $reserving_borrowernumber1 = AddMember(%reserving_borrower_data1); + my $reserving_borrowernumber1 = Koha::Patron->new(\%reserving_borrower_data1)->store->borrowernumber; AddReserve( $branch, $reserving_borrowernumber1, $biblionumber, $bibitems, $priority, $resdate, $expdate, $notes, @@ -1533,7 +1532,7 @@ subtest 'MultipleReserves' => sub { categorycode => $patron_category->{categorycode}, branchcode => $branch, ); - my $reserving_borrowernumber2 = AddMember(%reserving_borrower_data2); + my $reserving_borrowernumber2 = Koha::Patron->new(\%reserving_borrower_data2)->store->borrowernumber; AddReserve( $branch, $reserving_borrowernumber2, $biblionumber, $bibitems, $priority, $resdate, $expdate, $notes, diff --git a/t/db_dependent/Circulation/Branch.t b/t/db_dependent/Circulation/Branch.t index 1be07d98a3..c56e68711a 100644 --- a/t/db_dependent/Circulation/Branch.t +++ b/t/db_dependent/Circulation/Branch.t @@ -18,11 +18,12 @@ use Modern::Perl; use C4::Biblio; -use C4::Members; use C4::Circulation; use C4::Items; use C4::Context; +use Koha::Patrons; + use Test::More tests => 14; use t::lib::Mocks; use t::lib::TestBuilder; @@ -138,12 +139,12 @@ my @sampleitem3 = C4::Items::AddItem( my $item_id3 = $sampleitem3[2]; #Add borrower -my $borrower_id1 = C4::Members::AddMember( +my $borrower_id1 = Koha::Patron->new({ firstname => 'firstname1', surname => 'surname1 ', categorycode => $samplecat->{categorycode}, branchcode => $samplebranch1->{branchcode}, -); +})->store->borrowernumber; is_deeply( GetBranchBorrowerCircRule(), diff --git a/t/db_dependent/Circulation/Chargelostitem.t b/t/db_dependent/Circulation/Chargelostitem.t index f9b5a3bb35..658400c924 100644 --- a/t/db_dependent/Circulation/Chargelostitem.t +++ b/t/db_dependent/Circulation/Chargelostitem.t @@ -9,8 +9,8 @@ use t::lib::TestBuilder; use C4::Biblio; use C4::Items; -use C4::Members; use C4::Circulation; +use Koha::Patrons; use MARC::Record; BEGIN { @@ -55,7 +55,8 @@ my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; -my $borrowernumber = AddMember(categorycode => $categorycode, branchcode => $branchcode); +my $borrowernumber = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber; +# TODO following code must be simplified to use the Koha::Patron object my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed(); # Need to mock userenv for AddIssue diff --git a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t b/t/db_dependent/Circulation/CheckIfIssuedToPatron.t index 4e21c41a87..c25f7dc8ee 100644 --- a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t +++ b/t/db_dependent/Circulation/CheckIfIssuedToPatron.t @@ -23,7 +23,6 @@ use t::lib::TestBuilder; use C4::Biblio; use C4::Items; -use C4::Members; use Koha::Library; use Koha::Patrons; use MARC::Record; @@ -73,8 +72,9 @@ my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); my $barcode2 = '0202'; AddItem({ barcode => $barcode2, %item_info }, $biblionumber2); -my $borrowernumber1 = AddMember(categorycode => $categorycode, branchcode => $branchcode); -my $borrowernumber2 = AddMember(categorycode => $categorycode, branchcode => $branchcode); +my $borrowernumber1 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber; +my $borrowernumber2 = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode})->store->borrowernumber; +# FIXME following code must be simplified to use the Koha::Patron objects my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed; my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed; diff --git a/t/db_dependent/Circulation/GetTopIssues.t b/t/db_dependent/Circulation/GetTopIssues.t index 569176b9cb..b35f35aba2 100644 --- a/t/db_dependent/Circulation/GetTopIssues.t +++ b/t/db_dependent/Circulation/GetTopIssues.t @@ -26,7 +26,6 @@ use C4::Context; use C4::Circulation; use C4::Biblio; use C4::Items; -use C4::Members; use Koha::Database; use Koha::Patrons; @@ -63,11 +62,11 @@ AddItem({ homebranch => $branch_2->{ branchcode }, }, $biblionumber); -my $borrowernumber = AddMember( +my $borrowernumber = Koha::Patron->new({ userid => 'gti.test', categorycode => $category, branchcode => $branch_1->{ branchcode } -); +})->store->borrowernumber; my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; AddIssue($borrower, 'GTI_BARCODE_001'); diff --git a/t/db_dependent/Circulation/IsItemIssued.t b/t/db_dependent/Circulation/IsItemIssued.t index 7a30da9409..b175c55375 100644 --- a/t/db_dependent/Circulation/IsItemIssued.t +++ b/t/db_dependent/Circulation/IsItemIssued.t @@ -23,7 +23,6 @@ use Test::MockModule; use C4::Biblio; use C4::Circulation; use C4::Items; -use C4::Members; use Koha::Database; use Koha::DateUtils; use Koha::Patrons; @@ -49,12 +48,12 @@ C4::Context->set_userenv( -my $borrowernumber = AddMember( +my $borrowernumber = Koha::Patron->new({ firstname => 'my firstname', surname => 'my surname', categorycode => $patron_category->{categorycode}, branchcode => $library->{branchcode}, -); +})->store->borrowernumber; my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $record = MARC::Record->new(); diff --git a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t b/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t index 70fa799796..f02efcda84 100644 --- a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t +++ b/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t @@ -8,10 +8,10 @@ use C4::Context; use C4::Biblio qw( AddBiblio ); use C4::Circulation qw( AddIssue AddReturn ); use C4::Items qw( AddItem ); -use C4::Members qw( AddMember ); use Koha::Database; use Koha::DateUtils; use Koha::Patron::Debarments qw( GetDebarments DelDebarment ); +use Koha::Patrons; use t::lib::TestBuilder; @@ -46,12 +46,12 @@ $builder->build( } ); -my $borrowernumber = AddMember( +my $borrowernumber = Koha::Patron->new({ firstname => 'my firstname', surname => 'my surname', categorycode => $patron_category->{categorycode}, branchcode => $branchcode, -); +})->store->borrowernumber; my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $record = MARC::Record->new(); diff --git a/t/db_dependent/Circulation/MarkIssueReturned.t b/t/db_dependent/Circulation/MarkIssueReturned.t index d23290b7ef..452707aa91 100644 --- a/t/db_dependent/Circulation/MarkIssueReturned.t +++ b/t/db_dependent/Circulation/MarkIssueReturned.t @@ -25,9 +25,9 @@ use t::lib::TestBuilder; use C4::Circulation; use C4::Context; -use C4::Members; use Koha::Checkouts; use Koha::Database; +use Koha::Patrons; my $schema = Koha::Database->schema; $schema->storage->txn_begin; @@ -66,7 +66,7 @@ subtest 'anonymous patron' => sub { like ( $@, qr, 'AnonymousPatron is not set - Fatal error on anonymization' ); Koha::Checkouts->find( $issue->issue_id )->delete; - my $anonymous_borrowernumber = C4::Members::AddMember( categorycode => $patron_category->{categorycode}, branchcode => $library->{branchcode} ); + my $anonymous_borrowernumber = Koha::Patron->new({categorycode => $patron_category->{categorycode}, branchcode => $library->{branchcode} })->store->borrowernumber; t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_borrowernumber); $issue = C4::Circulation::AddIssue( $patron, $item->{barcode} ); eval { C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, 'dropbox_branch', 'returndate', 2 ) }; diff --git a/t/db_dependent/Circulation/issue.t b/t/db_dependent/Circulation/issue.t index 68160dd90b..6f190f070f 100644 --- a/t/db_dependent/Circulation/issue.t +++ b/t/db_dependent/Circulation/issue.t @@ -27,7 +27,6 @@ use C4::Biblio; use C4::Circulation; use C4::Context; use C4::Items; -use C4::Members; use C4::Reserves; use Koha::Checkouts; use Koha::Database; @@ -143,19 +142,19 @@ my @sampleitem2 = C4::Items::AddItem( my $item_id2 = $sampleitem2[2]; #Add borrower -my $borrower_id1 = C4::Members::AddMember( +my $borrower_id1 = Koha::Patron->new({ firstname => 'firstname1', surname => 'surname1 ', categorycode => $categorycode, branchcode => $branchcode_1 -); +})->store->borrowernumber; my $borrower_1 = Koha::Patrons->find( $borrower_id1 )->unblessed; -my $borrower_id2 = C4::Members::AddMember( +my $borrower_id2 = Koha::Patron->new({ firstname => 'firstname2', surname => 'surname2 ', categorycode => $categorycode, branchcode => $branchcode_2, -); +})->store->borrowernumber; my $borrower_2 = Koha::Patrons->find( $borrower_id2 )->unblessed; my @USERENV = ( diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 1e6c234487..93fe7459ba 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -11,7 +11,6 @@ use Test::More tests => 55; use MARC::Record; use C4::Biblio; use C4::Items; -use C4::Members; use C4::Calendar; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); @@ -58,12 +57,12 @@ my ($item_bibnum, $item_bibitemnum, $itemnumber) # Create some borrowers my @borrowernumbers; foreach (1..$borrowers_count) { - my $borrowernumber = AddMember( + my $borrowernumber = Koha::Patron->new({ firstname => 'my firstname', surname => 'my surname ' . $_, categorycode => $category->{categorycode}, branchcode => $branch_1, - ); + })->store->borrowernumber; push @borrowernumbers, $borrowernumber; } diff --git a/t/db_dependent/Holds/LocalHoldsPriority.t b/t/db_dependent/Holds/LocalHoldsPriority.t index 8da4befd72..f107e71d09 100755 --- a/t/db_dependent/Holds/LocalHoldsPriority.t +++ b/t/db_dependent/Holds/LocalHoldsPriority.t @@ -9,8 +9,8 @@ use Test::More tests => 6; use MARC::Record; use C4::Biblio; use C4::Items; -use C4::Members; use Koha::Database; +use Koha::Patrons; use t::lib::TestBuilder; @@ -57,12 +57,12 @@ my $patron_category = $builder->build({ source => 'Category' }); # Create some borrowers my @borrowernumbers; foreach ( 1 .. $borrowers_count ) { - my $borrowernumber = AddMember( + my $borrowernumber = Koha::Patron->new({ firstname => 'my firstname', surname => 'my surname ' . $_, categorycode => $patron_category->{categorycode}, branchcode => $branchcodes[$_], - ); + })->store->borrowernumber; push @borrowernumbers, $borrowernumber; } diff --git a/t/db_dependent/Holds/RevertWaitingStatus.t b/t/db_dependent/Holds/RevertWaitingStatus.t index ae7fdaa8dd..4df597f176 100755 --- a/t/db_dependent/Holds/RevertWaitingStatus.t +++ b/t/db_dependent/Holds/RevertWaitingStatus.t @@ -24,7 +24,6 @@ use Test::More tests => 3; use MARC::Record; use C4::Biblio; use C4::Items; -use C4::Members; use C4::Reserves; use Koha::Libraries; @@ -73,12 +72,12 @@ my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( my $patron_category = $builder->build({ source => 'Category' }); my @borrowernumbers; foreach my $i ( 1 .. $borrowers_count ) { - my $borrowernumber = AddMember( + my $borrowernumber = Koha::Patron->new({ firstname => 'my firstname', surname => 'my surname ' . $i, categorycode => $patron_category->{categorycode}, branchcode => $branchcode, - ); + })->store->borrowernumber; push @borrowernumbers, $borrowernumber; } diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index a00083a5b7..7630105e8e 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -25,10 +25,10 @@ use DateTime; use C4::Context; use C4::Biblio; # AddBiblio use C4::Circulation; # AddIssue -use C4::Members;# AddMember use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Libraries; +use Koha::Patrons; use Scalar::Util qw( isvstring ); use Try::Tiny; @@ -352,8 +352,7 @@ subtest 'unblessed_all_relateds' => sub { categorycode => $patron_category->{categorycode}, branchcode => $library->branchcode, }; - my $borrowernumber = C4::Members::AddMember(%$patron_data); - my $patron = Koha::Patrons->find( $borrowernumber ); + my $patron = Koha::Patron->new($patron_data)->store; my ($biblionumber) = AddBiblio( MARC::Record->new, '' ); my $biblio = Koha::Biblios->find( $biblionumber ); my $item = $builder->build_object( diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index bb6e2bcf98..d7153b0d32 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -28,11 +28,9 @@ use JSON; use C4::Biblio; use C4::Circulation; -use C4::Members; use C4::Circulation; use Koha::Holds; -use Koha::Patron; use Koha::Patrons; use Koha::Patron::Categories; use Koha::Database; @@ -395,7 +393,7 @@ subtest 'add_enrolment_fee_if_needed' => sub { branchcode => $library->{branchcode}, ); - my $borrowernumber = C4::Members::AddMember(%borrower_data); + my $borrowernumber = Koha::Patron->new(\%borrower_data)->store->borrowernumber; $borrower_data{borrowernumber} = $borrowernumber; my $patron = Koha::Patrons->find( $borrowernumber ); @@ -1259,7 +1257,7 @@ subtest 'userid_is_valid' => sub { ); my $expected_userid_patron_1 = 'tomasito.none'; - my $borrowernumber = AddMember(%data); + my $borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber; my $patron_1 = Koha::Patrons->find($borrowernumber); is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' ); @@ -1287,7 +1285,7 @@ subtest 'userid_is_valid' => sub { # Add a new borrower with the same userid but different cardnumber $data{cardnumber} = "987654321"; - my $new_borrowernumber = AddMember(%data); + my $new_borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber; my $patron_2 = Koha::Patrons->find($new_borrowernumber); $patron_2->userid($patron_1->userid); is( $patron_2->has_valid_userid, @@ -1296,10 +1294,10 @@ subtest 'userid_is_valid' => sub { my $new_userid = 'a_user_id'; $data{cardnumber} = "234567890"; $data{userid} = 'a_user_id'; - $borrowernumber = AddMember(%data); + $borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber; my $patron_3 = Koha::Patrons->find($borrowernumber); is( $patron_3->userid, $new_userid, - 'AddMember should insert the given userid' ); + 'Koha::Patron->store should insert the given userid' ); # Cleanup $patron_1->delete; @@ -1329,14 +1327,14 @@ subtest 'generate_userid' => sub { my $new_patron = Koha::Patron->new({ firstname => $data{firstname}, surname => $data{surname} } ); my $userid = $new_patron->generate_userid; is( $userid, $expected_userid_patron_1, 'generate_userid should generate the userid we expect' ); - my $borrowernumber = AddMember(%data); + my $borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber; my $patron_1 = Koha::Patrons->find($borrowernumber); is ( $patron_1->userid, $expected_userid_patron_1, 'The userid generated should be the one we expect' ); $userid = $new_patron->generate_userid; is( $userid, $expected_userid_patron_1 . '1', 'generate_userid should generate the userid we expect' ); $data{cardnumber} = '987654321'; - my $new_borrowernumber = AddMember(%data); + my $new_borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber; my $patron_2 = Koha::Patrons->find($new_borrowernumber); isnt( $patron_2->userid, 'tomasito', "Patron with duplicate userid has new userid generated" ); diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 6440dc5c0a..5a60e1470e 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -66,14 +66,14 @@ my $library = $builder->build({ }); my $patron_category = $builder->build({ source => 'Category' })->{categorycode}; my $date = dt_from_string; -my $borrowernumber = AddMember( +my $borrowernumber = Koha::Patron->new({ firstname => 'Jane', surname => 'Smith', categorycode => $patron_category, branchcode => $library->{branchcode}, dateofbirth => $date, smsalertnumber => undef, -); +})->store->borrowernumber; my $marc_record = MARC::Record->new; my( $biblionumber, $biblioitemnumber ) = AddBiblio( $marc_record, '' ); @@ -468,16 +468,17 @@ $dbh->do(q{INSERT INTO letter (module, code, name, title, content) VALUES ('seri my ($serials_count, @serials) = GetSerials($subscriptionid); my $serial = $serials[0]; -my $borrowernumber = AddMember( +my $patron = Koha::Patron->new({ firstname => 'John', surname => 'Smith', categorycode => $patron_category, branchcode => $library->{branchcode}, dateofbirth => $date, email => 'john.smith@test.de', -); +})->store; +my $borrowernumber = $patron->borrowernumber; my $subscription = Koha::Subscriptions->find( $subscriptionid ); -$subscription->add_subscriber( scalar Koha::Patrons->find( $borrowernumber ) ); +$subscription->add_subscriber( $patron ); my $err2; warning_is { @@ -676,14 +677,14 @@ subtest 'Test limit parameter for SendQueuedMessages' => sub { my $dbh = C4::Context->dbh; - my $borrowernumber = AddMember( + my $borrowernumber = Koha::Patron->new({ firstname => 'Jane', surname => 'Smith', categorycode => $patron_category, branchcode => $library->{branchcode}, dateofbirth => $date, smsalertnumber => undef, - ); + })->store->borrowernumber; $dbh->do(q|DELETE FROM message_queue|); $my_message = { diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t index f405a46a69..650eed6510 100755 --- a/t/db_dependent/Members.t +++ b/t/db_dependent/Members.t @@ -94,8 +94,8 @@ my %data = ( userid => 'tomasito' ); -my $addmem=AddMember(%data); -ok($addmem, "AddMember()"); +my $addmem=Koha::Patron->new(\%data)->store->borrowernumber; +ok($addmem, "Koha::Patron->store()"); my $member = Koha::Patrons->find( { cardnumber => $CARDNUMBER } ) or BAIL_OUT("Cannot read member with card $CARDNUMBER"); @@ -151,12 +151,12 @@ is ($checkcardnum, "2", "Card number is too long"); dateexpiry => '', dateenrolled => '', ); -my $borrowernumber = AddMember( %data ); +my $borrowernumber = Koha::Patron->new( \%data )->store->borrowernumber; my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; -is( $borrower->{dateofbirth}, undef, 'AddMember should undef dateofbirth if empty string is given'); -is( $borrower->{debarred}, undef, 'AddMember should undef debarred if empty string is given'); -isnt( $borrower->{dateexpiry}, '0000-00-00', 'AddMember should not set dateexpiry to 0000-00-00 if empty string is given'); -isnt( $borrower->{dateenrolled}, '0000-00-00', 'AddMember should not set dateenrolled to 0000-00-00 if empty string is given'); +is( $borrower->{dateofbirth}, undef, 'Koha::Patron->store should undef dateofbirth if empty string is given'); +is( $borrower->{debarred}, undef, 'Koha::Patron->store should undef debarred if empty string is given'); +isnt( $borrower->{dateexpiry}, '0000-00-00', 'Koha::Patron->store should not set dateexpiry to 0000-00-00 if empty string is given'); +isnt( $borrower->{dateenrolled}, '0000-00-00', 'Koha::Patron->store should not set dateenrolled to 0000-00-00 if empty string is given'); ModMember( borrowernumber => $borrowernumber, dateofbirth => '', debarred => '', dateexpiry => '', dateenrolled => '' ); $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; @@ -177,7 +177,7 @@ subtest 'ModMember should not update userid if not true' => sub { $data{ cardnumber } = "234567890"; $data{userid} = 'a_user_id'; - $borrowernumber = AddMember( %data ); + $borrowernumber = Koha::Patron->new( \%data )->store->borrowernumber; $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => '' ); @@ -266,7 +266,7 @@ $builder->build({ # IndependentBranches is off. t::lib::Mocks::mock_preference('IndependentBranches', 0); -my $owner = AddMember (categorycode => 'STAFFER', branchcode => $library2->{branchcode} ); +my $owner = Koha::Patron->new({ categorycode => 'STAFFER', branchcode => $library2->{branchcode} })->store->borrowernumber; my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } ); my @listpatrons = ($bor1inlist, $bor2inlist); AddPatronsToList( { list => $list1, borrowernumbers => \@listpatrons }); @@ -341,11 +341,11 @@ isnt( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lasts ## Remove all entries with userid='' (should be only 1 max) $dbh->do(q|DELETE FROM borrowers WHERE userid = ''|); ## And create a patron with a userid='' -$borrowernumber = AddMember( categorycode => $patron_category->{categorycode}, branchcode => $library2->{branchcode} ); +$borrowernumber = Koha::Patron->new({ categorycode => $patron_category->{categorycode}, branchcode => $library2->{branchcode} })->store->borrowernumber; $dbh->do(q|UPDATE borrowers SET userid = '' WHERE borrowernumber = ?|, undef, $borrowernumber); # Create another patron and verify the userid has been generated -$borrowernumber = AddMember( categorycode => $patron_category->{categorycode}, branchcode => $library2->{branchcode} ); -ok( $borrowernumber > 0, 'AddMember should have inserted the patron even if no userid is given' ); +$borrowernumber = Koha::Patron->new({ categorycode => $patron_category->{categorycode}, branchcode => $library2->{branchcode} })->store->borrowernumber; +ok( $borrowernumber > 0, 'Koha::Patron->store should have inserted the patron even if no userid is given' ); $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; ok( $borrower->{userid}, 'A userid should have been generated correctly' ); @@ -399,7 +399,7 @@ subtest 'Trivial test for AddMember_Auto' => sub { $schema->storage->txn_rollback; -subtest 'AddMember (invalid categorycode) tests' => sub { +subtest 'Koha::Patron->store (invalid categorycode) tests' => sub { plan tests => 1; $schema->storage->txn_begin; @@ -414,7 +414,7 @@ subtest 'AddMember (invalid categorycode) tests' => sub { }; throws_ok - { AddMember( %{ $patron_data } ); } + { Koha::Patron->new( $patron_data )->store; } 'Koha::Exceptions::Object::FKConstraint', 'AddMember raises an exception on invalid categorycode'; diff --git a/t/db_dependent/Members/GetAllIssues.t b/t/db_dependent/Members/GetAllIssues.t index 643320169c..21701cb05c 100644 --- a/t/db_dependent/Members/GetAllIssues.t +++ b/t/db_dependent/Members/GetAllIssues.t @@ -64,9 +64,9 @@ my $itemnumber3 = AddItem( { barcode => '0203', %item_infos }, $biblionumber2 ); my $borrowernumber1 = - AddMember( categorycode => $categorycode, branchcode => $branchcode ); + Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber; my $borrowernumber2 = - AddMember( categorycode => $categorycode, branchcode => $branchcode ); + Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber; my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed; my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed; diff --git a/t/db_dependent/Members/IssueSlip.t b/t/db_dependent/Members/IssueSlip.t index bfab08c8af..cbf3a72cc0 100644 --- a/t/db_dependent/Members/IssueSlip.t +++ b/t/db_dependent/Members/IssueSlip.t @@ -119,7 +119,7 @@ my $itemnumber2 = AddItem( { barcode => $barcode2, %item_infos }, $biblionumber2 ); my $borrowernumber = - AddMember( categorycode => $categorycode, branchcode => $branchcode ); + Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber; my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $module = new Test::MockModule('C4::Context'); diff --git a/t/db_dependent/Patron/Borrower_Debarments.t b/t/db_dependent/Patron/Borrower_Debarments.t index ac59f1b34c..144de3479e 100755 --- a/t/db_dependent/Patron/Borrower_Debarments.t +++ b/t/db_dependent/Patron/Borrower_Debarments.t @@ -3,7 +3,6 @@ use Modern::Perl; use C4::Context; -use C4::Members; use Koha::Database; use Koha::Patrons; @@ -23,12 +22,12 @@ my $library = $builder->build({ }); my $patron_category = $builder->build({ source => 'Category' }); -my $borrowernumber = AddMember( +my $borrowernumber = Koha::Patron->new({ firstname => 'my firstname', surname => 'my surname', categorycode => $patron_category->{categorycode}, branchcode => $library->{branchcode}, -); +})->store->borrowernumber; my $success = AddDebarment({ borrowernumber => $borrowernumber, diff --git a/t/db_dependent/Patron/Borrower_Discharge.t b/t/db_dependent/Patron/Borrower_Discharge.t index cf08a88308..d43b49e464 100644 --- a/t/db_dependent/Patron/Borrower_Discharge.t +++ b/t/db_dependent/Patron/Borrower_Discharge.t @@ -23,8 +23,8 @@ use C4::Biblio qw( AddBiblio ); use C4::Circulation qw( AddIssue AddReturn ); use C4::Context; use C4::Items qw( AddItem ); -use C4::Members qw( AddMember ); +use Koha::Patrons; use Koha::Patron::Discharge; use Koha::Database; diff --git a/t/db_dependent/Patron/Borrower_Files.t b/t/db_dependent/Patron/Borrower_Files.t index da82a048cd..b0cfc74552 100644 --- a/t/db_dependent/Patron/Borrower_Files.t +++ b/t/db_dependent/Patron/Borrower_Files.t @@ -20,9 +20,9 @@ use Modern::Perl; use C4::Context; -use C4::Members; use Koha::Database; +use Koha::Patrons; use t::lib::TestBuilder; use Test::More tests => 23; @@ -43,12 +43,12 @@ my $library = $builder->build({ }); my $patron_category = $builder->build({ source => 'Category' }); -my $borrowernumber = AddMember( +my $borrowernumber = Koha::Patron->new({ firstname => 'my firstname', surname => 'my surname', categorycode => $patron_category->{categorycode}, branchcode => $library->{branchcode}, -); +})->store->borrowernumber; my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber, diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 4fae478dd3..af5f064865 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -52,7 +52,7 @@ my $dbh = C4::Context->dbh; my $builder = t::lib::TestBuilder->new; -my $frameworkcode = q||; +my $frameworkcode = q//; t::lib::Mocks::mock_preference('ReservesNeedReturns', 1); @@ -120,7 +120,7 @@ my %data = ( branchcode => $branch_1, ); Koha::Patron::Categories->find($category_1)->set({ enrolmentfee => 0})->store; -my $borrowernumber = AddMember(%data); +my $borrowernumber = Koha::Patron->new(\%data)->store->borrowernumber; my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; my $biblionumber = $bibnum; my $barcode = $testbarcode; @@ -172,28 +172,28 @@ t::lib::Mocks::mock_preference( 'ReservesControlBranch', $ReservesControlBranch ### Regression test for bug 10272 ### my %requesters = (); -$requesters{$branch_1} = AddMember( +$requesters{$branch_1} = Koha::Patron->new({ branchcode => $branch_1, categorycode => $category_2, surname => "borrower from $branch_1", -); +})->store->borrowernumber; for my $i ( 2 .. 5 ) { - $requesters{"CPL$i"} = AddMember( + $requesters{"CPL$i"} = Koha::Patron->new({ branchcode => $branch_1, categorycode => $category_2, surname => "borrower $i from $branch_1", - ); + })->store->borrowernumber; } -$requesters{$branch_2} = AddMember( +$requesters{$branch_2} = Koha::Patron->new({ branchcode => $branch_2, categorycode => $category_2, surname => "borrower from $branch_2", -); -$requesters{$branch_3} = AddMember( +})->store->borrowernumber; +$requesters{$branch_3} = Koha::Patron->new({ branchcode => $branch_3, categorycode => $category_2, surname => "borrower from $branch_3", -); +})->store->borrowernumber; # Configure rules so that $branch_1 allows only $branch_1 patrons # to request its items, while $branch_2 will allow its items diff --git a/t/db_dependent/Serials_2.t b/t/db_dependent/Serials_2.t index b326ae6aab..95c36f7d8e 100644 --- a/t/db_dependent/Serials_2.t +++ b/t/db_dependent/Serials_2.t @@ -6,8 +6,8 @@ use Test::More tests => 50; use MARC::Record; use C4::Biblio qw( AddBiblio ); -use C4::Members qw( AddMember ); use Koha::Database; +use Koha::Patrons; use t::lib::Mocks; use t::lib::TestBuilder; use_ok('C4::Serials'); @@ -79,13 +79,13 @@ is( C4::Serials::can_edit_subscription($subscription_from_my_branch), 0, "cannot is( C4::Serials::can_claim_subscription($subscription_from_my_branch), 0, "cannot edit a subscription without userenv set"); my $userid = 'my_userid'; -my $borrowernumber = C4::Members::AddMember( +my $borrowernumber = Koha::Patron->new({ firstname => 'my fistname', surname => 'my surname', categorycode => $patron_category->{categorycode}, branchcode => $my_branch, userid => $userid, -); +})->store->borrowernumber; $userenv = { flags => 1, id => $borrowernumber, branch => '' }; diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t index 6604cd10f0..2d2bfb565c 100644 --- a/t/db_dependent/Suggestions.t +++ b/t/db_dependent/Suggestions.t @@ -25,13 +25,12 @@ use t::lib::Mocks; use t::lib::TestBuilder; use C4::Context; -use C4::Members; use C4::Letters; use C4::Budgets qw( AddBudgetPeriod AddBudget ); use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); -use Koha::Library; use Koha::Libraries; +use Koha::Patrons; use Koha::Suggestions; BEGIN { @@ -76,7 +75,7 @@ my $member = { categorycode => $patron_category->{categorycode}, branchcode => 'CPL', }; -my $borrowernumber = AddMember(%$member); +my $borrowernumber = Koha::Patron->new($member)->store->borrowernumber; my $biblionumber1 = 1; my $my_suggestion = { diff --git a/t/db_dependent/Utils/Datatables_Virtualshelves.t b/t/db_dependent/Utils/Datatables_Virtualshelves.t index 2b97b6a361..564a08ddc4 100644 --- a/t/db_dependent/Utils/Datatables_Virtualshelves.t +++ b/t/db_dependent/Utils/Datatables_Virtualshelves.t @@ -21,11 +21,10 @@ use Test::More tests => 13; use C4::Biblio; use C4::Context; -use C4::Members; use Koha::Library; +use Koha::Patrons; use Koha::Patron::Categories; -use Koha::Virtualshelf; use Koha::Virtualshelves; use_ok( "C4::Utils::DataTables::VirtualShelves" ); @@ -80,9 +79,9 @@ my %john_smith = ( userid => 'john.smith', ); -$john_doe{borrowernumber} = AddMember( %john_doe ); -$jane_doe{borrowernumber} = AddMember( %jane_doe ); -$john_smith{borrowernumber} = AddMember( %john_smith ); +$john_doe{borrowernumber} = Koha::Patron->new( \%john_doe )->store->borrowernumber; +$jane_doe{borrowernumber} = Koha::Patron->new( \%jane_doe )->store->borrowernumber; +$john_smith{borrowernumber} = Koha::Patron->new( \%john_smith )->store->borrowernumber; my $shelf1 = Koha::Virtualshelf->new( { -- 2.39.5