From 7c05f4fbe41800a9be4b6d4bdc8d7c7ddeb69ef9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 13 Aug 2018 13:49:56 -0300 Subject: [PATCH] Bug 21068: Remove NorwegianPatronDB related code Bug 11401 introduced code to support Norwegian national library card. This code is too specific to be part of Koha as it, it should be a plugin instead. Moreover nobody uses it, but a modified version (see comment 3). Test plan: Add/edit/delete patron and make sure there are no regressions introduced by these patches Signed-off-by: Benjamin Rokseth Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens --- C4/Installer/PerlDependencies.pm | 20 - C4/Members.pm | 6 - Koha/NorwegianPatronDB.pm | 676 ------------------ Koha/Patron.pm | 50 -- installer/data/mysql/kohastructure.sql | 18 - .../prog/en/includes/members-toolbar.inc | 9 +- .../prog/en/includes/nl-search-form.tt | 9 - .../prog/en/includes/str/members-menu.inc | 1 - .../prog/en/modules/members/deletemem.tt | 6 - .../prog/en/modules/members/member.tt | 5 - .../prog/en/modules/members/memberentrygen.tt | 12 - .../prog/en/modules/members/moremember.tt | 26 - .../prog/en/modules/members/nl-search.tt | 180 ----- .../intranet-tmpl/prog/js/members-menu.js | 44 +- members/deletemem.pl | 27 +- members/memberentry.pl | 17 - members/moremember.pl | 14 - members/nl-search.pl | 167 ----- misc/cronjobs/nl-sync-from-koha.pl | 202 ------ misc/cronjobs/nl-sync-to-koha.pl | 186 ----- t/00-load.t | 6 +- t/NorwegianPatronDB.t | 599 ---------------- 22 files changed, 9 insertions(+), 2271 deletions(-) delete mode 100644 Koha/NorwegianPatronDB.pm delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/nl-search-form.tt delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/members/nl-search.tt delete mode 100755 members/nl-search.pl delete mode 100755 misc/cronjobs/nl-sync-from-koha.pl delete mode 100755 misc/cronjobs/nl-sync-to-koha.pl delete mode 100644 t/NorwegianPatronDB.t diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 73721a640d..81f82fdbd3 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -737,26 +737,6 @@ our $PERL_DEPS = { 'required' => '0', 'min_ver' => '5.836', }, - 'SOAP::Lite' => { - 'usage' => 'Norwegian national library card', - 'required' => '0', - 'min_ver' => '0.712', - }, - 'Crypt::GCrypt' => { - 'usage' => 'Norwegian national library card', - 'required' => '0', - 'min_ver' => '1.24', - }, - 'Convert::BaseN' => { - 'usage' => 'Norwegian national library card', - 'required' => '0', - 'min_ver' => '0.01', - }, - 'Digest::SHA' => { - 'usage' => 'Norwegian national library card', - 'required' => '0', - 'min_ver' => '5.61', - }, 'PDF::FromHTML' => { 'usage' => 'Discharge generation', 'required' => '0', diff --git a/C4/Members.pm b/C4/Members.pm index dc78638123..0cd424b395 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -50,12 +50,6 @@ use Koha::Schema; our (@ISA,@EXPORT,@EXPORT_OK,$debug); -use Module::Load::Conditional qw( can_load ); -if ( ! can_load( modules => { 'Koha::NorwegianPatronDB' => undef } ) ) { - $debug && warn "Unable to load Koha::NorwegianPatronDB"; -} - - BEGIN { $debug = $ENV{DEBUG} || 0; require Exporter; diff --git a/Koha/NorwegianPatronDB.pm b/Koha/NorwegianPatronDB.pm deleted file mode 100644 index f6155a8fd1..0000000000 --- a/Koha/NorwegianPatronDB.pm +++ /dev/null @@ -1,676 +0,0 @@ -package Koha::NorwegianPatronDB; - -# Copyright 2014 Oslo Public Library -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -=head1 NAME - -Koha::NorwegianPatronDB - -=head1 SYNOPSIS - - use Koha::NorwegianPatronDB; - -=head1 CONDITIONAL LOADING - -This module depends on some Perl modules that have not been marked as required. -This is because the module only will be of interest to Norwegian libraries, and -it seems polite not to bother the rest of the world with these modules. It is -also good practice to check that the module is actually needed before loading -it. So in a NorwegianPatronDB page or script it will be OK to just do: - - use Koha::NorwegianPatronDB qw(...); - -But in scripts that are also used by others (like e.g. moremember.pl), it will -be polite to only load the module at runtime, if it is needed: - - use Module::Load; - if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { - load Koha::NorwegianPatronDB, qw( NLGetSyncDataFromBorrowernumber ); - } - -(Module::Load::Conditional is used for this in other parts of Koha, but it does -not seem to allow for a list of subroutines to import, so Module::Load looks -like a better candidate.) - -=head1 FUNCTIONS - -=cut - -use Modern::Perl; -use C4::Context; -use C4::Members::Attributes qw( UpdateBorrowerAttribute ); -use SOAP::Lite; -use Crypt::GCrypt; -use Digest::SHA qw( sha256_hex ); -use Convert::BaseN; -use DateTime; - -use base 'Exporter'; - -our %EXPORT_TAGS = ( all => [qw( - NLCheckSysprefs - NLSearch - NLSync - NLGetChanged - NLMarkForDeletion - NLDecodePin - NLEncryptPIN - NLUpdateHashedPIN - NLGetFirstname - NLGetSurname - NLGetSyncDataFromBorrowernumber -)] ); -Exporter::export_ok_tags('all'); - -my $nl_uri = 'http://lanekortet.no'; - -=head2 SOAP::Transport::HTTP::Client::get_basic_credentials - -This is included to set the username and password used by SOAP::Lite. - -=cut - -sub SOAP::Transport::HTTP::Client::get_basic_credentials { - # Library username and password from Base Bibliotek (stored as system preferences) - my $library_username = C4::Context->preference("NorwegianPatronDBUsername"); - my $library_password = C4::Context->preference("NorwegianPatronDBPassword"); - # Vendor username and password (stored in koha-conf.xml) - my $vendor_username = C4::Context->config( 'nlvendoruser' ); - my $vendor_password = C4::Context->config( 'nlvendorpass' ); - # Combine usernames and passwords, and encrypt with SHA256 - my $combined_username = "$vendor_username-$library_username"; - my $combined_password = sha256_hex( "$library_password-$vendor_password" ); - return $combined_username => $combined_password; -} - -=head2 NLCheckSysprefs - -Check that sysprefs relevant to NL are set. - -=cut - -sub NLCheckSysprefs { - - my $response = { - 'error' => 0, - 'nlenabled' => 0, - 'endpoint' => 0, - 'userpass' => 0, - }; - - # Check that the Norwegian national paron database is enabled - if ( C4::Context->preference("NorwegianPatronDBEnable") == 1 ) { - $response->{ 'nlenabled' } = 1; - } else { - $response->{ 'error' } = 1; - } - - # Check that an endpoint is specified - if ( C4::Context->preference("NorwegianPatronDBEndpoint") ne '' ) { - $response->{ 'endpoint' } = 1; - } else { - $response->{ 'error' } = 1; - } - - # Check that the username and password for the patron database is set - if ( C4::Context->preference("NorwegianPatronDBUsername") ne '' && C4::Context->preference("NorwegianPatronDBPassword") ne '' ) { - $response->{ 'userpass' } = 1; - } else { - $response->{ 'error' } = 1; - } - - return $response; - -} - -=head2 NLSearch - -Search the NL patron database. - -SOAP call: "hent" (fetch) - -=cut - -sub NLSearch { - - my ( $identifier ) = @_; - - my $client = SOAP::Lite - ->on_action( sub { return '""';}) - ->uri( $nl_uri ) - ->proxy( C4::Context->preference("NorwegianPatronDBEndpoint") ); - - my $id = SOAP::Data->type('string'); - $id->name('identifikator'); - $id->value( $identifier ); - my $som = $client->hent( $id ); - - return $som; - -} - -=head2 NLSync - -Sync a patron that has been changed or created in Koha "upstream" to NL. - -Input is a hashref with one of two possible elements, either a patron retrieved -from the database: - - my $result = NLSync({ 'patron' => $borrower_from_dbic }); - -or a plain old borrowernumber: - - my $result = NLSync({ 'borrowernumber' => $borrowernumber }); - -In the latter case, this function will retrieve the patron record from the -database using DBIC. - -Which part of the API is called depends on the value of the "syncstatus" column: - -=over 4 - -=item * B = The I ("new record") method is called. - -=item * B = The I ("change/update") method is called. - -=item * B = The I ("delete") method is called. - -=back - -Required values for B and B: - -=over 4 - -=item * sist_endret (last updated) - -=item * adresse, postnr eller sted (address, zip or city) - -=item * fdato (birthdate) - -=item * fnr_hash (social security number, but not hashed...) - -=item * kjonn (gender, M/F) - -=back - -=cut - -sub NLSync { - - my ( $input ) = @_; - - my $patron; - if ( defined $input->{'borrowernumber'} ) { - $patron = Koha::Database->new->schema->resultset('Borrower')->find( $input->{'borrowernumber'} ); - } elsif ( defined $input->{'patron'} ) { - $patron = $input->{'patron'}; - } - - # There should only be one sync, so we use the first one - my @syncs = $patron->borrower_syncs; - my $sync; - foreach my $this_sync ( @syncs ) { - if ( $this_sync->synctype eq 'norwegianpatrondb' ) { - $sync = $this_sync; - } - } - - my $client = SOAP::Lite - ->on_action( sub { return '""';}) - ->uri( $nl_uri ) - ->proxy( C4::Context->preference("NorwegianPatronDBEndpoint") ); - - my $cardnumber = SOAP::Data->name( 'lnr' => $patron->cardnumber ); - - # Call the appropriate method based on syncstatus - my $response; - if ( $sync->syncstatus eq 'edited' || $sync->syncstatus eq 'new' ) { - my $soap_patron = _koha_patron_to_soap( $patron ); - if ( $sync->syncstatus eq 'edited' ) { - $response = $client->endre( $cardnumber, $soap_patron ); - } elsif ( $sync->syncstatus eq 'new' ) { - $response = $client->nyPost( $soap_patron ); - } - } - if ( $sync->syncstatus eq 'delete' ) { - $response = $client->slett( $cardnumber ); - } - - # Update the sync data according to the results - if ( $response->{'status'} && $response->{'status'} == 1 ) { - if ( $sync->syncstatus eq 'delete' ) { - # Turn off any further syncing - $sync->update( { 'sync' => 0 } ); - } - # Update the syncstatus to 'synced' - $sync->update( { 'syncstatus' => 'synced' } ); - # Update the 'synclast' attribute with the "server time" ("server_tid") returned by the method - $sync->update( { 'lastsync' => $response->{'server_tid'} } ); - } - return $response; - -} - -=head2 NLGetChanged - -Fetches patrons from NL that have been changed since a given timestamp. This includes -patrons that have been changed by the library that runs the sync, so we have to -check which library was the last one to change a patron, before we update patrons -locally. - -This is supposed to be executed once per night. - -SOAP call: soekEndret - -=cut - -sub NLGetChanged { - - my ( $from_arg ) = @_; - - my $client = SOAP::Lite - ->on_action( sub { return '""';}) - ->uri( $nl_uri ) - ->proxy( C4::Context->preference("NorwegianPatronDBEndpoint") ); - - my $from_string; - if ( $from_arg && $from_arg ne '' ) { - $from_string = $from_arg; - } else { - # Calculate 1 second past midnight of the day before - my $dt = DateTime->now( time_zone => 'Europe/Oslo' ); - $dt->subtract( days => 1 ); - my $from = DateTime->new( - year => $dt->year(), - month => $dt->month(), - day => $dt->day(), - hour => 0, - minute => 0, - second => 1, - time_zone => 'Europe/Oslo', - ); - $from_string = $from->ymd . "T" . $from->hms; - } - - my $timestamp = SOAP::Data->name( 'tidspunkt' => $from_string ); - my $max_results = SOAP::Data->name( 'max_antall' => 0 ); # 0 = no limit - my $start_index = SOAP::Data->name( 'start_indeks' => 0 ); # 1 is the first record - - # Call the appropriate method based on syncstatus - my $som = $client->soekEndret( $timestamp, $max_results, $start_index ); - - # Extract and massage patron data - my $result = $som->result; - foreach my $patron ( @{ $result->{'respons_poster'} } ) { - # Only handle patrons that have lnr (barcode) and fnr_hash (social security number) - # Patrons that lack these two have been deleted from NL - if ( $patron->{'lnr'} && $patron->{'fnr_hash'} ) { - push @{ $result->{'kohapatrons'} }, _soap_to_kohapatron( $patron ); - } - } - return $result; - -} - -=head2 NLMarkForDeletion - -Mark a borrower for deletion, but do not do the actual deletion. Deleting the -borrower from NL will be done later by the nl-sync-from-koha.pl script. - -=cut - -sub NLMarkForDeletion { - - my ( $borrowernumber ) = @_; - - my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({ - 'synctype' => 'norwegianpatrondb', - 'borrowernumber' => $borrowernumber, - }); - return $borrowersync->update( { 'syncstatus' => 'delete' } ); - -} - -=head2 NLDecodePin - -Takes a string encoded with AES/ECB/PKCS5PADDING and a 128-bits key, and returns -the decoded string as plain text. - -The key needs to be stored in koha-conf.xml, like so: - - - ... - - ... - xyz - - - -=cut - -sub NLDecodePin { - - my ( $hash ) = @_; - my $key = C4::Context->config( 'nlkey' ); - - # Convert the hash from Base16 - my $cb = Convert::BaseN->new( base => 16 ); - my $decoded_hash = $cb->decode( $hash ); - - # Do the decryption - my $cipher = Crypt::GCrypt->new( - type => 'cipher', - algorithm => 'aes', - mode => 'ecb', - padding => 'standard', # "This is also known as PKCS#5" - ); - $cipher->start( 'decrypting' ); - $cipher->setkey( $key ); # Must be called after start() - my $plaintext = $cipher->decrypt( $decoded_hash ); - $plaintext .= $cipher->finish; - - return $plaintext; - -} - -=head2 NLEncryptPIN - -Takes a plain text PIN as argument, returns the encrypted PIN, according to the -NL specs. - - my $encrypted_pin = NLEncryptPIN( $plain_text_pin ); - -=cut - -sub NLEncryptPIN { - - my ( $pin ) = @_; - return _encrypt_pin( $pin ); - -} - -=head2 NLUpdateHashedPIN - -Takes two arguments: - -=over 4 - -=item * Borrowernumber - -=item * Clear text PIN code - -=back - -Hashes the password and saves it in borrower_sync.hashed_pin. - -=cut - -sub NLUpdateHashedPIN { - - my ( $borrowernumber, $pin ) = @_; - my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({ - 'synctype' => 'norwegianpatrondb', - 'borrowernumber' => $borrowernumber, - }); - return $borrowersync->update({ 'hashed_pin', _encrypt_pin( $pin ) }); - -} - -=head2 _encrypt_pin - -Takes a plain text PIN and returns the encrypted version, according to the NL specs. - -=cut - -sub _encrypt_pin { - - my ( $pin ) = @_; - my $key = C4::Context->config( 'nlkey' ); - - # Do the encryption - my $cipher = Crypt::GCrypt->new( - type => 'cipher', - algorithm => 'aes', - mode => 'ecb', - padding => 'standard', # "This is also known as PKCS#5" - ); - $cipher->start( 'encrypting' ); - $cipher->setkey( $key ); # Must be called after start() - my $ciphertext = $cipher->encrypt( $pin ); - $ciphertext .= $cipher->finish; - - # Encode as Bas16 - my $cb = Convert::BaseN->new( base => 16 ); - my $encoded_ciphertext = $cb->encode( $ciphertext ); - - return $encoded_ciphertext; - -} - -=head2 NLGetSyncDataFromBorrowernumber - -Takes a borrowernumber as argument, returns a Koha::Schema::Result::BorrowerSync -object. - - my $syncdata = NLGetSyncDataFromBorrowernumber( $borrowernumber ); - -=cut - -sub NLGetSyncDataFromBorrowernumber { - - my ( $borrowernumber ) = @_; - my $data = Koha::Database->new->schema->resultset('BorrowerSync')->find({ - 'synctype' => 'norwegianpatrondb', - 'borrowernumber' => $borrowernumber, - }); - return $data; - -} - -=head2 NLGetFirstname - -Takes a string like "Surname, Firstname" and returns the "Firstname" part. - -If there is no comma, the string is returned unaltered. - - my $firstname = NLGetFirstname( $name ); - -=cut - -sub NLGetFirstname { - - my ( $s ) = @_; - my ( $surname, $firstname ) = _split_name( $s ); - if ( $surname eq $s ) { - return $s; - } else { - return $firstname; - } - -} - -=head2 NLGetSurname - -Takes a string like "Surname, Firstname" and returns the "Surname" part. - -If there is no comma, the string is returned unaltered. - - my $surname = NLGetSurname( $name ); - -=cut - -sub NLGetSurname { - - my ( $s ) = @_; - my ( $surname, $firstname ) = _split_name( $s ); - return $surname; - -} - -=head2 _split_name - -Takes a string like "Surname, Firstname" and returns a list of surname and firstname. - -If there is no comma, the string is returned unaltered. - - my ( $surname, $firstname ) = _split_name( $name ); - -=cut - -sub _split_name { - - my ( $s ) = @_; - - # Return the string if there is no comma - unless ( $s =~ m/,/ ) { - return $s; - } - - my ( $surname, $firstname ) = split /, /, $s; - - return ( $surname, $firstname ); - -} - -=head2 _format_soap_error - -Takes a soap result object as input and returns a formatted string containing SOAP error data. - -=cut - -sub _format_soap_error { - - my ( $result ) = @_; - if ( $result ) { - return join ', ', $result->faultcode, $result->faultstring, $result->faultdetail; - } else { - return 'No result'; - } - -} - -=head2 _soap_to_koha_patron - -Convert a SOAP object of type "Laaner" into a hash that can be sent to Koha::Patron - -=cut - -sub _soap_to_kohapatron { - - my ( $soap ) = @_; - - return { - 'cardnumber' => $soap->{ 'lnr' }, - 'surname' => NLGetSurname( $soap->{ 'navn' } ), - 'firstname' => NLGetFirstname( $soap->{ 'navn' } ), - 'sex' => $soap->{ 'kjonn' }, - 'dateofbirth' => $soap->{ 'fdato' }, - 'address' => $soap->{ 'p_adresse1' }, - 'address2' => $soap->{ 'p_adresse2' }, - 'zipcode' => $soap->{ 'p_postnr' }, - 'city' => $soap->{ 'p_sted' }, - 'country' => $soap->{ 'p_land' }, - 'b_address' => $soap->{ 'm_adresse1' }, - 'b_address2' => $soap->{ 'm_adresse2' }, - 'b_zipcode' => $soap->{ 'm_postnr' }, - 'b_city' => $soap->{ 'm_sted' }, - 'b_country' => $soap->{ 'm_land' }, - 'password' => $soap->{ 'pin' }, - 'dateexpiry' => $soap->{ 'gyldig_til' }, - 'email' => $soap->{ 'epost' }, - 'mobile' => $soap->{ 'tlf_mobil' }, - 'phone' => $soap->{ 'tlf_hjemme' }, - 'phonepro' => $soap->{ 'tlf_jobb' }, - '_extra' => { # Data that should not go in the borrowers table - 'socsec' => $soap->{ 'fnr_hash' }, - 'created' => $soap->{ 'opprettet' }, - 'created_by' => $soap->{ 'opprettet_av' }, - 'last_change' => $soap->{ 'sist_endret' }, - 'last_change_by' => $soap->{ 'sist_endret_av' }, - }, - }; - -} - -=head2 _koha_patron_to_soap - -Convert a patron (in the form of a Koha::Schema::Result::Borrower) into a SOAP -object that can be sent to NL. - -=cut - -sub _koha_patron_to_soap { - - my ( $patron ) = @_; - - # Extract attributes - my $patron_attributes = {}; - foreach my $attribute ( $patron->borrower_attributes ) { - $patron_attributes->{ $attribute->code->code } = $attribute->attribute; - } - - # There should only be one sync, so we use the first one - my @syncs = $patron->borrower_syncs; - my $sync = $syncs[0]; - - # Create SOAP::Data object - my $soap_patron = SOAP::Data->name( - 'post' => \SOAP::Data->value( - SOAP::Data->name( 'lnr' => $patron->cardnumber ), - SOAP::Data->name( 'fnr_hash' => $patron_attributes->{ 'fnr' } )->type( 'string' )->type( 'string' ), - SOAP::Data->name( 'navn' => $patron->surname . ', ' . $patron->firstname )->type( 'string' ), - SOAP::Data->name( 'sist_endret' => $sync->lastsync )->type( 'string' ), - SOAP::Data->name( 'kjonn' => $patron->sex )->type( 'string' ), - SOAP::Data->name( 'fdato' => $patron->dateofbirth )->type( 'string' ), - SOAP::Data->name( 'p_adresse1' => $patron->address )->type( 'string' ), - SOAP::Data->name( 'p_adresse2' => $patron->address2 )->type( 'string' ), - SOAP::Data->name( 'p_postnr' => $patron->zipcode )->type( 'string' ), - SOAP::Data->name( 'p_sted' => $patron->city )->type( 'string' ), - SOAP::Data->name( 'p_land' => $patron->country )->type( 'string' ), - SOAP::Data->name( 'm_adresse1' => $patron->b_address )->type( 'string' ), - SOAP::Data->name( 'm_adresse2' => $patron->b_address2 )->type( 'string' ), - SOAP::Data->name( 'm_postnr' => $patron->b_zipcode )->type( 'string' ), - SOAP::Data->name( 'm_sted' => $patron->b_city )->type( 'string' ), - SOAP::Data->name( 'm_land' => $patron->b_country )->type( 'string' ), - # Do not send the PIN code as it has been hashed by Koha, but use the version hashed according to NL - SOAP::Data->name( 'pin' => $sync->hashed_pin )->type( 'string' ), - SOAP::Data->name( 'gyldig_til' => $patron->dateexpiry )->type( 'string' ), - SOAP::Data->name( 'epost' => $patron->email )->type( 'string' ), - SOAP::Data->name( 'tlf_mobil' => $patron->mobile )->type( 'string' ), - SOAP::Data->name( 'tlf_hjemme' => $patron->phone )->type( 'string' ), - SOAP::Data->name( 'tlf_jobb' => $patron->phonepro )->type( 'string' ), - ), - )->type("Laaner"); - - return $soap_patron; - -} - -=head1 EXPORT - -None by default. - -=head1 AUTHOR - -Magnus Enger - -=cut - -1; - -__END__ diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 660a447d12..1637a042ac 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -23,7 +23,6 @@ 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 ); use C4::Accounts; @@ -45,10 +44,6 @@ use Koha::Club::Enrollments; use Koha::Account; use Koha::Subscription::Routinglists; -if ( ! can_load( modules => { 'Koha::NorwegianPatronDB' => undef } ) ) { - warn "Unable to load Koha::NorwegianPatronDB"; -} - use base qw(Koha::Object); our $RESULTSET_PATRON_ID_MAPPING = { @@ -245,24 +240,6 @@ sub store { $self = $self->SUPER::store; - # 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 ) - { - Koha::Database->new->schema->resultset('BorrowerSync') - ->create( - { - 'borrowernumber' => $self->borrowernumber, - 'synctype' => 'norwegianpatrondb', - 'sync' => 1, - 'syncstatus' => 'new', - 'hashed_pin' => - Koha::NorwegianPatronDB::NLEncryptPIN($self->plain_text_password), - } - ); - } - $self->add_enrolment_fee_if_needed; logaction( "MEMBERS", "CREATE", $self->borrowernumber, "" ) @@ -293,28 +270,6 @@ sub store { $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_from_storage->cardnumber; if ($borrowers_log @@ -685,11 +640,6 @@ sub update_password { return 0 if $password eq '****' or $password eq ''; - 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, $password ); - } - my $digest = Koha::AuthUtils::hash_password($password); $self->update( { diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index a15d4164de..45fd11773a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1697,24 +1697,6 @@ CREATE TABLE borrower_debarments ( -- tracks restrictions on the patron's record ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; --- --- Table structure for table borrower_sync --- - -DROP TABLE IF EXISTS `borrower_sync`; -CREATE TABLE borrower_sync ( - borrowersyncid int(11) NOT NULL AUTO_INCREMENT, -- Primary key, unique identifier - borrowernumber int(11) NOT NULL, -- Connects data about synchronisations to a borrower - synctype varchar(32) NOT NULL, -- There could potentially be more than one kind of syncing going on, a text string here can be used to tell them apart. E.g.: The Norwegian national patron database uses 'norwegianpatrondb' in this column - sync tinyint(1) NOT NULL DEFAULT '0', -- A boolean (1/0) for turning syncing off and on for individual borrowers - syncstatus varchar(10) DEFAULT NULL, -- The sync status for any given borrower. Could be text strings like 'new', 'edited', 'synced' etc. The values used here will depend on the actual syncing being done. - lastsync varchar(50) DEFAULT NULL, -- Date of the last successfull sync. The date format might be different depending on the service that is being used, so no special date format is being enforced here. - hashed_pin varchar(64) DEFAULT NULL, -- Perhaps specific to The Norwegian national patron database, this column holds a hashed PIN code - PRIMARY KEY (borrowersyncid), - KEY borrowernumber (borrowernumber), - CONSTRAINT borrower_sync_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -- -- Table structure for table api_keys -- diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc index 6d4b896cb1..3f9a0ea744 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/members-toolbar.inc @@ -4,7 +4,6 @@ [% USE Branches %] [% USE Categories %] [% USE AuthorisedValues %] -[% SET NorwegianPatronDBEnable = Koha.Preference( 'NorwegianPatronDBEnable' ) %]
[% IF CAN_user_borrowers_edit_borrowers %] [% IF ( guarantor ) %] @@ -72,13 +71,7 @@ [% END %] [% IF CAN_user_borrowers_edit_borrowers %] - [% IF ( NorwegianPatronDBEnable == 1 ) %] -
  • Delete local
  • -
  • Delete remote
  • -
  • Delete local and remote
  • - [% ELSE %] -
  • Delete
  • - [% END %] +
  • Delete
  • [% ELSE %]
  • Delete
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/nl-search-form.tt b/koha-tmpl/intranet-tmpl/prog/en/includes/nl-search-form.tt deleted file mode 100644 index cf133a96c3..0000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/nl-search-form.tt +++ /dev/null @@ -1,9 +0,0 @@ -
    - -
    - [% nl_search_form_title | html %] - - - -
    -
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/str/members-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/str/members-menu.inc index cd92d68a9e..703930cd25 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/str/members-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/str/members-menu.inc @@ -9,7 +9,6 @@ var CAN_user_borrowers_edit_borrowers = "[% CAN_user_borrowers_edit_borrowers | html %]"; var dateformat = "[% Koha.Preference('dateformat') | html %]"; - var NorwegianPatronDBEnable = "[% Koha.Preference('NorwegianPatronDBEnable') | html %]"; var borrowernumber; var number_of_adult_categories = 0; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/deletemem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/deletemem.tt index d9b25826ed..ba9cbb5b38 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/deletemem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/deletemem.tt @@ -49,12 +49,6 @@
    [% END %] - [% IF ( keeplocal ) %] -
    -

    Remote record deleted, local record kept

    -

    Patron was marked for deletion from Norwegian national patron database, but the local record was kept.

    -
    - [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt index 1a765a6cba..5f6b364727 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt @@ -28,11 +28,6 @@ [% END %] - [% IF Koha.Preference( 'NorwegianPatronDBEnable' ) == 1 %] - [% SET nl_search_form_title='Search the Norwegian national patron database' %] - [% INCLUDE 'nl-search-form.tt' %] - [% END %] - [% INCLUDE 'patron-toolbar.inc' %] [% INCLUDE 'noadd-warnings.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 52acc1db37..e5b34e139e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -635,18 +635,6 @@ [% IF ( mandatorysort2 ) %]Required[% END %] [% END %] - [% IF ( Koha.Preference( 'NorwegianPatronDBEnable' ) == 1 ) %] -
  • - - [% IF ( sync == 0 ) %] - Yes - No - [% ELSE %] - Yes - No - [% END %] -
  • - [% END %] [% IF ( Koha.Preference('CheckPrevCheckout') == 'softyes' || Koha.Preference('CheckPrevCheckout') == 'softno' ) %]
  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -as - - - -[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/members-menu.js b/koha-tmpl/intranet-tmpl/prog/js/members-menu.js index 4a3f4f7f52..ecc22b19c1 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members-menu.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members-menu.js @@ -1,4 +1,4 @@ -/* global borrowernumber advsearch dateformat _ CAN_user_borrowers_edit_borrowers NorwegianPatronDBEnable number_of_adult_categories destination */ +/* global borrowernumber advsearch dateformat _ CAN_user_borrowers_edit_borrowers number_of_adult_categories destination */ $(document).ready(function(){ $("#filteraction_off, #filteraction_on").on('click', function(e) { @@ -31,27 +31,9 @@ $(document).ready(function(){ }); if( CAN_user_borrowers_edit_borrowers ){ - if( NorwegianPatronDBEnable == 1 ){ - $("#deletepatronlocal").click(function(){ - confirm_local_deletion(); - $(".btn-group").removeClass("open"); - return false; - }); - $("#deletepatronremote").click(function(){ - confirm_remote_deletion(); - $(".btn-group").removeClass("open"); - return false; - }); - $("#deletepatronboth").click(function(){ - confirm_both_deletion(); - $(".btn-group").removeClass("open"); - return false; - }); - } else { - $("#deletepatron").click(function(){ - window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber; - }); - } + $("#deletepatron").click(function(){ + window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber; + }); $("#renewpatron").click(function(){ confirm_reregistration(); $(".btn-group").removeClass("open"); @@ -101,24 +83,6 @@ $(document).ready(function(){ $("#borrower_message").val( $(this).val() ); }); }); -function confirm_local_deletion() { - var is_confirmed = window.confirm(_("Are you sure you want to delete this patron from the local database? This cannot be undone.")); - if (is_confirmed) { - window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber + '&deletelocal=true&deleteremote=false'; - } -} -function confirm_remote_deletion() { - var is_confirmed = window.confirm(_("Are you sure you want to delete this patron from the Norwegian national patron database? This cannot be undone.")); - if (is_confirmed) { - window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber + '&deletelocal=false&deleteremote=true'; - } -} -function confirm_both_deletion() { - var is_confirmed = window.confirm(_("Are you sure you want to delete this patron both from the local database and from the Norwegian national patron database? This cannot be undone.")); - if (is_confirmed) { - window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber + '&deletelocal=true&deleteremote=true'; - } -} function confirm_updatechild() { var is_confirmed = window.confirm(_("Are you sure you want to update this child to an Adult category? This cannot be undone.")); diff --git a/members/deletemem.pl b/members/deletemem.pl index c010f0fecf..4789cf4fb1 100755 --- a/members/deletemem.pl +++ b/members/deletemem.pl @@ -28,15 +28,10 @@ use C4::Context; use C4::Output; use C4::Auth; use C4::Members; -use Module::Load; use Koha::Patrons; use Koha::Token; use Koha::Patron::Categories; -if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { - load Koha::NorwegianPatronDB, qw( NLMarkForDeletion NLSync ); -} - my $input = new CGI; my ($template, $loggedinuser, $cookie) @@ -61,20 +56,6 @@ my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in" my $patron = Koha::Patrons->find( $member ); output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); -# Handle deletion from the Norwegian national patron database, if it is enabled -# If the "deletelocal" parameter is set to "false", the regular deletion will be -# short circuited, and only a deletion from the national database can be carried -# out. If "deletelocal" is set to "true", or not set to anything normal -# deletion will be done. -my $deletelocal = $input->param('deletelocal') eq 'false' ? 0 : 1; # Deleting locally is the default -if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { - if ( $input->param('deleteremote') eq 'true' ) { - # Mark for deletion, then try a live sync - NLMarkForDeletion( $member ); - NLSync({ 'borrowernumber' => $member }); - } -} - my $charges = $patron->account->non_issues_charges; my $countissues = $patron->checkouts->count; my $userenv = C4::Context->userenv; @@ -104,7 +85,7 @@ if (C4::Context->preference("IndependentBranches")) { my $op = $input->param('op') || 'delete_confirm'; my $dbh = C4::Context->dbh; my $is_guarantor = $dbh->selectrow_array("SELECT COUNT(*) FROM borrowers WHERE guarantorid=?", undef, $member); -if ( $op eq 'delete_confirm' or $countissues > 0 or $charges or $is_guarantor or $deletelocal == 0) { +if ( $op eq 'delete_confirm' or $countissues > 0 or $charges or $is_guarantor ) { $template->param( patron => $patron, @@ -118,11 +99,9 @@ if ( $op eq 'delete_confirm' or $countissues > 0 or $charges or $is_guarantor or if ($is_guarantor) { $template->param(guarantees => 1); } - if ($deletelocal == 0) { - $template->param(keeplocal => 1); - } + # This is silly written but reflect the same conditions as above - if ( not $countissues > 0 and not $charges and not $is_guarantor and not $deletelocal == 0 ) { + if ( not $countissues > 0 and not $charges and not $is_guarantor ) { $template->param( op => 'delete_confirm', csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID') }), diff --git a/members/memberentry.pl b/members/memberentry.pl index cb4d0506ac..14a11361a2 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -48,10 +48,6 @@ use Koha::Patron::HouseboundRole; use Koha::Patron::HouseboundRoles; use Koha::Token; use Email::Valid; -use Module::Load; -if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { - load Koha::NorwegianPatronDB, qw( NLGetSyncDataFromBorrowernumber ); -} use Koha::SMS::Providers; use vars qw($debug); @@ -483,10 +479,6 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) { C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'}); } - # Try to do the live sync with the Norwegian national patron database, if it is enabled - if ( exists $data{'borrowernumber'} && C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { - NLSync({ 'borrowernumber' => $borrowernumber }); - } # Create HouseboundRole if necessary. # Borrower did not exist, so HouseboundRole *cannot* yet exist. @@ -599,15 +591,6 @@ if ($op eq "modify") { if ( $step == 4 ) { $template->param( categorycode => $borrower_data->{'categorycode'} ); } - # Add sync data to the user data - if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { - my $sync = NLGetSyncDataFromBorrowernumber( $borrowernumber ); - if ( $sync ) { - $template->param( - sync => $sync->sync, - ); - } - } } if ( $op eq "duplicate" ) { $template->param( updtype => 'I' ); diff --git a/members/moremember.pl b/members/moremember.pl index 711cbbf1cd..9f06882b8f 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -55,10 +55,6 @@ use Koha::AuthorisedValues; use Koha::CsvProfiles; use Koha::Patron::Debarments qw(GetDebarments); use Koha::Patron::Messages; -use Module::Load; -if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { - load Koha::NorwegianPatronDB, qw( NLGetSyncDataFromBorrowernumber ); -} #use Smart::Comments; #use Data::Dumper; use DateTime; @@ -241,16 +237,6 @@ if ($borrowernumber) { ->count( { borrowernumber => $borrowernumber } ) ); } -# Add sync data to the user data -if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { - my $sync = NLGetSyncDataFromBorrowernumber( $borrowernumber ); - if ( $sync ) { - $data->{'sync'} = $sync->sync; - $data->{'syncstatus'} = $sync->syncstatus; - $data->{'lastsync'} = $sync->lastsync; - } -} - # Generate CSRF token for upload and delete image buttons $template->param( csrf_token => Koha::Token->new->generate_csrf({ session_id => $input->cookie('CGISESSID'),}), diff --git a/members/nl-search.pl b/members/nl-search.pl deleted file mode 100755 index a873fd9663..0000000000 --- a/members/nl-search.pl +++ /dev/null @@ -1,167 +0,0 @@ -#!/usr/bin/perl - -# Copyright 2013 Oslo Public Library -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -=head1 NAME - -nl-search.pl - Script for searching the Norwegian national patron database - -=head1 DESCRIPTION - -This script will search the Norwegian national patron database, and let staff -import patrons from the natial database into the local database. - -In order to use this, a username/password from the Norwegian national database -of libraries ("Base Bibliotek") is needed. A special key is also needed, in -order to decrypt and encrypt PIN-codes/passwords. - -See http://www.lanekortet.no/ for more information (in Norwegian). - -=cut - -use Modern::Perl; -use CGI; -use C4::Auth; -use C4::Context; -use C4::Output; -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; -my $dbh = C4::Context->dbh; -my $op = $cgi->param('op'); - -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { - template_name => "members/nl-search.tt", - query => $cgi, - type => "intranet", - authnotrequired => 0, - flagsrequired => { borrowers => 'edit_borrowers' }, - debug => 1, - } -); - -my $userenv = C4::Context->userenv; - -# Check sysprefs -my $check_result = NLCheckSysprefs(); -if ( $check_result->{'error'} == 1 ) { - $template->param( 'error' => $check_result ); - output_html_with_http_headers $cgi, $cookie, $template->output; - exit 0; -} - -if ( $op && $op eq 'search' ) { - - # Get the string we are searching for - my $identifier = $cgi->param('q'); - if ( $identifier ) { - # Local search - my $local_results = C4::Utils::DataTables::Members::search( - { - searchmember => $identifier, - dt_params => { iDisplayLength => -1 }, - } - )->{patrons}; - $template->param( 'local_result' => $local_results ); - # Search NL, unless we got at least one hit and further searching is - # disabled - if ( scalar @{ $local_results } == 0 || C4::Context->preference("NorwegianPatronDBSearchNLAfterLocalHit") == 1 ) { - # TODO Check the format of the identifier before searching NL - my $result = NLSearch( $identifier ); - unless ($result->fault) { - my $r = $result->result(); - my $categories = Koha::Patron::Categories->search_limited; - $template->param( - 'result' => $r, - 'categories' => $categories, - ); - } else { - $template->param( 'error' => join ', ', $result->faultcode, $result->faultstring, $result->faultdetail ); - } - } - $template->param( 'q' => $identifier ); - } - -} elsif ( $op && $op eq 'save' ) { - - # This is where we map from fields in NL to fields in Koha - my %borrower = ( - 'surname' => NLGetSurname( $cgi->param('navn') ), - 'firstname' => NLGetFirstname( $cgi->param('navn') ), - 'sex' => scalar $cgi->param('kjonn'), - 'dateofbirth' => scalar $cgi->param('fdato'), - 'cardnumber' => scalar $cgi->param('lnr'), - 'userid' => scalar $cgi->param('lnr'), - 'address' => scalar $cgi->param('p_adresse1'), - 'address2' => scalar $cgi->param('p_adresse2'), - 'zipcode' => scalar $cgi->param('p_postnr'), - 'city' => scalar $cgi->param('p_sted'), - 'country' => scalar $cgi->param('p_land'), - 'B_address' => scalar $cgi->param('m_adresse1'), - 'B_address2' => scalar $cgi->param('m_adresse2'), - 'B_zipcode' => scalar $cgi->param('m_postnr'), - 'B_city' => scalar $cgi->param('m_sted'), - 'B_country' => scalar $cgi->param('m_land'), - 'password' => NLDecodePin( $cgi->param('pin') ), - 'dateexpiry' => scalar $cgi->param('gyldig_til'), - 'email' => scalar $cgi->param('epost'), - 'mobile' => scalar $cgi->param('tlf_mobil'), - 'phone' => scalar $cgi->param('tlf_hjemme'), - 'phonepro' => scalar $cgi->param('tlf_jobb'), - 'branchcode' => $userenv->{'branch'}, - 'categorycode' => scalar $cgi->param('categorycode'), - ); - # Add the new patron - 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 Koha::Patron->store - my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({ - 'synctype' => 'norwegianpatrondb', - 'borrowernumber' => $borrowernumber, - }); - $borrowersync->update({ 'syncstatus', 'synced' }); - $borrowersync->update({ 'lastsync', $cgi->param('sist_endret') }); - $borrowersync->update({ 'hashed_pin', $cgi->param('pin') }); - # Try to sync in real time. If this fails it will be picked up by the cronjob - NLSync({ 'borrowernumber' => $borrowernumber }); - # Redirect to the edit screen - print $cgi->redirect( "/cgi-bin/koha/members/memberentry.pl?op=modify&destination=circ&borrowernumber=$borrowernumber" ); - } else { - $template->param( 'error' => 'COULD_NOT_ADD_PATRON' ); - } -} - -output_html_with_http_headers $cgi, $cookie, $template->output; - -=head1 AUTHOR - -Magnus Enger - -=cut diff --git a/misc/cronjobs/nl-sync-from-koha.pl b/misc/cronjobs/nl-sync-from-koha.pl deleted file mode 100755 index 81e3218232..0000000000 --- a/misc/cronjobs/nl-sync-from-koha.pl +++ /dev/null @@ -1,202 +0,0 @@ -#!/usr/bin/perl - -# Copyright 2014 Oslo Public Library - -=head1 NAME - -nl-sync-from-koha.pl - Sync patrons from Koha to the Norwegian national patron database (NL). - -=head1 SYNOPSIS - - perl nl-sync-from-koha.pl -v --run - -=cut - -use Koha::NorwegianPatronDB qw( NLCheckSysprefs NLSync ); -use Koha::Database; -use Getopt::Long; -use Pod::Usage; -use Modern::Perl; - -# Get options -my ( $run, $verbose, $debug ) = get_options(); - -=head1 ACTIONS - -=head2 - -Find local patrons that have been changed and need to be sent upstream to NL. -These patrons will be distinguished by two borrower attributes: - -=over 4 - -=item * The "nlstatus" attribute will have a value of "needsync". (Which means -that the patron has been changed in Koha, but not yet successfully synced -upstream.) - -=item * The "nlsync" attribute will have a value of 1. (Which means that this -patron has accepted to be synced with NL, as opposed to a value of 0 which -would indicate that the patron has asked not to be synced with NL.) - -=back - -=head1 STEPS - -This script performs the following steps: - -=head2 Check sysprefs - -Check that the necessary sysprefs are set before proceeding. - -=cut - -my $check_result = NLCheckSysprefs(); -if ( $check_result->{'error'} == 1 ) { - if ( $check_result->{'nlenabled'} == 0 ) { say "* Please activate this function with the NorwegianPatronDBEnable system preference." }; - if ( $check_result->{'endpoint'} == 0 ) { say "* Please specify an endpoint with the NorwegianPatronDBEndpoint system preference." }; - if ( $check_result->{'userpass'} == 0 ) { say "* Please fill in the NorwegianPatronDBUsername and NorwegianPatronDBPassword system preferences." }; - exit 0; -} - -unless ( $run ) { - say "* You have not specified --run, no real syncing will be done."; -} - -=head2 Find patrons that need to be synced - -Patrons with either of these statuses: - -=over 4 - -=item * edited - -=item * new - -=item * deleted - -=back - -=cut - -my @needs_sync = Koha::Database->new->schema->resultset('BorrowerSync')->search({ - -and => [ - sync => 1, - synctype => 'norwegianpatrondb', - -or => [ - syncstatus => 'edited', - syncstatus => 'new', - syncstatus => 'delete', - ], - ], -}); - -=head2 Do the actual sync - -Data is synced to NL with NLSync. - -=cut - -my $sync_success = 0; -my $sync_failed = 0; -foreach my $borrower ( @needs_sync ) { - my $cardnumber = $borrower->borrowernumber->cardnumber; - my $firstname = $borrower->borrowernumber->firstname; - my $surname = $borrower->borrowernumber->surname; - my $syncstatus = $borrower->syncstatus; - say "*** Syncing patron: $cardnumber - $firstname $surname ($syncstatus)" if $verbose; - if ( $run ) { - my $response = NLSync({ 'patron' => $borrower->borrowernumber }); - if ( $response ) { - my $result = $response->result; - if ( $result->{'status'} && $result->{'status'} == 1 ) { - $sync_success++; - } else { - $sync_failed++; - } - if ( $result->{'melding'} && $verbose ) { - say $result->{'melding'}; - } - } - } -} - -=head2 Summarize if verbose mode is enabled - -Specify -v on the command line to get a summary of the syncing operations. - -=cut - -if ( $verbose ) { - say "-----------------------------"; - say "Sync succeeded: $sync_success"; - say "Sync failed : $sync_failed"; -} - -=head1 OPTIONS - -=over 4 - -=item B<-r, --run> - -Actually carry out syncing operations. Without this option, the script will -only report what it would have done, but not change any data, locally or -remotely. - -=item B<-v --verbose> - -Report on the progress of the script. - -=item B<-d --debug> - -Even more output. - -=item B<-h, -?, --help> - -Prints this help message and exits. - -=back - -=cut - -sub get_options { - - # Options - my $run = '', - my $verbose = ''; - my $debug = ''; - my $help = ''; - - GetOptions ( - 'r|run' => \$run, - 'v|verbose' => \$verbose, - 'd|debug' => \$debug, - 'h|?|help' => \$help - ); - - pod2usage( -exitval => 0 ) if $help; - - return ( $run, $verbose, $debug ); - -} - -=head1 AUTHOR - -Magnus Enger - -=head1 COPYRIGHT - -Copyright 2014 Oslo Public Library - -=head1 LICENSE - -This file is part of Koha. - -Koha is free software; you can redistribute it and/or modify it under the terms -of the GNU General Public License as published by the Free Software Foundation; -either version 3 of the License, or (at your option) any later version. - -You should have received a copy of the GNU General Public License along with -Koha; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, -Fifth Floor, Boston, MA 02110-1301 USA. - -=cut diff --git a/misc/cronjobs/nl-sync-to-koha.pl b/misc/cronjobs/nl-sync-to-koha.pl deleted file mode 100755 index ce25c7e142..0000000000 --- a/misc/cronjobs/nl-sync-to-koha.pl +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/perl - -# Copyright 2014 Oslo Public Library - -=head1 NAME - -nl-sync-to-koha.pl - Sync patrons from the Norwegian national patron database (NL) to Koha. - -=head1 SYNOPSIS - - perl nl-sync-to-koha.pl -v --run - -=cut - -use C4::Members::Attributes qw( UpdateBorrowerAttribute ); -use Koha::NorwegianPatronDB qw( NLCheckSysprefs NLGetChanged ); -use Koha::Patrons; -use Koha::Database; -use Getopt::Long; -use Pod::Usage; -use Modern::Perl; - -# Get options -my ( $run, $from, $verbose, $debug ) = get_options(); - -my $check_result = NLCheckSysprefs(); -if ( $check_result->{'error'} == 1 ) { - if ( $check_result->{'nlenabled'} == 0 ) { say "* Please activate this function with the NorwegianPatronDBEnable system preference." }; - if ( $check_result->{'endpoint'} == 0 ) { say "* Please specify an endpoint with the NorwegianPatronDBEndpoint system preference." }; - if ( $check_result->{'userpass'} == 0 ) { say "* Please fill in the NorwegianPatronDBUsername and NorwegianPatronDBPassword system preferences." }; - exit 0; -} - -unless ( $run ) { - say "* You have not specified --run, no real syncing will be done."; -} - -# Do the sync -my $sync_success = 0; -my $sync_failed = 0; -my $skipped_local_change = 0; - -# Get the borrowers that have been changed -my $result = NLGetChanged( $from ); - -if ( $verbose ) { - say 'Number of records: ' . $result->{'antall_poster_returnert'}; - say 'Number of hits: ' . $result->{'antall_treff'}; - say 'Message: ' . $result->{'melding'}; - say 'Status: ' . $result->{'status'}; - say 'Server time: ' . $result->{'server_tid'}; - say "-----------------------------"; -} - -# Loop through the patrons -foreach my $patron ( @{ $result->{'kohapatrons'} } ) { - if ( $verbose ) { - if ( $patron->{'surname'} ) { - say "*** Name: " . $patron->{'surname'}; - } else { - say "*** No name"; - } - say 'Created by: ' . $patron->{'_extra'}->{'created_by'}; - say 'Last change by: ' . $patron->{'_extra'}->{'last_change_by'}; - } - # Only sync in changes made by other libraries - if ( C4::Context->preference("NorwegianPatronDBUsername") ne $patron->{'_extra'}->{'last_change_by'} ) { - # Make a copy of the data in the hashref and store it as a hash - my %clean_patron = %$patron; - # Delete the extra data from the copy of the hashref - delete $clean_patron{'_extra'}; - # Find the borrowernumber based on cardnumber - my $stored_patron = Koha::Patrons->find({ cardnumber => $patron->{cardnumber} }); - my $borrowernumber = $stored_patron->borrowernumber; - if ( $run ) { - # 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', - 'borrowernumber' => $borrowernumber, - }); - # Update the syncstatus to 'synced' - $sync->update( { 'syncstatus' => 'synced' } ); - # Update the 'synclast' attribute with the "server time" ("server_tid") returned by the method - $sync->update( { 'lastsync' => $result->{'result'}->{'server_tid'} } ); - # Save social security number as attribute - UpdateBorrowerAttribute( - $borrowernumber, - { code => 'fnr', attribute => $patron->{'_extra'}->{'socsec'} }, - ); - $sync_success++; - } else { - $sync_failed++; - } - } - } else { - say "Skipped, local change" if $verbose; - $skipped_local_change++; - } -} - -if ( $verbose ) { - say "-----------------------------"; - say "Sync succeeded: $sync_success"; - say "Sync failed : $sync_failed"; - say "Skipped local change: $skipped_local_change"; -} - -=head1 OPTIONS - -=over 4 - -=item B<-r, --run> - -Actually carry out syncing operations. Without this option, the script will -only report what it would have done, but not change any data, locally or -remotely. - -=item B<-v --verbose> - -Report on the progress of the script. - -=item B<-f --from> - -Date and time to sync from, if this should be different from "1 second past -midnight of the day before". The date should be in this format: - - 2014-06-03T00:00:01 - -=item B<-d --debug> - -Even more output. - -=item B<-h, -?, --help> - -Prints this help message and exits. - -=back - -=cut - -sub get_options { - - # Options - my $run = '', - my $from = '', - my $verbose = ''; - my $debug = ''; - my $help = ''; - - GetOptions ( - 'r|run' => \$run, - 'f|from=s' => \$from, - 'v|verbose' => \$verbose, - 'd|debug' => \$debug, - 'h|?|help' => \$help - ); - - pod2usage( -exitval => 0 ) if $help; - - return ( $run, $from, $verbose, $debug ); - -} - -=head1 AUTHOR - -Magnus Enger - -=head1 COPYRIGHT - -Copyright 2014 Oslo Public Library - -=head1 LICENSE - -This file is part of Koha. - -Koha is free software; you can redistribute it and/or modify it under the terms -of the GNU General Public License as published by the Free Software Foundation; -either version 3 of the License, or (at your option) any later version. - -You should have received a copy of the GNU General Public License along with -Koha; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, -Fifth Floor, Boston, MA 02110-1301 USA. - -=cut diff --git a/t/00-load.t b/t/00-load.t index 95b3511607..c45f21a599 100644 --- a/t/00-load.t +++ b/t/00-load.t @@ -75,11 +75,7 @@ sub is_testable { my ($module_name) = @_; my @needed_module_names; my $return_value = 1; - if ( $module_name =~ /Koha::NorwegianPatronDB/xsm ) { - @needed_module_names = - ( 'SOAP::Lite', 'Crypt::GCrypt', 'Digest::SHA', 'Convert::BaseN' ); - } - elsif ( $module_name =~ /Koha::SearchEngine::Elasticsearch::Indexer/xsm ) { + if ( $module_name =~ /Koha::SearchEngine::Elasticsearch::Indexer/xsm ) { @needed_module_names = ( 'Catmandu::Importer::MARC', 'Catmandu::Store::ElasticSearch' ); } diff --git a/t/NorwegianPatronDB.t b/t/NorwegianPatronDB.t deleted file mode 100644 index ec630203d6..0000000000 --- a/t/NorwegianPatronDB.t +++ /dev/null @@ -1,599 +0,0 @@ -#!/usr/bin/perl - -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -use Modern::Perl; -use Test::More; -use Test::MockModule; -use t::lib::Mocks; -use Data::Dumper; - -# Check that all the modules we need are installed, or bail out -BEGIN { - my $missing_lib; - eval { - require Test::DBIx::Class; - 1; - } or do { - $missing_lib = "Test::DBIx::Class"; - }; - - eval { - require SOAP::Lite; - 1; - } or do { - $missing_lib = "SOAP::Lite"; - }; - - eval { - require Crypt::GCrypt; - 1; - } or do { - $missing_lib = "Crypt::GCrypt"; - }; - - eval { - require Convert::BaseN; - 1; - } or do { - $missing_lib = "Convert::BaseN"; - }; - - if ( $missing_lib ) { - plan skip_all => $missing_lib . " is not available."; - } else { - # Everything good - plan tests => 73; - } -} - -use Test::DBIx::Class {}, 'Borrower', 'BorrowerSync'; #Also loads those modules. - -# Make the code in the module use our mocked Koha::Schema/Koha::Database -my $db = Test::MockModule->new('Koha::Database'); -$db->mock( - # Schema() gives us the DB connection set up by Test::DBIx::Class - _new_schema => sub { return Schema(); } -); - -fixtures_ok [ - 'Borrower' => [ - [qw/firstname surname borrowernumber address city/], - ['Test', 'Borrower', 1, 'Test road', 'Test city'], - ['Test', 'Borrower', 2, 'Test road', 'Test city'], - ['Test', 'Borrower', 3, 'Test road', 'Test city'], - ['Test', 'Borrower', 4, 'Test road', 'Test city'], - ], - 'BorrowerSync' => [ - [qw/borrowernumber sync syncstatus lastsync hashed_pin synctype/], - [1, 1, 'new', '2014-03-31T12:35:14', 'abc', 'norwegianpatrondb' ], - [2, 1, 'edited', '2014-03-31T12:35:14', 'abc', 'norwegianpatrondb' ], - [3, 1, 'new', '2014-03-31T12:35:14', 'abc', 'norwegianpatrondb' ], - [4, 1, 'new', '2014-03-31T12:35:14', 'abc', 'norwegianpatrondb' ], - ], -], 'installed some fixtures'; - -=head1 LOADING THE MODULE - -=cut - -BEGIN { use_ok( 'Koha::NorwegianPatronDB', ':all' ) } - - -=head1 UTILITY SUBROUTINES - -=head2 NLCheckSysprefs - -Relevant sysprefs: - -=over 4 - -=item * NorwegianPatronDBEnable - -=item * NorwegianPatronDBEndpoint - -=item * NorwegianPatronDBUsername - -=item * NorwegianPatronDBPassword - -=back - -=cut - -BEGIN { - t::lib::Mocks::mock_config('nlkey', 'key'); - t::lib::Mocks::mock_config('nlvendoruser', 'user'); - t::lib::Mocks::mock_config('nlvendorpass', 'pass'); -} -t::lib::Mocks::mock_preference('NorwegianPatronDBEnable', 0); -t::lib::Mocks::mock_preference('NorwegianPatronDBEndpoint', ''); -t::lib::Mocks::mock_preference('NorwegianPatronDBUsername', ''); -t::lib::Mocks::mock_preference('NorwegianPatronDBPassword', ''); - -ok( my $result = NLCheckSysprefs(), 'call NLCheckSysprefs() ok' ); -is( $result->{ 'error' }, 1, 'error detected' ); -is( $result->{ 'nlenabled' }, 0, 'NL is not enabled' ); -is( $result->{ 'endpoint' }, 0, 'an endpoint is not specified' ); -is( $result->{ 'userpass' }, 0, 'username and/or password is missing' ); - -t::lib::Mocks::mock_preference('NorwegianPatronDBEnable', 1); -ok( $result = NLCheckSysprefs(), 'call NLCheckSysprefs() ok' ); -is( $result->{ 'error' }, 1, 'error detected' ); -is( $result->{ 'nlenabled' }, 1, 'NL is enabled' ); -is( $result->{ 'endpoint' }, 0, 'an endpoint is not specified' ); -is( $result->{ 'userpass' }, 0, 'username and/or password is missing' ); - -t::lib::Mocks::mock_preference('NorwegianPatronDBEnable', 0); -t::lib::Mocks::mock_preference('NorwegianPatronDBUsername', 'user'); -t::lib::Mocks::mock_preference('NorwegianPatronDBPassword', 'pass'); -ok( $result = NLCheckSysprefs(), 'call NLCheckSysprefs() ok' ); -is( $result->{ 'error' }, 1, 'error detected' ); -is( $result->{ 'nlenabled' }, 0, 'NL is not enabled' ); -is( $result->{ 'endpoint' }, 0, 'an endpoint is not specified' ); -is( $result->{ 'userpass' }, 1, 'username and/or password is present' ); - -t::lib::Mocks::mock_preference('NorwegianPatronDBEnable', 1); -t::lib::Mocks::mock_preference('NorwegianPatronDBEndpoint', 'http://example.com/'); -ok( $result = NLCheckSysprefs(), 'call NLCheckSysprefs() ok' ); -is( $result->{ 'error' }, 0, 'no error detected' ); -is( $result->{ 'nlenabled' }, 1, 'NL is enabled' ); -is( $result->{ 'endpoint' }, 1, 'an endpoint is specified' ); -is( $result->{ 'userpass' }, 1, 'username and/or password is present' ); - -=head2 NLGetFirstname and NLGetSurname - -=cut - -my $firstname = 'Firstname'; -my $surname = 'Surname'; -my $fullname = "$surname, $firstname"; -my $wrongname = "$surname $firstname"; - -is( NLGetFirstname( $fullname ), $firstname, 'can get firstname from name' ); -is( NLGetSurname( $fullname ), $surname, 'can get surname from name' ); -is( NLGetFirstname( $wrongname ), $wrongname, 'returns full string when name misses comma' ); -is( NLGetSurname( $wrongname ), $wrongname, 'returns full string when name misses comma' ); - -=head2 NLDecodePin and NLEncryptPIN - -=cut - -my $pin = '1234'; -my $hash = NLEncryptPIN( $pin ); - -is( NLEncryptPIN( $pin ), $hash, 'NLEncryptPIN works' ); -is( NLDecodePin( $hash ), $pin, 'NLDecodePin works' ); - -=head2 NLUpdateHashedPIN - -=cut - -is ( BorrowerSync->find({ 'borrowernumber' => 1 })->get_column('hashed_pin'), 'abc', 'hashed_pin is "abc"' ); -# Set a new pin -my $new_pin = 'bcd'; -ok( NLUpdateHashedPIN( 1, $new_pin ), 'NLUpdateHashedPIN runs ok' ); -# Hash the new pin and compare it to the one stored in the database -my $hashed_pin = Koha::NorwegianPatronDB::_encrypt_pin( $new_pin ); -is ( BorrowerSync->find({ 'borrowernumber' => 1 })->get_column('hashed_pin'), $hashed_pin, 'hashed_pin was updated' ); - -=head2 NLMarkForDeletion - -=cut - -is ( BorrowerSync->find({ 'borrowernumber' => 3 })->get_column('syncstatus'), 'new', 'syncstatus is "new"' ); -ok( NLMarkForDeletion( 3 ), 'NLMarkForDeletion runs ok' ); -# Check that the syncstatus was updated. Note: We will use this status later, to check syncing of deleted borrowers -is ( BorrowerSync->find({ 'borrowernumber' => 3 })->get_column('syncstatus'), 'delete', 'syncstatus is "delete"' ); - -=head2 NLGetSyncDataFromBorrowernumber - -=cut - -ok( my $sync_data = NLGetSyncDataFromBorrowernumber( 1 ), 'NLGetSyncDataFromBorrowernumber runs ok' ); -isa_ok( $sync_data, 'Koha::Schema::Result::BorrowerSync' ); -is( $sync_data->sync, 1, 'the sync is on' ); -is( $sync_data->syncstatus, 'new', 'syncstatus is "new"' ); -is( $sync_data->lastsync, '2014-03-31T12:35:14', 'lastsync is ok' ); -is( $sync_data->hashed_pin, $hashed_pin, 'hashed_pin is ok' ); - -=head1 SUBROUTINES THAT TALK TO SOAP - -=head2 NLSearch - -=cut - -my $lite = Test::MockModule->new('SOAP::Lite'); - -# Mock a successfull call to the "hent" method -$lite->mock( - hent => sub { return SOAP::Deserializer->deserialize( hent_success() )->result; } -); -ok( my $res = NLSearch( '12345678910' ), 'successfull call to NLSearch' ); -is( $res->{'antall_poster_returnert'}, 1, 'got 1 record' ); -isa_ok( $res, "Resultat" ); -isa_ok( $res->{'respons_poster'}, "LaanerListe" ); -isa_ok( $res->{'respons_poster'}[0], "Laaner" ); - -# Mock an unsuccessfull call to the "hent" method -$lite->mock( - hent => sub { return SOAP::Deserializer->deserialize( hent_failure() )->result; } -); -ok( $res = NLSearch( '12345678910' ), 'call to NLSearch with an illegal argument' ); -is( $res->{'antall_poster_returnert'}, 0, 'got 0 records' ); -isa_ok( $res, "Resultat" ); -like( $res->{'melding'}, qr/Ulovlig argument: hverken LNR eller FNR_HASH/, "got expected error message for an illegal identifier" ); - -=head2 NLSync - -=head3 New patron - -=cut - -my $borrower = Borrower->find({ 'borrowernumber' => 1 }); -$lite->mock( - nyPost => sub { return SOAP::Deserializer->deserialize( nyPost_success() )->result; } -); -is ( BorrowerSync->find({ 'borrowernumber' => 1 })->get_column('syncstatus'), 'new', 'patron is new' ); -ok ( $result = NLSync({ 'patron' => $borrower }), 'successfull call to NLSync via patron ("nyPost")' ); -is ( BorrowerSync->find({ 'borrowernumber' => 1 })->get_column('syncstatus'), 'synced', 'patron is synced' ); - -# Now do the same test, but pass in a borrowernumber, not a Koha::Schema::Result::Borrower -is ( BorrowerSync->find({ 'borrowernumber' => 4 })->get_column('syncstatus'), 'new', 'patron is new' ); -ok ( $result = NLSync({ 'borrowernumber' => 4 }), 'successfull call to NLSync via borrowernumber ("nyPost")' ); -is ( BorrowerSync->find({ 'borrowernumber' => 4 })->get_column('syncstatus'), 'synced', 'patron is synced' ); - -=head3 Edited patron - -=cut - -ok ( $borrower = Borrower->find({ 'borrowernumber' => 2 }), 'find our "edited" mock patron' ); -$lite->mock( - endre => sub { return SOAP::Deserializer->deserialize( endre_success() )->result; } -); -is ( BorrowerSync->find({ 'borrowernumber' => 2 })->get_column('syncstatus'), 'edited', 'patron is edited' ); -ok ( $result = NLSync({ 'patron' => $borrower }), 'successfull call to NLSync ("endre")' ); -is ( BorrowerSync->find({ 'borrowernumber' => 2 })->get_column('syncstatus'), 'synced', 'patron is synced' ); - -=head3 Deleted patron - -=cut - -ok ( $borrower = Borrower->find({ 'borrowernumber' => 3 }), 'find our "deleted" mock patron' ); -$lite->mock( - slett => sub { return SOAP::Deserializer->deserialize( endre_success() )->result; } -); -is ( BorrowerSync->find({ 'borrowernumber' => 3 })->get_column('syncstatus'), 'delete', 'patron is marked for deletion' ); -ok ( $result = NLSync({ 'patron' => $borrower }), 'successfull call to NLSync ("slett")' ); -is ( BorrowerSync->find({ 'borrowernumber' => 3 })->get_column('sync'), 0, 'sync is now disabled' ); - -=head2 NLGetChanged - -=cut - -# Mock a successfull call to the "soekEndret" method -$lite->mock( - soekEndret => sub { return SOAP::Deserializer->deserialize( soekEndret_success() ); } -); -ok( $res = NLGetChanged(), 'successfull call to NLGetChanged - 2 results' ); -is( $res->{'melding'}, 'OK', 'got "OK"' ); -is( $res->{'antall_poster_returnert'}, 2, 'got 2 records' ); -isa_ok( $res, "Resultat" ); -isa_ok( $res->{'respons_poster'}, "LaanerListe" ); -isa_ok( $res->{'respons_poster'}[0], "Laaner" ); - - -# Mock a successfull call to the "soekEndret" method, but with zero new records -$lite->mock( - soekEndret => sub { return SOAP::Deserializer->deserialize( soekEndret_zero_new() ); } -); -ok( $res = NLGetChanged(), 'successfull call to NLGetChanged - 0 results' ); -is( $res->{'melding'}, 'ingen treff', 'got "ingen treff"' ); -is( $res->{'antall_poster_returnert'}, 0, 'got 0 records' ); -is( $res->{'antall_treff'}, 0, 'got 0 records' ); - -=head1 SAMPLE SOAP XML RESPONSES - -These responses can be gathered by setting "outputxml()" to true on the SOAP -client: - - my $client = SOAP::Lite - ->on_action( sub { return '""';}) - ->uri('http://lanekortet.no') - ->proxy('https://fl.lanekortet.no/laanekort/fl_test.php') - ->outputxml(1); - my $response = $client->slett( $x ); - say $response; - -Pretty formatting can be achieved by piping the output from a test script -through xmllint: - - perl my_test_script.pl > xmllint --format - - -=cut - -sub slett_success { - - return <<'ENDRESPONSE'; - - - - - - true - Test Testersen (1973-08-11) er slettet fra registeret - N000106188 - 2014-06-02T16:51:58 - - - - -ENDRESPONSE - -} - -sub endre_success { - - return <<'ENDRESPONSE'; - - - - - - true - Oppdaterte felt: navn, p_adresse1, p_postnr, p_sted, p_land, fdato, fnr_hash, kjonn, pin, sist_endret, sist_endret_av - N000106188 - 2014-06-02T16:42:32 - - - - -ENDRESPONSE - -} - -sub nyPost_success { - - return <<'ENDRESPONSE'; - - - - - - true - Ny post er opprettet - N000106188 - 2014-06-02T14:10:09 - - - - -ENDRESPONSE - -} - -sub soekEndret_success { - -return <<'ENDRESPONSE'; - - - - - - true - OK - 2 - 2 - 0 - - - N000106186 - Hansen, Hanne - - - - BØDØ - no - 0 - - - - - - 0 - 0000-00-00 - - - - - - - 5180401 - 1994-04-08 - 11087395628 - F - 89308dfc85ee7a5826ae14e2d8efad1e - - 0 - 2014-04-28T15:20:38 - 5180401 - 2014-04-28T15:20:38 - 5180401 - 0000-00-00 - - - N000106184 - Enger, Magnus - Svarthammarveien 633333 - - 8015 - Bodø - no - 0 - - - - - no - 0 - 0000-00-00 - 95158548 - - - magnus@enger.priv.no - - - 5180401 - 1973-08-11 - 11087345795 - M - a632c504b8c4fba3149115cb07e0796c - - 0 - 2014-04-28T14:52:02 - 5180401 - 2014-05-13T11:01:33 - 5180401 - 0000-00-00 - - - 2014-05-16T14:44:44 - - - - -ENDRESPONSE -} - -sub soekEndret_zero_new { - return <<'ENDRESPONSE'; - - - - - - false - ingen treff - 0 - 0 - 0 - - 2014-05-20T13:02:02 - - - - -ENDRESPONSE -} - -sub hent_failure { - return <<'ENDRESPONSE'; - - - - - - false - hent: Ulovlig argument: hverken LNR eller FNR_HASH - 0 - 0 - 0 - - 2014-05-15T10:56:24 - - - - -ENDRESPONSE - -} - -sub hent_success { - -return <<'ENDRESPONSE'; - - - - - - true - OK - 1 - 1 - 0 - - - N000123456 - Test, Testersen - Bibliotekveien 6 - - 1234 - Lillevik - no - 0 - - - - - no - 0 - 0000-00-00 - - - 12345678 - test@example.com - 0 - - 2060000 - 1964-05-22 - 22056412345 - F - g345abc123dab567abc78900abc123ab - - - 2005-10-20 - 2060000 - 2013-05-13T13:51:24 - 2060000 - - 0000-00-00 - - - 2014-01-07T14:43:18 - - - - -ENDRESPONSE - -} -- 2.39.5