From fbac859ae24529795e766a3fd5fae3254604b73b Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 5 Jun 2013 10:44:18 -0400 Subject: [PATCH] Bug 10421 - [SIGNED-OFF] Add cron script to delete deleted records This script will batch delete all records where the leader's record status ( position 5 ) is set to 'd' ( Deleted ). Test Plan: 1) Edit a few records, set the leader 05 to 'd' for deleted 2) Run delete_deleted_records.pl 3) Records that are deletable should be deleted! Signed-off-by: Magnus Enger I can confirm that NORMARC uses leader position 5 in the same way as MARC21, and as far as I can see from this document, UNIMARC does too: http://archive.ifla.org/VI/8/unimarc-concise-bibliographic-format-2008.pdf -h and --help as well as running the script without arguments give a nice "help" message -c and --confirm makes the script do its job Records with leader position 5 = d are deleted. If there are items attached to the record, an error is reported: Deleting biblionumber 562 ... ERROR: ( | This Biblio has items attached, please delete them first before deleting this biblio ) Looks good! --- misc/cronjobs/delete_deleted_records.pl | 89 +++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 misc/cronjobs/delete_deleted_records.pl diff --git a/misc/cronjobs/delete_deleted_records.pl b/misc/cronjobs/delete_deleted_records.pl new file mode 100755 index 0000000..224789e --- /dev/null +++ b/misc/cronjobs/delete_deleted_records.pl @@ -0,0 +1,89 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Getopt::Long; +use Pod::Usage; + +use C4::Biblio; +use C4::Context; + +my ($help, $confirm); +GetOptions( + 'h|help' => \$help, + 'c|confirm' => \$confirm, +); + +pod2usage(1) if ( $help || !$confirm ); + +my $dbh = C4::Context->dbh; + +my $sql = q{ SELECT biblionumber FROM biblioitems WHERE SUBSTR(marcxml,INSTR(marcxml, "")+8+5,1) = "d" }; + +my @biblionumbers = @{ $dbh->selectcol_arrayref($sql) }; + +foreach my $biblionumber ( @biblionumbers ) { + print "Deleting biblionumber $biblionumber ... "; + my $error; + eval { + $error = DelBiblio $biblionumber; + }; + if ( $@ or $error) { + say "ERROR: $@ ($! | $error)"; + } else { + say "DONE!"; + } +} + +exit(0); + +__END__ + +=head1 NAME + +delete_deleted_recordss.pl + +=head1 SYNOPSIS + +./delete_deleted_records.pl --confirm + +This script will batch delete all records where the leader's record status ( position 5 ) is set to 'd' ( Deleted ). + +=head1 OPTIONS + +=over 8 + +=item B<-h|--help> + +prints this help message + +=item B<-c|--confirm> + +Confirm you really want to batch delete deleted records + +=back + +=head1 AUTHOR + +Kyle M Hall + +=head1 COPYRIGHT + +Copyright 2013 Kyle M Hall + +=head1 LICENSE + +This file is part of Koha. + +Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later version. + +You should have received a copy of the GNU General Public License along +with Koha; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +=head1 DISCLAIMER OF WARRANTY + +Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +=cut -- 1.7.10.4