@@ -, +, @@ state why they were not. --- C4/Items.pm | 3 + misc/cronjobs/delete_records_via_leader.pl | 92 ++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 0 deletions(-) create mode 100755 misc/cronjobs/delete_records_via_leader.pl --- a/C4/Items.pm +++ a/C4/Items.pm @@ -2264,6 +2264,9 @@ Exported function (core API) for deleting an item record in Koha if there no cur sub DelItemCheck { my ( $dbh, $biblionumber, $itemnumber ) = @_; + + $dbh ||= C4::Context->dbh; + my $error; my $countanalytics=GetAnalyticsCount($itemnumber); --- a/misc/cronjobs/delete_records_via_leader.pl +++ a/misc/cronjobs/delete_records_via_leader.pl @@ -0,0 +1,92 @@ +#!/usr/bin/perl + +#----------------------------------- +# Copyright 2013 ByWater Solutions +# +# 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. +# +# 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. +# +# 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. +#----------------------------------- + +use Modern::Perl; + +BEGIN { + + # find Koha's Perl modules + # test carefully before changing this + use FindBin; + eval { require "$FindBin::Bin/../kohalib.pl" }; +} + +use Getopt::Long; + +use C4::Biblio; +use C4::Items; +use Koha::Database; + +my $delete_items; +my $confirm; +my $test; +my $verbose; +my $help; + +GetOptions( + 'i|di|delete-items' => \$delete_items, + 'c|confirm' => \$confirm, + 't|test' => \$test, + 'v|verbose' => \$verbose, + 'h|help' => \$help, +); + +if ( $help || !$confirm ) { + say qq{ +delete_records_via_leader.pl - Attempt to delete any MARC records where the leader character 5 equals 'd' +usage: delete_records_via_leader.pl --confirm --verbose [--test] +This script has the following parameters : + -h --help: Prints this message + -c --confirm: Script will do nothing without this parameter + -v --verbose: Be verbose + -t --test: Test mode, does not delete records + -i --delete-items: Try deleting items before deleting record. + Records with items cannot be deleted. +}; + exit(); +} + +my $schema = Koha::Database->new()->schema(); +my @biblioitems = + $schema->resultset('Biblioitem')->search( { marc => { LIKE => '_____d%' } } ); + +foreach my $biblioitem (@biblioitems) { + my $biblionumber = $biblioitem->get_column('biblionumber'); + + say "Working on " + . $biblioitem->biblionumber->title() + . " ( $biblionumber )" + if $verbose; + + if ($delete_items) { + say "Attempting to delete items for this record" if $verbose; + foreach my $item ( $biblioitem->items() ) { + my $error = $test ? "Test mode enabled" : DelItemCheck( undef, $biblionumber, $item->itemnumber() ); + $error = undef if ( $error eq '1' ); + + say "ERROR - Cannot delete item: barcode " . $item->barcode() . ", itemnumber " . $item->itemnumber() . ": $error" if $error; + } + + } + + my $error = $test ? q{Test mode enabled} : DelBiblio($biblionumber); + say "ERROR - Cannot delete biblionumber $biblionumber: $error" if $error; +} --