Bugzilla – Attachment 162575 Details for
Bug 36201
Add -days_old and -months_old arguments for misc/export_records.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36201: Add -days_old and -months_old arguments to misc/export_records.pl
Bug-36201-Add--daysold-and--monthsold-arguments-to.patch (text/plain), 7.96 KB, created by
Alex Buckley
on 2024-02-29 03:57:46 UTC
(
hide
)
Description:
Bug 36201: Add -days_old and -months_old arguments to misc/export_records.pl
Filename:
MIME Type:
Creator:
Alex Buckley
Created:
2024-02-29 03:57:46 UTC
Size:
7.96 KB
patch
obsolete
>From 4f0e9df1b40dafc39b1715e51fb3d606df8c2cff Mon Sep 17 00:00:00 2001 >From: Alex Buckley <alexbuckley@catalyst.net.nz> >Date: Mon, 26 Feb 2024 09:19:13 +0000 >Subject: [PATCH] Bug 36201: Add -days_old and -months_old arguments to > misc/export_records.pl > >Limit exported records based on the biblio.datecreated using the >-days_old and -months_old arguments. > >Test plan: >1. Remove all biblios in your Koha catalogue, then create 10 bibliographic records - in the Koha database set 6 of the biblios to have a biblio.datecreated 50 days ago > >2. Apply patches and restart services > >3. In koha-shell run the following command: >perl misc/export_records.pl --months_old=1 --format=marc --record-type=bibs --filename=/tmp/test.mrc > >4. Check the /tmp/test.mrc and confirm it has 4 biblios in it > >5. In the koha-shell run the following command: >perl misc/export_records.pl --days_old=31 --format=marc --record-type=bibs --filename=/tmp/test2.mrc > >6. Check the /tmp/test2.mrc and confirm it also has 4 biblios in it > >7. In the koha-shell run the following command: >perl misc/export_records.pl --days_old=52 --format=marc --record-type=bibs --filename=/tmp/test3.mrc > >8. Check the /tmp/test3.mrc and confirm it has 10 biblios in it > >9. In the koha-shell run the following command: >perl misc/export_records.pl --format=marc --record-type=bibs --filename=/tmp/all.mrc > >10. Check the /tmp/all.mrc and confirm it also has 10 biblios in it > >11. Try running the export_records.pl script with a variety of other >arguments and confirm it works as expected > >Sponsored-By: Department of Corrections, New Zealand >--- > misc/export_records.pl | 115 ++++++++++++++++++++++++++++++++--------- > 1 file changed, 90 insertions(+), 25 deletions(-) > >diff --git a/misc/export_records.pl b/misc/export_records.pl >index 051657aa762..c1d366c5171 100755 >--- a/misc/export_records.pl >+++ b/misc/export_records.pl >@@ -53,6 +53,8 @@ my ( > $ending_callnumber, > $start_accession, > $end_accession, >+ $days_old, >+ $months_old, > $marc_conditions, > $help > ); >@@ -77,6 +79,8 @@ GetOptions( > 'ending_callnumber=s' => \$ending_callnumber, > 'start_accession=s' => \$start_accession, > 'end_accession=s' => \$end_accession, >+ 'days_old=s' => \$days_old, >+ 'months_old=s' => \$months_old, > 'marc_conditions=s' => \$marc_conditions, > 'h|help|?' => \$help > ) || pod2usage(1); >@@ -109,9 +113,29 @@ if ( $deleted_barcodes and $record_type ne 'bibs' ) { > pod2usage(q|--deleted_barcodes can only be used with biblios|); > } > >+if ( $days_old and $record_type ne 'bibs' ) { >+ pod2usage(q|days_old can only be used with biblios|); >+} >+ >+if ( $months_old and $record_type ne 'bibs' ) { >+ pod2usage(q|months_old can only be used with biblios|); >+} >+ > $start_accession = dt_from_string( $start_accession ) if $start_accession; > $end_accession = dt_from_string( $end_accession ) if $end_accession; > >+# Fetch date in the past >+my $date; >+if ( $days_old || $months_old ) { >+ $date = DateTime->now(); >+ if ( $days_old ) { >+ $date->subtract( days => $days_old ); >+ } elsif ( $months_old ) { >+ $date->set_day(1); >+ $date->subtract( months => $months_old ); >+ } >+} >+ > # Parse marc conditions > my @marc_conditions; > if ($marc_conditions) { >@@ -139,31 +163,62 @@ my @record_ids; > $timestamp = ($timestamp) ? output_pref({ dt => dt_from_string($timestamp), dateformat => 'iso', dateonly => 0, }): ''; > > if ( $record_type eq 'bibs' ) { >- if ( $timestamp ) { >- if (!$dont_export_items) { >- push @record_ids, $_->{biblionumber} for @{ >- $dbh->selectall_arrayref(q| ( >- SELECT biblio_metadata.biblionumber >- FROM biblio_metadata >- LEFT JOIN items USING(biblionumber) >- WHERE biblio_metadata.timestamp >= ? >- OR items.timestamp >= ? >- ) UNION ( >- SELECT biblio_metadata.biblionumber >- FROM biblio_metadata >- LEFT JOIN deleteditems USING(biblionumber) >- WHERE biblio_metadata.timestamp >= ? >- OR deleteditems.timestamp >= ? >- ) |, { Slice => {} }, ( $timestamp ) x 4 ); >- }; >- } else { >- push @record_ids, $_->{biblionumber} for @{ >- $dbh->selectall_arrayref(q| ( >- SELECT biblio_metadata.biblionumber >- FROM biblio_metadata >- WHERE biblio_metadata.timestamp >= ? >- ) |, { Slice => {} }, $timestamp ); >- }; >+ if ( $timestamp || $date ) { >+ if ( $timestamp ) { >+ if (!$dont_export_items) { >+ push @record_ids, $_->{biblionumber} for @{ >+ $dbh->selectall_arrayref(q| ( >+ SELECT biblio_metadata.biblionumber >+ FROM biblio_metadata >+ LEFT JOIN items USING(biblionumber) >+ LEFT JOIN biblio USING(biblionumber) >+ WHERE biblio_metadata.timestamp >= ? >+ OR items.timestamp >= ? >+ ) UNION ( >+ SELECT biblio_metadata.biblionumber >+ FROM biblio_metadata >+ LEFT JOIN deleteditems USING(biblionumber) >+ LEFT JOIN biblio USING(biblionumber) >+ WHERE biblio_metadata.timestamp >= ? >+ OR deleteditems.timestamp >= ? >+ ) |, { Slice => {} }, ( $timestamp ) x 4 ); >+ }; >+ } else { >+ push @record_ids, $_->{biblionumber} for @{ >+ $dbh->selectall_arrayref(q| ( >+ SELECT biblio_metadata.biblionumber >+ FROM biblio_metadata >+ WHERE biblio_metadata.timestamp >= ? >+ ) |, { Slice => {} }, $timestamp ); >+ }; >+ } >+ } elsif ( $date ) { >+ if (!$dont_export_items) { >+ push @record_ids, $_->{biblionumber} for @{ >+ $dbh->selectall_arrayref(q| ( >+ SELECT biblio_metadata.biblionumber >+ FROM biblio_metadata >+ LEFT JOIN items USING(biblionumber) >+ LEFT JOIN biblio USING(biblionumber) >+ WHERE biblio.datecreated >= ? >+ ) UNION ( >+ SELECT biblio_metadata.biblionumber >+ FROM biblio_metadata >+ LEFT JOIN deleteditems USING(biblionumber) >+ LEFT JOIN biblio USING(biblionumber) >+ WHERE biblio.datecreated >= ? >+ ) |, { Slice => {} }, ( $date ) x 2 ); >+ }; >+ } else { >+ push @record_ids, $_->{biblionumber} for @{ >+ $dbh->selectall_arrayref(q| ( >+ SELECT biblio_metadata.biblionumber >+ FROM biblio_metadata >+ LEFT JOIN biblio USING(biblionumber) >+ WHERE biblio.datecreated >= ? >+ ) |, { Slice => {} }, $date ); >+ }; >+ } > } > } else { > my $conditions = { >@@ -395,6 +450,16 @@ Print a brief help message. > "exists(<marc_target>)" will include marc records where > no <marc_target> exists. > >+=item B<--days_old> >+ >+ --days_old=NUMBER OF DAYS Export biblio with a datecreated less than the number of days defined. >+ This can only be used to export biblio records. >+ >+=item B<--months_old> >+ >+ --months_old=NUMBER OF MONTHS Export biblio with a datecreated less than the number of months defined. >+ This can only be used to export biblio records. >+ > =back > > =head1 AUTHOR >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36201
: 162575