Bug 14596 - GetMarcBiblio corrupts biblioitemnumber if they are out of sync
Summary: GetMarcBiblio corrupts biblioitemnumber if they are out of sync
Status: RESOLVED DUPLICATE of bug 10961
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P3 major (vote)
Assignee: Stéphane Delaune
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-23 13:47 UTC by Stéphane Delaune
Modified: 2015-07-23 14:51 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stéphane Delaune 2015-07-23 13:47:52 UTC
biblionumbers and biblioitemnumbers are out of sync in some libraries and this creates bug with misc/batchRebuildBiblioTables.pl (and probably others some features).

To reproduce :
- change AUTO_INCREMENT in TABLE biblioitems to be different than biblionumber (eg. if last biblionumber is 5000 : "SET FOREIGN_KEY_CHECKS=OFF;ALTER TABLE biblioitems AUTO_INCREMENT = 5002;SET FOREIGN_KEY_CHECKS=ON;")

- create one or more new bib records (with items)

- see mysql records :
SELECT biblio.biblionumber AS bibbiblionumber, biblioitems.biblionumber AS bibitemsbiblionumber, biblioitems.biblioitemnumber AS bibitemsbiblioitemnumber, items.biblionumber AS itemsbiblionumber, items.biblioitemnumber AS itemsbiblioitemnumber, biblioitems.publishercode, biblio.title, items.barcode FROM biblioitems JOIN biblio ON biblio.biblionumber=biblioitems.biblionumber JOIN items ON biblioitems.biblionumber=items.biblionumber WHERE biblio.biblionumber>5000;

#before batchRebuildBiblioTables
+-----------------+----------------------+--------------------------+-------------------+-----------------------+----------------+--------------+-----------------+
| bibbiblionumber | bibitemsbiblionumber | bibitemsbiblioitemnumber | itemsbiblionumber | itemsbiblioitemnumber | publishercode  | title        | barcode         |
+-----------------+----------------------+--------------------------+-------------------+-----------------------+----------------+--------------+-----------------+
|            5001 |                 5001 |                     5002 |              5001 |                  5002 | editeur test 0 | Titre test 0 | barcode testa 0 |
|            5002 |                 5002 |                     5003 |              5002 |                  5003 | editeur test 1 | Titre test 1 | barcode testa 1 |
|            5003 |                 5003 |                     5004 |              5003 |                  5004 | editeur test 2 | Titre test 2 | barcode testa 2 |
|            5004 |                 5004 |                     5005 |              5004 |                  5005 | editeur test 3 | Titre test 3 | barcode testa 3 |
|            5005 |                 5005 |                     5006 |              5005 |                  5006 | editeur test 4 | Titre test 4 | barcode testa 4 |
|            5006 |                 5006 |                     5007 |              5006 |                  5007 | editeur test 5 | Titre test 5 | barcode testa 5 |
|            5007 |                 5007 |                     5008 |              5007 |                  5008 | editeur test 6 | Titre test 6 | barcode testa 6 |
|            5008 |                 5008 |                     5009 |              5008 |                  5009 | editeur test 7 | Titre test 7 | barcode testa 7 |
|            5009 |                 5009 |                     5010 |              5009 |                  5010 | editeur test 8 | Titre test 8 | barcode testa 8 |
|            5010 |                 5010 |                     5011 |              5010 |                  5011 | editeur test 9 | Titre test 9 | barcode testa 9 |
+-----------------+----------------------+--------------------------+-------------------+-----------------------+----------------+--------------+-----------------+

- run ~/src/misc/batchRebuildBiblioTables.pl -c

- see mysql records :
SELECT biblio.biblionumber AS bibbiblionumber, biblioitems.biblionumber AS bibitemsbiblionumber, biblioitems.biblioitemnumber AS bibitemsbiblioitemnumber, items.biblionumber AS itemsbiblionumber, items.biblioitemnumber AS itemsbiblioitemnumber, biblioitems.publishercode, biblio.title, items.barcode FROM biblioitems JOIN biblio ON biblio.biblionumber=biblioitems.biblionumber JOIN items ON biblioitems.biblionumber=items.biblionumber WHERE biblio.biblionumber>5000;

#after batchRebuildBiblioTables
+-----------------+----------------------+--------------------------+-------------------+-----------------------+----------------+--------------+-----------------+
| bibbiblionumber | bibitemsbiblionumber | bibitemsbiblioitemnumber | itemsbiblionumber | itemsbiblioitemnumber | publishercode  | title        | barcode         |
+-----------------+----------------------+--------------------------+-------------------+-----------------------+----------------+--------------+-----------------+
|            5002 |                 5002 |                     5002 |              5002 |                  5003 | editeur test 1 | Titre test 1 | barcode testa 1 |
|            5003 |                 5003 |                     5003 |              5003 |                  5004 | editeur test 2 | Titre test 2 | barcode testa 2 |
|            5004 |                 5004 |                     5004 |              5004 |                  5005 | editeur test 3 | Titre test 3 | barcode testa 3 |
|            5005 |                 5005 |                     5005 |              5005 |                  5006 | editeur test 4 | Titre test 4 | barcode testa 4 |
|            5006 |                 5006 |                     5006 |              5006 |                  5007 | editeur test 5 | Titre test 5 | barcode testa 5 |
|            5007 |                 5007 |                     5007 |              5007 |                  5008 | editeur test 6 | Titre test 6 | barcode testa 6 |
|            5008 |                 5008 |                     5008 |              5008 |                  5009 | editeur test 7 | Titre test 7 | barcode testa 7 |
|            5009 |                 5009 |                     5009 |              5009 |                  5010 | editeur test 8 | Titre test 8 | barcode testa 8 |
|            5010 |                 5010 |                     5010 |              5010 |                  5011 | editeur test 9 | Titre test 9 | barcode testa 9 |
|            5010 |                 5010 |                     5011 |              5010 |                  5011 | editeur test 9 | Titre test 9 | barcode testa 9 |
+-----------------+----------------------+--------------------------+-------------------+-----------------------+----------------+--------------+-----------------+

result : 
- first desynchronized biblionumber disappeared
- biblioitems.biblioitemnumber have been updated to be identical to biblionumber
- for one biblionumber : biblioitemnumber is not the same in biblioitems and items table

cause : 

. in C4::Biblio : GetMarcBiblio calls _koha_marc_update_bib_ids with the wrong arguments : ("$record, '', $biblionumber, $biblionumber") instead of ("$record, $frameworkcode, $biblionumber, $biblioitemnumber")
Comment 1 Tomás Cohen Arazi 2015-07-23 13:51:39 UTC
I think no piece of code should assume that biblionumber and biblioitemnumber are in sync. They are just id's on tables.
Comment 2 Stéphane Delaune 2015-07-23 14:51:40 UTC

*** This bug has been marked as a duplicate of bug 10961 ***