Bug 20287: Move ModMember to Koha::Patron
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>
This commit is contained in:
parent
cfbc53bb22
commit
d2a2d973ce
108
C4/Members.pm
108
C4/Members.pm
|
|
@ -72,7 +72,6 @@ BEGIN {
|
|||
|
||||
#Modify data
|
||||
push @EXPORT, qw(
|
||||
&ModMember
|
||||
&changepassword
|
||||
);
|
||||
|
||||
|
|
@ -261,113 +260,6 @@ sub patronflags {
|
|||
return ( \%flags );
|
||||
}
|
||||
|
||||
|
||||
=head2 ModMember
|
||||
|
||||
my $success = ModMember(borrowernumber => $borrowernumber,
|
||||
[ field => value ]... );
|
||||
|
||||
Modify borrower's data. All date fields should ALREADY be in ISO format.
|
||||
|
||||
return :
|
||||
true on success, or false on failure
|
||||
|
||||
=cut
|
||||
|
||||
sub ModMember {
|
||||
my (%data) = @_;
|
||||
|
||||
# trim whitespace from data which has some non-whitespace in it.
|
||||
foreach my $field_name (keys(%data)) {
|
||||
if ( defined $data{$field_name} && $data{$field_name} =~ /\S/ ) {
|
||||
$data{$field_name} =~ s/^\s*|\s*$//g;
|
||||
}
|
||||
}
|
||||
|
||||
# test to know if you must update or not the borrower password
|
||||
if (exists $data{password}) {
|
||||
if ($data{password} eq '****' or $data{password} eq '') {
|
||||
delete $data{password};
|
||||
} else {
|
||||
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
|
||||
# Update the hashed PIN in borrower_sync.hashed_pin, before Koha hashes it
|
||||
Koha::NorwegianPatronDB::NLUpdateHashedPIN( $data{'borrowernumber'}, $data{password} );
|
||||
}
|
||||
$data{password} = hash_password($data{password});
|
||||
}
|
||||
}
|
||||
|
||||
my $old_categorycode = Koha::Patrons->find( $data{borrowernumber} )->categorycode;
|
||||
|
||||
# get only the columns of a borrower
|
||||
my $schema = Koha::Database->new()->schema;
|
||||
my @columns = $schema->source('Borrower')->columns;
|
||||
my $new_borrower = { map { join(' ', @columns) =~ /$_/ ? ( $_ => $data{$_} ) : () } keys(%data) };
|
||||
|
||||
$new_borrower->{dateofbirth} ||= undef if exists $new_borrower->{dateofbirth};
|
||||
$new_borrower->{dateenrolled} ||= undef if exists $new_borrower->{dateenrolled};
|
||||
$new_borrower->{dateexpiry} ||= undef if exists $new_borrower->{dateexpiry};
|
||||
$new_borrower->{debarred} ||= undef if exists $new_borrower->{debarred};
|
||||
$new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
|
||||
$new_borrower->{guarantorid} ||= undef if exists $new_borrower->{guarantorid};
|
||||
|
||||
my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
|
||||
|
||||
my $borrowers_log = C4::Context->preference("BorrowersLog");
|
||||
if ( $borrowers_log && $patron->cardnumber ne $new_borrower->{cardnumber} )
|
||||
{
|
||||
logaction(
|
||||
"MEMBERS",
|
||||
"MODIFY",
|
||||
$data{'borrowernumber'},
|
||||
to_json(
|
||||
{
|
||||
cardnumber_replaced => {
|
||||
previous_cardnumber => $patron->cardnumber,
|
||||
new_cardnumber => $new_borrower->{cardnumber},
|
||||
}
|
||||
},
|
||||
{ utf8 => 1, pretty => 1 }
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid};
|
||||
|
||||
my $execute_success = $patron->store if $patron->set($new_borrower);
|
||||
|
||||
if ($execute_success) { # only proceed if the update was a success
|
||||
# If the patron changes to a category with enrollment fee, we add a fee
|
||||
if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
|
||||
if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
|
||||
$patron->add_enrolment_fee_if_needed;
|
||||
}
|
||||
}
|
||||
|
||||
# If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a
|
||||
# cronjob will use for syncing with NL
|
||||
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
|
||||
my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({
|
||||
'synctype' => 'norwegianpatrondb',
|
||||
'borrowernumber' => $data{'borrowernumber'}
|
||||
});
|
||||
# Do not set to "edited" if syncstatus is "new". We need to sync as new before
|
||||
# we can sync as changed. And the "new sync" will pick up all changes since
|
||||
# the patron was created anyway.
|
||||
if ( $borrowersync->syncstatus ne 'new' && $borrowersync->syncstatus ne 'delete' ) {
|
||||
$borrowersync->update( { 'syncstatus' => 'edited' } );
|
||||
}
|
||||
# Set the value of 'sync'
|
||||
$borrowersync->update( { 'sync' => $data{'sync'} } );
|
||||
# Try to do the live sync
|
||||
Koha::NorwegianPatronDB::NLSync({ 'borrowernumber' => $data{'borrowernumber'} });
|
||||
}
|
||||
|
||||
logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if $borrowers_log;
|
||||
}
|
||||
return $execute_success;
|
||||
}
|
||||
|
||||
=head2 GetAllIssues
|
||||
|
||||
$issues = &GetAllIssues($borrowernumber, $sortkey, $limit);
|
||||
|
|
|
|||
110
Koha/Patron.pm
110
Koha/Patron.pm
|
|
@ -22,6 +22,7 @@ use Modern::Perl;
|
|||
|
||||
use Carp;
|
||||
use List::MoreUtils qw( uniq );
|
||||
use JSON qw( to_json );
|
||||
use Module::Load::Conditional qw( can_load );
|
||||
use Text::Unaccent qw( unac_string );
|
||||
|
||||
|
|
@ -155,17 +156,26 @@ sub store {
|
|||
# We are in a transaction but the table is not locked
|
||||
$self->fixup_cardnumber;
|
||||
}
|
||||
|
||||
unless( $self->category->in_storage ) {
|
||||
Koha::Exceptions::Object::FKConstraint->throw(
|
||||
broken_fk => 'categorycode',
|
||||
value => $self->categorycode,
|
||||
);
|
||||
}
|
||||
|
||||
$self->trim_whitespaces;
|
||||
|
||||
# We don't want invalid dates in the db (mysql has a bad habit of inserting 0000-00-00)
|
||||
$self->dateofbirth(undef) unless $self->dateofbirth;
|
||||
$self->debarred(undef) unless $self->debarred;
|
||||
|
||||
# Set default values if not set
|
||||
$self->sms_provider_id(undef) unless $self->sms_provider_id;
|
||||
$self->guarantorid(undef) unless $self->guarantorid;
|
||||
|
||||
unless ( $self->in_storage ) { #AddMember
|
||||
|
||||
unless( $self->category->in_storage ) {
|
||||
Koha::Exceptions::Object::FKConstraint->throw(
|
||||
broken_fk => 'categorycode',
|
||||
value => $self->categorycode,
|
||||
);
|
||||
}
|
||||
|
||||
$self->trim_whitespaces;
|
||||
|
||||
# Generate a valid userid/login if needed
|
||||
$self->userid($self->generate_userid)
|
||||
if not $self->userid or not $self->has_valid_userid;
|
||||
|
|
@ -201,14 +211,6 @@ sub store {
|
|||
? Koha::AuthUtils::hash_password( $self->password )
|
||||
: '!' );
|
||||
|
||||
# We don't want invalid dates in the db (mysql has a bad habit of inserting 0000-00-00)
|
||||
$self->dateofbirth(undef) unless $self->dateofbirth;
|
||||
$self->debarred(undef) unless $self->debarred;
|
||||
|
||||
# Set default values if not set
|
||||
$self->sms_provider_id(undef) unless $self->sms_provider_id;
|
||||
$self->guarantorid(undef) unless $self->guarantorid;
|
||||
|
||||
$self->borrowernumber(undef);
|
||||
|
||||
$self = $self->SUPER::store;
|
||||
|
|
@ -237,9 +239,78 @@ sub store {
|
|||
if C4::Context->preference("BorrowersLog");
|
||||
}
|
||||
else { #ModMember
|
||||
# test to know if you must update or not the borrower password
|
||||
if ( defined $self->password ) {
|
||||
if ( $self->password eq '****' or $self->password eq '' ) {
|
||||
$self->password(undef);
|
||||
} else {
|
||||
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
|
||||
# Update the hashed PIN in borrower_sync.hashed_pin, before Koha hashes it
|
||||
Koha::NorwegianPatronDB::NLUpdateHashedPIN( $self->borrowernumber, $self->password );
|
||||
}
|
||||
$self->password(Koha::AuthUtils::hash_password($self->password));
|
||||
}
|
||||
}
|
||||
|
||||
# Come from ModMember, but should not be possible (?)
|
||||
$self->dateenrolled(undef) unless $self->dateenrolled;
|
||||
$self->dateexpiry(undef) unless $self->dateexpiry;
|
||||
|
||||
if ( C4::Context->preference('FeeOnChangePatronCategory')
|
||||
and $self->category->categorycode ne
|
||||
$self->get_from_storage->category->categorycode )
|
||||
{
|
||||
$self->add_enrolment_fee_if_needed;
|
||||
}
|
||||
|
||||
# If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a
|
||||
# cronjob will use for syncing with NL
|
||||
if ( C4::Context->preference('NorwegianPatronDBEnable')
|
||||
&& C4::Context->preference('NorwegianPatronDBEnable') == 1 )
|
||||
{
|
||||
my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({
|
||||
'synctype' => 'norwegianpatrondb',
|
||||
'borrowernumber' => $self->borrowernumber,
|
||||
});
|
||||
# Do not set to "edited" if syncstatus is "new". We need to sync as new before
|
||||
# we can sync as changed. And the "new sync" will pick up all changes since
|
||||
# the patron was created anyway.
|
||||
if ( $borrowersync->syncstatus ne 'new' && $borrowersync->syncstatus ne 'delete' ) {
|
||||
$borrowersync->update( { 'syncstatus' => 'edited' } );
|
||||
}
|
||||
# Set the value of 'sync'
|
||||
# FIXME THIS IS BROKEN # $borrowersync->update( { 'sync' => $data{'sync'} } );
|
||||
|
||||
# Try to do the live sync
|
||||
Koha::NorwegianPatronDB::NLSync({ 'borrowernumber' => $self->borrowernumber });
|
||||
}
|
||||
|
||||
my $borrowers_log = C4::Context->preference("BorrowersLog");
|
||||
my $previous_cardnumber = $self->get_from_storage->cardnumber;
|
||||
if ( $borrowers_log && $previous_cardnumber ne $self->cardnumber )
|
||||
{
|
||||
logaction(
|
||||
"MEMBERS",
|
||||
"MODIFY",
|
||||
$self->borrowernumber,
|
||||
to_json(
|
||||
{
|
||||
cardnumber_replaced => {
|
||||
previous_cardnumber => $previous_cardnumber,
|
||||
new_cardnumber => $self->cardnumber,
|
||||
}
|
||||
},
|
||||
{ utf8 => 1, pretty => 1 }
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
logaction( "MEMBERS", "MODIFY", $self->borrowernumber,
|
||||
"UPDATE (executed w/ arg: " . $self->borrowernumber . ")" )
|
||||
if $borrowers_log;
|
||||
|
||||
$self = $self->SUPER::store;
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
return $self;
|
||||
|
|
@ -1162,8 +1233,7 @@ Generate a userid using the $surname and the $firstname (if there is a value in
|
|||
|
||||
Return the generate userid ($firstname.$surname if there is a $firstname, or $surname if there is no value in $firstname) plus offset (0 if the $userid is unique, or a higher numeric value if not unique).
|
||||
|
||||
# Note: Should we set $self->userid with the generated value?
|
||||
# Certainly yes, but we AddMember and ModMember will be rewritten
|
||||
# TODO: Set $self->userid with the generated value
|
||||
|
||||
=cut
|
||||
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' )
|
|||
}
|
||||
}
|
||||
|
||||
# remove keys from %newdata that ModMember() doesn't like
|
||||
# remove keys from %newdata that is not part of patron's attributes
|
||||
{
|
||||
my @keys_to_delete = (
|
||||
qr/^BorrowerMandatoryField$/,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use CGI qw ( -utf8 );
|
|||
use C4::Auth;
|
||||
use C4::Output;
|
||||
use C4::Context;
|
||||
use C4::Members;
|
||||
use Koha::Patrons;
|
||||
use Koha::Patron::Modifications;
|
||||
|
||||
my $query = new CGI;
|
||||
|
|
@ -57,10 +57,9 @@ foreach my $param (@params) {
|
|||
|
||||
if ($query->param("unset_gna_$borrowernumber")) {
|
||||
# Unset gone no address
|
||||
ModMember(
|
||||
borrowernumber => $borrowernumber,
|
||||
gonenoaddress => undef
|
||||
);
|
||||
# FIXME Looks like this could go to $m->approve
|
||||
my $patron = Koha::Patrons->find( $borrowernumber );
|
||||
$patron->gonenoaddress(undef)->store;
|
||||
}
|
||||
|
||||
$m->approve() if $m;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
script to update a child member to (usually) an adult member category
|
||||
|
||||
- if called with op=multi, will return all available non child categories, for selection.
|
||||
- if called with op=update, script will update member record via ModMember().
|
||||
- if called with op=update, script will update member record via Koha::Patron->store.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -31,7 +31,6 @@ use CGI qw ( -utf8 );
|
|||
use C4::Context;
|
||||
use C4::Auth;
|
||||
use C4::Output;
|
||||
use C4::Members;
|
||||
use Koha::Patrons;
|
||||
use Koha::Patron::Categories;
|
||||
|
||||
|
|
@ -76,14 +75,9 @@ elsif ( $op eq 'update' ) {
|
|||
my $patron = Koha::Patrons->find( $borrowernumber );
|
||||
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
|
||||
|
||||
my $member = $patron->unblessed;
|
||||
$member->{'guarantorid'} = 0;
|
||||
$member->{'categorycode'} = $catcode;
|
||||
my $borcat = Koha::Patron::Categories->find($catcode);
|
||||
$member->{'category_type'} = $borcat->category_type;
|
||||
$member->{'description'} = $borcat->description;
|
||||
delete $member->{password};
|
||||
ModMember(%$member);
|
||||
$patron->guarantorid(undef);
|
||||
$patron->categorycode($catcode);
|
||||
$patron->store;
|
||||
|
||||
if ( $catcode_multi ) {
|
||||
$template->param(
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ nl-sync-to-koha.pl - Sync patrons from the Norwegian national patron database (N
|
|||
|
||||
=cut
|
||||
|
||||
use C4::Members;
|
||||
use C4::Members::Attributes qw( UpdateBorrowerAttribute );
|
||||
use Koha::NorwegianPatronDB qw( NLCheckSysprefs NLGetChanged );
|
||||
use Koha::Patrons;
|
||||
use Koha::Database;
|
||||
use Getopt::Long;
|
||||
use Pod::Usage;
|
||||
|
|
@ -70,17 +70,11 @@ foreach my $patron ( @{ $result->{'kohapatrons'} } ) {
|
|||
# Delete the extra data from the copy of the hashref
|
||||
delete $clean_patron{'_extra'};
|
||||
# Find the borrowernumber based on cardnumber
|
||||
my $stored_patron = Koha::Database->new->schema->resultset('Borrower')->find({
|
||||
'cardnumber' => $patron->{'cardnumber'}
|
||||
});
|
||||
my $stored_patron = Koha::Patrons->find({ cardnumber => $patron->{cardnumber} });
|
||||
my $borrowernumber = $stored_patron->borrowernumber;
|
||||
if ( $run ) {
|
||||
# Call ModMember
|
||||
my $success = ModMember(
|
||||
'borrowernumber' => $borrowernumber,
|
||||
%clean_patron,
|
||||
);
|
||||
if ( $success ) {
|
||||
# FIXME Exceptions must be caught here
|
||||
if ( $stored_patron->set(\%clean_patron)->store ) {
|
||||
# Get the sync object
|
||||
my $sync = Koha::Database->new->schema->resultset('BorrowerSync')->find({
|
||||
'synctype' => 'norwegianpatrondb',
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ use C4::Output;
|
|||
use C4::Members;
|
||||
use C4::Members::Messaging;
|
||||
use C4::Form::MessagingPreferences;
|
||||
use Koha::Patrons;
|
||||
use Koha::SMS::Providers;
|
||||
|
||||
my $query = CGI->new();
|
||||
|
|
@ -50,37 +51,35 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
|
|||
}
|
||||
);
|
||||
|
||||
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
|
||||
my $patron = Koha::Patrons->find( $borrowernumber ); # FIXME and if borrowernumber is invalid?
|
||||
|
||||
my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
|
||||
|
||||
if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
|
||||
my $sms = $query->param('SMSnumber');
|
||||
my $sms_provider_id = $query->param('sms_provider_id');
|
||||
if ( defined $sms && ( $borrower->{'smsalertnumber'} // '' ) ne $sms
|
||||
or ( $borrower->{sms_provider_id} // '' ) ne $sms_provider_id ) {
|
||||
ModMember(
|
||||
borrowernumber => $borrowernumber,
|
||||
if ( defined $sms && ( $patron->smsalertnumber // '' ) ne $sms
|
||||
or ( $patron->sms_provider_id // '' ) ne $sms_provider_id ) {
|
||||
$patron->set({
|
||||
smsalertnumber => $sms,
|
||||
sms_provider_id => $sms_provider_id,
|
||||
);
|
||||
# FIXME will not be needed when ModMember will be replaced
|
||||
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
|
||||
})->store;
|
||||
}
|
||||
|
||||
C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $borrowernumber }, $template);
|
||||
C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $patron->borrowernumber }, $template);
|
||||
}
|
||||
|
||||
C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrower->{'borrowernumber'} }, $template);
|
||||
C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $patron->borrowernumber }, $template);
|
||||
|
||||
$template->param( BORROWER_INFO => $borrower,
|
||||
$template->param( BORROWER_INFO => $patron->unblessed,
|
||||
messagingview => 1,
|
||||
SMSnumber => $borrower->{'smsalertnumber'},
|
||||
SMSnumber => $patron->smsalertnumber, # FIXME This is already sent 2 lines above
|
||||
SMSSendDriver => C4::Context->preference("SMSSendDriver"),
|
||||
TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification") );
|
||||
|
||||
if ( C4::Context->preference("SMSSendDriver") eq 'Email' ) {
|
||||
my @providers = Koha::SMS::Providers->search();
|
||||
$template->param( sms_providers => \@providers, sms_provider_id => $borrower->{'sms_provider_id'} );
|
||||
$template->param( sms_providers => \@providers, sms_provider_id => $patron->sms_provider_id );
|
||||
}
|
||||
|
||||
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ use CGI qw ( -utf8 );
|
|||
|
||||
use C4::Auth; # checkauth, getborrowernumber.
|
||||
use C4::Context;
|
||||
use C4::Members;
|
||||
use C4::Output;
|
||||
use Koha::Patrons;
|
||||
|
||||
|
|
@ -50,12 +49,14 @@ my $privacy = $query->param("privacy");
|
|||
my $privacy_guarantor_checkouts = $query->param("privacy_guarantor_checkouts");
|
||||
|
||||
if ( $op eq "update_privacy" ) {
|
||||
ModMember(
|
||||
borrowernumber => $borrowernumber,
|
||||
privacy => $privacy,
|
||||
privacy_guarantor_checkouts => $privacy_guarantor_checkouts,
|
||||
);
|
||||
$template->param( 'privacy_updated' => 1 );
|
||||
my $patron = Koha::Patrons->find( $borrowernumber );
|
||||
if ( $patron ) {
|
||||
$patron->set({
|
||||
privacy => $privacy,
|
||||
privacy_guarantor_checkouts => $privacy_guarantor_checkouts,
|
||||
})->store;
|
||||
$template->param( 'privacy_updated' => 1 );
|
||||
}
|
||||
}
|
||||
elsif ( $op eq "delete_record" ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -402,16 +402,16 @@ subtest 'add_enrolment_fee_if_needed' => sub {
|
|||
|
||||
t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
|
||||
$borrower_data{categorycode} = 'J';
|
||||
C4::Members::ModMember(%borrower_data);
|
||||
$patron->set(\%borrower_data)->store;
|
||||
$total = $patron->account->balance;
|
||||
is( int($total), int($enrolmentfee_K), "Kid growing and become a juvenile, but shouldn't pay for the upgrade " );
|
||||
|
||||
$borrower_data{categorycode} = 'K';
|
||||
C4::Members::ModMember(%borrower_data);
|
||||
$patron->set(\%borrower_data)->store;
|
||||
t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 1 );
|
||||
|
||||
$borrower_data{categorycode} = 'J';
|
||||
C4::Members::ModMember(%borrower_data);
|
||||
$patron->set(\%borrower_data)->store;
|
||||
$total = $patron->account->balance;
|
||||
is( int($total), int($enrolmentfee_K + $enrolmentfee_J), "Kid growing and become a juvenile, they should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
|
||||
|
||||
|
|
@ -1362,13 +1362,13 @@ subtest 'Log cardnumber change' => sub {
|
|||
plan tests => 3;
|
||||
|
||||
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 );
|
||||
my $patron = $builder->build( { source => 'Borrower' } );
|
||||
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
|
||||
|
||||
my $cardnumber = $patron->{cardnumber};
|
||||
$patron->{cardnumber} = 'TESTCARDNUMBER';
|
||||
ModMember(%$patron);
|
||||
my $cardnumber = $patron->cardnumber;
|
||||
$patron->set( { cardnumber => 'TESTCARDNUMBER' });
|
||||
$patron->store;
|
||||
|
||||
my @logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->{borrowernumber} } );
|
||||
my @logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } );
|
||||
my $log_info = from_json( $logs[0]->info );
|
||||
is( $log_info->{cardnumber_replaced}->{new_cardnumber}, 'TESTCARDNUMBER', 'Got correct new cardnumber' );
|
||||
is( $log_info->{cardnumber_replaced}->{previous_cardnumber}, $cardnumber, 'Got correct old cardnumber' );
|
||||
|
|
|
|||
|
|
@ -610,7 +610,7 @@ subtest 'SendQueuedMessages' => sub {
|
|||
is( $@, '', 'SendQueuedMessages should not explode if the patron does not have a sms provider set' );
|
||||
|
||||
my $sms_pro = $builder->build_object({ class => 'Koha::SMS::Providers', value => { domain => 'kidclamp.rocks' } });
|
||||
ModMember( borrowernumber => $borrowernumber, smsalertnumber => '5555555555', sms_provider_id => $sms_pro->id() );
|
||||
$patron->set( { smsalertnumber => '5555555555', sms_provider_id => $sms_pro->id() } )->store;
|
||||
$message_id = C4::Letters::EnqueueLetter($my_message); #using datas set around line 95 and forward
|
||||
C4::Letters::SendQueuedMessages();
|
||||
my $sms_message_address = $schema->resultset('MessageQueue')->search({
|
||||
|
|
|
|||
|
|
@ -97,9 +97,9 @@ my %data = (
|
|||
my $addmem=Koha::Patron->new(\%data)->store->borrowernumber;
|
||||
ok($addmem, "Koha::Patron->store()");
|
||||
|
||||
my $member = Koha::Patrons->find( { cardnumber => $CARDNUMBER } )
|
||||
my $patron = Koha::Patrons->find( { cardnumber => $CARDNUMBER } )
|
||||
or BAIL_OUT("Cannot read member with card $CARDNUMBER");
|
||||
$member = $member->unblessed;
|
||||
my $member = $patron->unblessed;
|
||||
|
||||
ok ( $member->{firstname} eq $FIRSTNAME &&
|
||||
$member->{surname} eq $SURNAME &&
|
||||
|
|
@ -114,7 +114,7 @@ $member->{firstname} = $CHANGED_FIRSTNAME . q{ };
|
|||
$member->{email} = $EMAIL;
|
||||
$member->{phone} = $PHONE;
|
||||
$member->{emailpro} = $EMAILPRO;
|
||||
ModMember(%$member);
|
||||
$patron->set($member)->store;
|
||||
my $changedmember = Koha::Patrons->find( { cardnumber => $CARDNUMBER } )->unblessed;
|
||||
ok ( $changedmember->{firstname} eq $CHANGED_FIRSTNAME &&
|
||||
$changedmember->{email} eq $EMAIL &&
|
||||
|
|
@ -152,43 +152,45 @@ is ($checkcardnum, "2", "Card number is too long");
|
|||
dateenrolled => '',
|
||||
);
|
||||
my $borrowernumber = Koha::Patron->new( \%data )->store->borrowernumber;
|
||||
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
|
||||
$patron = Koha::Patrons->find( $borrowernumber );
|
||||
my $borrower = $patron->unblessed;
|
||||
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 => '' );
|
||||
$patron->set({ dateofbirth => '', debarred => '', dateexpiry => '', dateenrolled => '' })->store;
|
||||
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
|
||||
is( $borrower->{dateofbirth}, undef, 'ModMember should undef dateofbirth if empty string is given');
|
||||
is( $borrower->{debarred}, undef, 'ModMember should undef debarred if empty string is given');
|
||||
isnt( $borrower->{dateexpiry}, '0000-00-00', 'ModMember should not set dateexpiry to 0000-00-00 if empty string is given');
|
||||
isnt( $borrower->{dateenrolled}, '0000-00-00', 'ModMember 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 => '1970-01-01', debarred => '2042-01-01', dateexpiry => '9999-12-31', dateenrolled => '2015-09-06' );
|
||||
$patron->set({ dateofbirth => '1970-01-01', debarred => '2042-01-01', dateexpiry => '9999-12-31', dateenrolled => '2015-09-06' })->store;
|
||||
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
|
||||
is( $borrower->{dateofbirth}, '1970-01-01', 'ModMember should correctly set dateofbirth if a valid date is given');
|
||||
is( $borrower->{debarred}, '2042-01-01', 'ModMember should correctly set debarred if a valid date is given');
|
||||
is( $borrower->{dateexpiry}, '9999-12-31', 'ModMember should correctly set dateexpiry if a valid date is given');
|
||||
is( $borrower->{dateenrolled}, '2015-09-06', 'ModMember should correctly set dateenrolled if a valid date is given');
|
||||
is( $borrower->{dateofbirth}, '1970-01-01', 'Koha::Patron->store should correctly set dateofbirth if a valid date is given');
|
||||
is( $borrower->{debarred}, '2042-01-01', 'Koha::Patron->store should correctly set debarred if a valid date is given');
|
||||
is( $borrower->{dateexpiry}, '9999-12-31', 'Koha::Patron->store should correctly set dateexpiry if a valid date is given');
|
||||
is( $borrower->{dateenrolled}, '2015-09-06', 'Koha::Patron->store should correctly set dateenrolled if a valid date is given');
|
||||
|
||||
subtest 'ModMember should not update userid if not true' => sub {
|
||||
subtest 'Koha::Patron->store should not update userid if not true' => sub {
|
||||
plan tests => 3;
|
||||
|
||||
$data{ cardnumber } = "234567890";
|
||||
$data{userid} = 'a_user_id';
|
||||
$borrowernumber = Koha::Patron->new( \%data )->store->borrowernumber;
|
||||
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
|
||||
my $patron = Koha::Patrons->find( $borrowernumber );
|
||||
my $borrower = $patron->unblessed;
|
||||
|
||||
ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => '' );
|
||||
$patron->set( { firstname => 'Tomas', userid => '' } )->store;
|
||||
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
|
||||
is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an empty string' );
|
||||
ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => 0 );
|
||||
is ( $borrower->{userid}, $data{userid}, 'Koha::Patron->store should not update the userid with an empty string' );
|
||||
$patron->set( { firstname => 'Tomas', userid => 0 } )->store;
|
||||
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
|
||||
is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an 0');
|
||||
ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => undef );
|
||||
is ( $borrower->{userid}, $data{userid}, 'Koha::Patron->store should not update the userid with an 0');
|
||||
$patron->set( { firstname => 'Tomas', userid => undef } )->store;
|
||||
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
|
||||
is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an undefined value');
|
||||
is ( $borrower->{userid}, $data{userid}, 'Koha::Patron->store should not update the userid with an undefined value');
|
||||
};
|
||||
|
||||
#Regression tests for bug 10612
|
||||
|
|
@ -272,7 +274,7 @@ my @listpatrons = ($bor1inlist, $bor2inlist);
|
|||
AddPatronsToList( { list => $list1, borrowernumbers => \@listpatrons });
|
||||
my $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id() } );
|
||||
is( scalar(@$patstodel),0,'No staff deleted from list of all staff');
|
||||
ModMember( borrowernumber => $bor2inlist, categorycode => 'CIVILIAN' );
|
||||
Koha::Patrons->find($bor2inlist)->set({ categorycode => 'CIVILIAN' })->store;
|
||||
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
|
||||
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted from list');
|
||||
$patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patron_list_id => $list1->patron_list_id() } );
|
||||
|
|
@ -282,8 +284,8 @@ ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inli
|
|||
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
|
||||
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by last issue date');
|
||||
|
||||
ModMember( borrowernumber => $bor1inlist, categorycode => 'CIVILIAN' );
|
||||
ModMember( borrowernumber => $guarantee->{borrowernumber} ,guarantorid=>$bor1inlist );
|
||||
Koha::Patrons->find($bor1inlist)->set({ categorycode => 'CIVILIAN' })->store;
|
||||
Koha::Patrons->find($guarantee->{borrowernumber})->set({ guarantorid => $bor1inlist })->store;
|
||||
|
||||
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
|
||||
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted from list');
|
||||
|
|
@ -293,7 +295,7 @@ $patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02', patron_list
|
|||
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by expirationdate and list');
|
||||
$patstodel = GetBorrowersToExpunge( {not_borrowed_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
|
||||
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by last issue date');
|
||||
ModMember( borrowernumber => $guarantee->{borrowernumber}, guarantorid=>'' );
|
||||
Koha::Patrons->find($guarantee->{borrowernumber})->set({ guarantorid => '' })->store;
|
||||
|
||||
$builder->build({
|
||||
source => 'Issue',
|
||||
|
|
|
|||
|
|
@ -526,13 +526,13 @@ is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Res
|
|||
|
||||
#Set the dateofbirth for the Borrower making them "too young".
|
||||
$borrower->{dateofbirth} = DateTime->now->add( years => -15 );
|
||||
C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $borrower->{dateofbirth} );
|
||||
Koha::Patrons->find( $borrowernumber )->set({ dateofbirth => $borrower->{dateofbirth} })->store;
|
||||
|
||||
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'ageRestricted', "Reserving a 'PEGI 16' Biblio by a 15 year old borrower fails");
|
||||
|
||||
#Set the dateofbirth for the Borrower making them "too old".
|
||||
$borrower->{dateofbirth} = DateTime->now->add( years => -30 );
|
||||
C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $borrower->{dateofbirth} );
|
||||
Koha::Patrons->find( $borrowernumber )->set({ dateofbirth => $borrower->{dateofbirth} })->store;
|
||||
|
||||
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
|
||||
####
|
||||
|
|
|
|||
|
|
@ -295,8 +295,8 @@ if ( $op eq 'do' ) {
|
|||
# If at least one field are filled, we want to modify the borrower
|
||||
if ( defined $infos ) {
|
||||
$infos->{borrowernumber} = $borrowernumber;
|
||||
my $success = ModMember(%$infos);
|
||||
if (!$success) {
|
||||
eval { Koha::Patrons->find( $borrowernumber )->set($infos)->store; };
|
||||
if ( $@ ) { # FIXME We could provide better error handling here
|
||||
my $patron = Koha::Patrons->find( $borrowernumber );
|
||||
$infos->{cardnumber} = $patron ? $patron->cardnumber || '' : '';
|
||||
push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber}, cardnumber => $infos->{cardnumber} };
|
||||
|
|
|
|||
Loading…
Reference in New Issue