From 1152da9db09c2e9602eba3791db0e2c906b0cdfa Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 5 Jun 2013 10:44:18 -0400 Subject: [PATCH] Bug 10421 - 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! --- misc/cronjobs/delete_deleted_records.pl | 89 +++++++++++++++++++++++++++++++ 1 files changed, 89 insertions(+), 0 deletions(-) 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..8762687 --- /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.2.5