From 93c4dd3d3ec54b0eb71b8edf70f8b1685ffa2277 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Thu, 6 Jan 2022 14:48:36 +0100 Subject: [PATCH] BUG 29811 : add timestamp option on authority record type According to the timestamp option for bibs record type I added the timestamp option for authority records. Timestamp is already present in database on field "modification_time" Test Plan : 1 - Be sure to have authority record type for easiest test create one 2 - Execute script export_records.pl in your koha/misc directory and choose a date (example yesterday if you just created an authority right now).(see export_records.pl -h for help) 3 - Timestamp option has no effect on authority record type 4 - Execute script again but choose the date of tomorrow for example 5 - Same result 6 - Apply this patch 7 - Play again steps 2 and 4 8 - On step 2 you will see only your authorities created today (because script show you authority has changes since the date you choose in option) and for step 4 you must see an empty file. --- misc/export_records.pl | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/misc/export_records.pl b/misc/export_records.pl index 32658cb8c8..39878b502f 100755 --- a/misc/export_records.pl +++ b/misc/export_records.pl @@ -100,9 +100,6 @@ if ( $output_format eq 'csv' and not $csv_profile_id ) { pod2usage(q|Define a csv profile to export in CSV|); } -if ( $timestamp and $record_type ne 'bibs' ) { - pod2usage(q|--timestamp can only be used with biblios|); -} if ( $record_type ne 'bibs' and $record_type ne 'auths' ) { pod2usage(q|--record_type is not valid|); @@ -210,20 +207,31 @@ if ( $record_type eq 'bibs' ) { } } elsif ( $record_type eq 'auths' ) { - my $conditions = { - ( $starting_authid or $ending_authid ) - ? ( - authid => { - ( $starting_authid ? ( '>=' => $starting_authid ) : () ), - ( $ending_authid ? ( '<=' => $ending_authid ) : () ), - } - ) - : (), - ( $authtype ? ( authtypecode => $authtype ) : () ), - }; - # Koha::MetadataRecord::Authority is not a Koha::Object... - my $authorities = Koha::Database->new->schema->resultset('AuthHeader')->search( $conditions ); - @record_ids = map { $_->authid } $authorities->all; + if ( $timestamp ) { + push @record_ids, $_->{authid} for @{ + $dbh->selectall_arrayref(q| ( + SELECT authid + FROM auth_header + WHERE modification_time >= ? + ) |, { Slice => {} }, $timestamp ); + }; + } + else { + my $conditions = { + ( $starting_authid or $ending_authid ) + ? ( + authid => { + ( $starting_authid ? ( '>=' => $starting_authid ) : () ), + ( $ending_authid ? ( '<=' => $ending_authid ) : () ), + } + ) + : (), + ( $authtype ? ( authtypecode => $authtype ) : () ), + }; + # Koha::MetadataRecord::Authority is not a Koha::Object... + my $authorities = Koha::Database->new->schema->resultset('AuthHeader')->search( $conditions ); + @record_ids = map { $_->authid } $authorities->all; + } } @record_ids = uniq @record_ids; -- 2.25.1