I am not sure I understood the point of this subroutine.
Did I miss something here?
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>
use C4::Context;
use Koha::AuthUtils qw(get_script_name);
use Koha::Database;
-use C4::Members qw( AddMember_Auto );
+use Koha::Patrons;
use C4::Members::Messaging;
use Carp;
use CGI;
$borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || '';
}
- %borrower = AddMember_Auto( %borrower );
- C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $borrower{'borrowernumber'}, categorycode => $borrower{'categorycode'} } );
+ my $patron = Koha::Patron->new( \%borrower )->store;
+ C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $patron->borrowernumber, categorycode => $patron->categorycode } );
- return ( 1, $borrower{'cardnumber'}, $borrower{'userid'} );
+ return ( 1, $patron->cardnumber, $patron->userid );
}
sub _get_uri {
#Insert data
push @EXPORT, qw(
- &AddMember_Auto
&AddMember_Opac
);
);
}
-=head2 AddMember_Auto
-
-=cut
-
-sub AddMember_Auto {
- my ( %borrower ) = @_;
-
- my $patron = Koha::Patron->new(\%borrower)->store;
-
- return %{ $patron->unblessed };
-}
-
=head2 AddMember_Opac
=cut
$borrower{'password'} = $password;
}
- %borrower = AddMember_Auto(%borrower);
+ my $patron = Koha::Patron->new(\%borrower)->store;
- return ( $borrower{'borrowernumber'}, $password );
+ return ( $patron->borrowernumber, $password );
}
=head2 DeleteExpiredOpacRegistrations
$template->param( OpacPasswordChange =>
C4::Context->preference('OpacPasswordChange') );
- my ( $borrowernumber, $password ) = AddMember_Opac(%borrower);
- C4::Members::Attributes::SetBorrowerAttributes( $borrowernumber, $attributes );
- C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if $borrowernumber && C4::Context->preference('EnhancedMessagingPreferences');
+ my $patron = Koha::Patron->new( \%borrower )->store;
+ if ( $patron ) {
+ C4::Members::Attributes::SetBorrowerAttributes( $patron->borrowernumber, $attributes );
+ if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
+ C4::Form::MessagingPreferences::handle_form_action(
+ $cgi,
+ { borrowernumber => $patron->borrowernumber },
+ $template,
+ 1,
+ C4::Context->preference('PatronSelfRegistrationDefaultCategory')
+ );
+ }
- $template->param( password_cleartext => $password );
- my $patron = Koha::Patrons->find( $borrowernumber );
- $template->param( borrower => $patron->unblessed );
+ $template->param( password_cleartext => $password );
+ $template->param( borrower => $patron->unblessed );
+ } else {
+ # FIXME Handle possible errors here
+ }
$template->param(
PatronSelfRegistrationAdditionalInstructions =>
C4::Context->preference(
use Modern::Perl;
-use Test::More tests => 51;
+use Test::More tests => 50;
use Test::MockModule;
use Test::Exception;
my $hashed_up = Koha::AuthUtils::hash_password("Nexus-6", $borrower->{password});
is( $borrower->{password} eq $hashed_up, 1, 'Check password hash equals hash of submitted password' );
-subtest 'Trivial test for AddMember_Auto' => sub {
- plan tests => 3;
- my $library = $builder->build({ source => 'Branch' });
- my $category = $builder->build({ source => 'Category' });
- my %borr = AddMember_Auto( surname=> 'Dick3', firstname => 'Philip', branchcode => $library->{branchcode}, categorycode => $category->{categorycode}, password => '34567890' );
- ok( $borr{borrowernumber}, 'Borrower hash contains borrowernumber' );
- like( $borr{cardnumber}, qr/^\d+$/, 'Borrower hash contains cardnumber' );
- my $patron = Koha::Patrons->find( $borr{borrowernumber} );
- isnt( $patron, undef, 'Patron found' );
-};
-
$schema->storage->txn_rollback;
subtest 'Koha::Patron->store (invalid categorycode) tests' => sub {