Bug 23217: Remove SQL error when batch patron mod and not attribute selected
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sat, 29 Jun 2019 15:55:17 +0000 (10:55 -0500)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 26 Jul 2019 15:15:17 +0000 (16:15 +0100)
commit0b2a9b5872c72ee6b0f17d32e20c8e59231f03f3
tree87c1d20effdbce4ac6f5a945405ccaf447de4d73
parentfbeb22802f41f8daf99498303146d1916c851507
Bug 23217: Remove SQL error when batch patron mod and not attribute selected

On the batch patron modification tool, if no patron attribute is selected then
an UPDATE query will be executed anyway. Indeed the form will send a
an empty "patron_attributes" parameter. We need to handle it.

Test plan:
Go to the patron modification tool
Enter a cardnumber
Change a field (like city)
Do not change anything in the patron's attributes
Save
=> Without this patch a SQL error is generated:

DBD::mysql::st execute failed: Cannot add or update a child row: a foreign key constraint fails (`koha_kohadev`.`borrower_attributes`, CONSTRAINT `borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`) ON DELETE CASCADE ON UPDATE CASCADE) [for Statement "INSERT INTO borrower_attributes SET attribute = ?, code = ?, borrowernumber = ?" with ParamValues: 0=undef, 1="", 2="51"] at /home/vagrant/kohaclone/C4/Members/Attributes.pm line 287.

=> With this patch applied you will not see it

You should also test that you can modify patron's attributes ;)

Signed-off-by: Hayley Mapley <hayleymapley@catalyst.net.nz>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
tools/modborrowers.pl