|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
#----------------------------------- |
| 4 |
# Copyright 2013 ByWater Solutions |
| 5 |
# |
| 6 |
# This file is part of Koha. |
| 7 |
# |
| 8 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 9 |
# terms of the GNU General Public License as published by the Free Software |
| 10 |
# Foundation; either version 2 of the License, or (at your option) any later |
| 11 |
# version. |
| 12 |
# |
| 13 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 14 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 15 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License along |
| 18 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 19 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 |
#----------------------------------- |
| 21 |
|
| 22 |
use Modern::Perl; |
| 23 |
|
| 24 |
BEGIN { |
| 25 |
|
| 26 |
# find Koha's Perl modules |
| 27 |
# test carefully before changing this |
| 28 |
use FindBin; |
| 29 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
| 30 |
} |
| 31 |
|
| 32 |
use Getopt::Long; |
| 33 |
|
| 34 |
use C4::Biblio; |
| 35 |
use C4::Items; |
| 36 |
use Koha::Database; |
| 37 |
|
| 38 |
my $delete_items; |
| 39 |
my $confirm; |
| 40 |
my $test; |
| 41 |
my $verbose; |
| 42 |
my $help; |
| 43 |
|
| 44 |
GetOptions( |
| 45 |
'i|di|delete-items' => \$delete_items, |
| 46 |
'c|confirm' => \$confirm, |
| 47 |
't|test' => \$test, |
| 48 |
'v|verbose' => \$verbose, |
| 49 |
'h|help' => \$help, |
| 50 |
); |
| 51 |
|
| 52 |
if ( $help || !$confirm ) { |
| 53 |
say |
| 54 |
q{delete_fixed_field_5.pl - Attempt to delete any records with the leader character 5 equals 'd'}; |
| 55 |
say q{usage: delete_fixec_field_5.pl --confirm --verbose}; |
| 56 |
exit(); |
| 57 |
} |
| 58 |
|
| 59 |
my $schema = Koha::Database->new()->schema(); |
| 60 |
my @biblioitems = |
| 61 |
$schema->resultset('Biblioitem')->search( { marc => { LIKE => '_____d%' } } ); |
| 62 |
|
| 63 |
foreach my $biblioitem (@biblioitems) { |
| 64 |
my $biblionumber = $biblioitem->get_column('biblionumber'); |
| 65 |
|
| 66 |
say "Working on " |
| 67 |
. $biblioitem->biblionumber->title() |
| 68 |
. " ( $biblionumber )" |
| 69 |
if $verbose; |
| 70 |
|
| 71 |
if ($delete_items) { |
| 72 |
say "Attempting to delete items for this record" if $verbose; |
| 73 |
foreach my $item ( $biblioitem->items() ) { |
| 74 |
my $error = $test ? "Test mode enabled" : DelItemCheck( undef, $biblionumber, $item->itemnumber() ); |
| 75 |
$error = undef if ( $error eq '1' ); |
| 76 |
|
| 77 |
say "ERROR - Cannot delete item: barcode " . $item->barcode() . ", itemnumber " . $item->itemnumber() . ": $error" if $error; |
| 78 |
} |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
my $error = $test ? q{Test mode enabled} : DelBiblio($biblionumber); |
| 83 |
say "ERROR - Cannot delete biblionumber $biblionumber: $error" if $error; |
| 84 |
} |