Bug 19725: OAI-PMH - Use biblio_metadata.timestamp
authorJulian Maurice <julian.maurice@biblibre.com>
Fri, 1 Dec 2017 15:21:56 +0000 (15:21 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 21 Dec 2017 16:21:11 +0000 (13:21 -0300)
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:
1. prove t/db_dependent/OAI/Server.t
2. Verify that it SUCCEEDS

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/OAI/Server/ListBase.pm
t/db_dependent/OAI/Server.t

index 0c7c56a..92af1c3 100644 (file)
@@ -58,7 +58,7 @@ sub GetRecords {
     # first deleted records ($deleted == 1), then normal records ($deleted == 0)
     STAGELOOP:
     for ( ; $deleted >= 0; $deleted-- ) {
-        my $table = $deleted ? 'deletedbiblioitems' : 'biblioitems';
+        my $table = $deleted ? 'deletedbiblio_metadata' : 'biblio_metadata';
         my $sql = "
             SELECT biblionumber
             FROM $table
@@ -103,7 +103,7 @@ sub GetRecords {
             $sql = "
                 SELECT MAX(timestamp)
                 FROM (
-                    SELECT timestamp FROM deletedbiblioitems WHERE biblionumber = ?
+                    SELECT timestamp FROM deletedbiblio_metadata WHERE biblionumber = ?
                     UNION
                     SELECT timestamp FROM deleteditems WHERE biblionumber = ?
                 ) bis
@@ -112,7 +112,7 @@ sub GetRecords {
             $sql = "
                 SELECT MAX(timestamp)
                 FROM (
-                    SELECT timestamp FROM biblioitems WHERE biblionumber = ?
+                    SELECT timestamp FROM biblio_metadata WHERE biblionumber = ?
                     UNION
                     SELECT timestamp FROM deleteditems WHERE biblionumber = ?
                     UNION
index fa2d2a7..def867b 100644 (file)
@@ -85,7 +85,6 @@ foreach my $index ( 0 .. NUMBER_OF_MARC_RECORDS - 1 ) {
     $sth->execute($biblionumber);
     my $timestamp = $sth->fetchrow_array . 'Z';
     $timestamp =~ s/ /T/;
-    $timestamp = manipulate_timestamp( $index, $biblionumber, $timestamp );
     $record = GetMarcBiblio({ biblionumber => $biblionumber });
     $record = XMLin($record->as_xml_record);
     push @header, { datestamp => $timestamp, identifier => "TEST:$biblionumber" };
@@ -353,6 +352,7 @@ subtest 'Bug 19725: OAI-PMH ListRecords and ListIdentifiers should use biblio_me
     my $record = GetMarcBiblio({biblionumber => $biblionumber});
     $record->append_fields(MARC::Field->new(999, '', '', z => '_'));
     ModBiblio($record, $biblionumber);
+    $oaidc[0]->{header}->{datestamp} = $from;
 
     test_query(
         'ListRecords oai_dc with parameter from',
@@ -364,15 +364,3 @@ subtest 'Bug 19725: OAI-PMH ListRecords and ListIdentifiers should use biblio_me
 };
 
 $schema->storage->txn_rollback;
-
-sub manipulate_timestamp {
-# This eliminates waiting a few seconds in order to get a higher timestamp
-# Works only for 60 records..
-    my ( $index, $bibno, $timestamp ) = @_;
-    return $timestamp if $timestamp !~ /\d{2}Z/;
-    my $secs = sprintf( "%02d", $index );
-    $timestamp =~ s/\d{2}Z/${secs}Z/;
-    $dbh->do("UPDATE biblioitems SET timestamp=? WHERE biblionumber=?", undef,
-        ( $timestamp, $bibno ));
-    return $timestamp;
-}