Browse Source

Bug 20287: Replace occurrences of AddMember with Koha::Patron->new->store->borrowernumber

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

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

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
18.11.x
Jonathan Druart 5 years ago
committed by Nick Clemens
parent
commit
ef410fd62f
  1. 1
      C4/Auth_with_ldap.pm
  2. 14
      C4/Members.pm
  3. 2
      Koha/NorwegianPatronDB.pm
  4. 25
      Koha/Patrons/Import.pm
  5. 10
      installer/onboarding.pl
  6. 12
      members/memberentry.pl
  7. 9
      members/nl-search.pl
  8. 6
      misc/devel/create_superlibrarian.pl
  9. 8
      opac/svc/auth/googleopenidconnect
  10. 5
      t/db_dependent/Acquisition/OrderUsers.t
  11. 10
      t/db_dependent/Budgets.t
  12. 33
      t/db_dependent/Circulation.t
  13. 7
      t/db_dependent/Circulation/Branch.t
  14. 5
      t/db_dependent/Circulation/Chargelostitem.t
  15. 6
      t/db_dependent/Circulation/CheckIfIssuedToPatron.t
  16. 5
      t/db_dependent/Circulation/GetTopIssues.t
  17. 5
      t/db_dependent/Circulation/IsItemIssued.t
  18. 6
      t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t
  19. 4
      t/db_dependent/Circulation/MarkIssueReturned.t
  20. 9
      t/db_dependent/Circulation/issue.t
  21. 5
      t/db_dependent/Holds.t
  22. 6
      t/db_dependent/Holds/LocalHoldsPriority.t
  23. 5
      t/db_dependent/Holds/RevertWaitingStatus.t
  24. 5
      t/db_dependent/Koha/Object.t
  25. 16
      t/db_dependent/Koha/Patrons.t
  26. 15
      t/db_dependent/Letters.t
  27. 28
      t/db_dependent/Members.t
  28. 4
      t/db_dependent/Members/GetAllIssues.t
  29. 2
      t/db_dependent/Members/IssueSlip.t
  30. 5
      t/db_dependent/Patron/Borrower_Debarments.t
  31. 2
      t/db_dependent/Patron/Borrower_Discharge.t
  32. 6
      t/db_dependent/Patron/Borrower_Files.t
  33. 20
      t/db_dependent/Reserves.t
  34. 6
      t/db_dependent/Serials_2.t
  35. 5
      t/db_dependent/Suggestions.t
  36. 9
      t/db_dependent/Utils/Datatables_Virtualshelves.t

1
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;

14
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

2
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

25
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',
}
);
}

10
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 {

12
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'}) {

9
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,

6
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

8
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.';
}

5
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 );

10
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},

33
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,

7
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(),

5
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

6
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;

5
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');

5
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();

6
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();

4
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<Fatal error: the patron \(\d+\) .* AnonymousPatron>, '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 ) };

9
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 = (

5
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;
}

6
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;
}

5
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;
}

5
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(

16
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" );

15
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 = {

28
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';

4
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;

2
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');

5
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,

2
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;

6
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,

20
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

6
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 => '' };

5
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 = {

9
t/db_dependent/Utils/Datatables_Virtualshelves.t