use Koha::NorwegianPatronDB;


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.)



This is included to set the username and password used by SOAP::Lite.


Check that sysprefs relevant to NL are set.


Search the NL patron database.

SOAP call: "hent" (fetch)


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:

Required values for new and edited:


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


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.


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:

<yazgfs> ... <config> ... <nlkey>xyz</nlkey> </config> </yazgfs>


Takes a plain text PIN as argument, returns the encrypted PIN, according to the NL specs.

    my $encrypted_pin = NLEncryptPIN( $plain_text_pin );


Takes two arguments:

Hashes the password and saves it in borrower_sync.hashed_pin.


Takes a plain text PIN and returns the encrypted version, according to the NL specs.


Takes a borrowernumber as argument, returns a Koha::Schema::Result::BorrowerSync object.

    my $syncdata = NLGetSyncDataFromBorrowernumber( $borrowernumber );


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


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


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


Takes a soap result object as input and returns a formatted string containing SOAP error data.


Convert a SOAP object of type "Laaner" into a hash that can be sent to AddMember or ModMember.


Convert a patron (in the form of a Koha::Schema::Result::Borrower) into a SOAP object that can be sent to NL.


None by default.


Magnus Enger <digitalutvikling@gmail.com>