From f687c419cf342dc0e50bc620f0f3f0ef12e5d38b Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
Date: Wed, 9 Aug 2017 10:03:09 -0300
Subject: [PATCH] Bug 19016: Check and fix 'biblioitems'

This patch adds 'biblioitems' to the list of tables to be evaluated and fixed.

To test the problem exists:
- reset_all
- Run:
  $ sudo koha-mysql kohadev
  > SELECT biblionumber FROM biblio ORDER BY biblionumber DESC LIMIT 1;
- From the staff UI, delete the biblio with that biblionumber
- Restart mysql:
  $ sudo systemctl restart mysql.service
- Add a new biblio record
- Run:
  $ sudo koha-shell kohadev
 k> cd kohaclone
 k> misc/cronjobs/cleanup_database.pl --list-corrupted-data
=> FAIL: biblioitems issue is not higlighted
- Apply this patch
- Run:
  $ sudo koha-shell kohadev
 k> cd kohaclone
 k> misc/cronjobs/cleanup_database.pl --list-corrupted-data
=> SUCCESS: biblioitems issue is highlighted

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
---
 misc/cronjobs/cleanup_database.pl | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl
index b1967b6..54ffcf2 100755
--- a/misc/cronjobs/cleanup_database.pl
+++ b/misc/cronjobs/cleanup_database.pl
@@ -561,6 +561,10 @@ sub GetCorruptedData {
         q|SELECT b.biblionumber FROM biblio b JOIN deletedbiblio db ON b.biblionumber=db.biblionumber|,
         { Slice => {} }
     );
+    my $biblioitems = $dbh->selectall_arrayref(
+        q|SELECT b.biblioitemnumber FROM biblioitems b JOIN deletedbiblioitems db ON b.biblioitemnumber=db.biblioitemnumber|,
+        { Slice => {} }
+    );
     my $items = $dbh->selectall_arrayref(
         q|SELECT i.itemnumber FROM items i JOIN deleteditems di ON i.itemnumber=di.itemnumber|,
         { Slice => {} }
@@ -590,6 +594,11 @@ sub GetCorruptedData {
             : ()
         ),
         (
+            @$biblioitems
+            ? { entity => 'biblioitems', col_name => 'biblioitemnumber', rows => $biblioitems, tables => ['biblioitems', 'deletedbiblioitems'] }
+            : ()
+        ),
+        (
             @$items ? { entity => 'items', col_name => 'itemnumber', rows => $items, tables => [ 'items', 'deleteditems' ] }
             : ()
         ),
-- 
2.7.4