From d5efbcc77e77b8bb90748635833fe89e3a1ac289 Mon Sep 17 00:00:00 2001
From: Julian Maurice <julian.maurice@biblibre.com>
Date: Fri, 1 Dec 2017 15:51:16 +0000
Subject: [PATCH] Bug 19730: Use biblio_metadata.timestamp in export_records.pl

Since bug 17196, biblioitems.timestamp is not always updated after a
change in the MARC record.
Filtering should be based on biblio_metadata.timestamp instead.

Test plan:
0. Do not apply patch
1. Run export DATE="$(date '+%F %T')"
2. Edit a biblio record, modify a field that is not mapped to a DB
   column, so biblio_metadata.timestamp will be modified but not
   biblioitems.timestamp
3. Run misc/export_records.pl --date="$DATE"
4. Verify that koha.mrc is empty
5. Apply patch
6. Run misc/export_records.pl --date="$DATE"
7. Verify koha.mrc contains the record you modified
---
 misc/export_records.pl | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/misc/export_records.pl b/misc/export_records.pl
index 23cc9f1109..6e363686a3 100755
--- a/misc/export_records.pl
+++ b/misc/export_records.pl
@@ -104,16 +104,16 @@ if ( $record_type eq 'bibs' ) {
     if ( $timestamp ) {
         push @record_ids, $_->{biblionumber} for @{
             $dbh->selectall_arrayref(q| (
-                SELECT biblionumber
-                FROM biblioitems
+                SELECT biblio_metadata.biblionumber
+                FROM biblio_metadata
                   LEFT JOIN items USING(biblionumber)
-                WHERE biblioitems.timestamp >= ?
+                WHERE biblio_metadata.timestamp >= ?
                   OR items.timestamp >= ?
             ) UNION (
-                SELECT biblionumber
-                FROM biblioitems
+                SELECT biblio_metadata.biblionumber
+                FROM biblio_metadata
                   LEFT JOIN deleteditems USING(biblionumber)
-                WHERE biblioitems.timestamp >= ?
+                WHERE biblio_metadata.timestamp >= ?
                   OR deleteditems.timestamp >= ?
             ) |, { Slice => {} }, ( $timestamp ) x 4 );
         };
-- 
2.11.0