Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBI Exception on RequestItem #12

Open
BibliothekTHWildau opened this issue Jun 14, 2022 · 7 comments
Open

DBI Exception on RequestItem #12

BibliothekTHWildau opened this issue Jun 14, 2022 · 7 comments

Comments

@BibliothekTHWildau
Copy link

Using NCIP server with Koha 21.11 and sending a RequestItem message using ItemIdentifierValue (instead of BibliographicRecordIdentifier) ends up with the following error:

DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Cannot add or update a child row: a foreign key constraint fails (koha_hsbwildau.reserves, CONSTRAINT reserves_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE) at /usr/share/koha/lib/Koha/Object.pm line 170
This errors seems to occur due to a missing biblionumber in Koha.pm call of AddReserve.
When i set the missing biblionumber with $item->biblionumber it works.

Example request:

 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.niso.org/2008/ncip http://www.niso.org/schemas/ncip/v2_0/ncip_v2_0.xsd">
<ns:RequestItem>
<ns:UserId>
<ns:UserIdentifierValue>userid</ns:UserIdentifierValue>
</ns:UserId>
 <ns:ItemId>
 <ns:ItemIdentifierValue>123456789</ns:ItemIdentifierValue>
 </ns:ItemId>
 <ns:RequestType>PreBook</ns:RequestType>
 <!--<ns:RequestType>Order</ns:RequestType>-->
 <ns:RequestScopeType>ItemId</ns:RequestScopeType>
 <ns:AcknowledgedFeeAmount>
 <ns:CurrencyCode/>
 <ns:MonetaryValue>01</ns:MonetaryValue>
 </ns:AcknowledgedFeeAmount>
 </ns:RequestItem>
 </NCIPMessage>
@kylemhall
Copy link
Member

What branch of the NCIP server are you running?

@BibliothekTHWildau
Copy link
Author

I am running the master branch.

@kylemhall
Copy link
Member

Can you try switching to the v21.11 branch and see if that works for you?

https://github.com/bywatersolutions/ncip-server/tree/v21.11

@BibliothekTHWildau
Copy link
Author

when using v21.11 i get the following error:

No valid librarian found for userenv_borrowernumber ncip! Please update your configuration! at /var/lib/koha/hsbwildau/ncip-server/lib/NCIP/ILS/Koha.pm line 135.
DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Cannot add or update a child row: a foreign key constraint fails (`koha_hsbwildau`.`reserves`, CONSTRAINT `reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE) at /usr/share/koha/lib/Koha/Object.pm line 170

I managed to resolve "No valid librarian" warning by changing ? Koha::Patrons->find( $config->{userenv_borrowernumber} )
to ? Koha::Patrons->find( { cardnumber => $config->{userenv_borrowernumber} } ) in Koha.pm (line 133) but the error remains the same.
I hope this is not a result of the warnings in about koha -> system information tab.

@kylemhall
Copy link
Member

kylemhall commented Jun 15, 2022

@BibliothekTHWildau the NCIP server now needs a Koha staff account to "act as" for certain actions in Koha. I would recommend creating a special staff account just for NCIP, then setting the borrowernumber in the NCIP config. The option is userenv_borrowernumber under koha like this:

koha:
  # Borrowernumber of librarian to act as. Best practice is to create an "NCIP Librarian" account
  userenv_borrowernumber: 1

If you find your config.yml it should already have that line in there.

@BibliothekTHWildau
Copy link
Author

@kylemhall I already had a staff user with a carnumber 'ncip'. When running
Koha::Patrons->find( $config->{userenv_borrowernumber} ), which in my case would be
Koha::Patrons->find( 'ncip' ), it returns undef.
Only running Koha::Patrons->find( { cardnumber => 'ncip' } ) works in my case.

But the DBI Exception issue remains the same.
My solution for avoiding a DBI Exception is setting the missing $biblionumber in Koha.pm request sub:

if (!$biblionumber && $item->biblionumber) {
  $biblionumber = $item->biblionumber;
}

my $can_reserve =
      $itemnumber
      ? CanItemBeReserved( $borrowernumber, $itemnumber )->{status}
      : CanBookBeReserved( $borrowernumber, $biblionumber )->{status};

and then calling AddReserve

@kylemhall
Copy link
Member

Ah, that setting needs to be the borrowernumber of the user, not the userid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants