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 qq{ |
54 |
delete_records_via_leader.pl - Attempt to delete any MARC records where the leader character 5 equals 'd' |
55 |
usage: delete_records_via_leader.pl --confirm --verbose [--test] |
56 |
This script has the following parameters : |
57 |
-h --help: Prints this message |
58 |
-c --confirm: Script will do nothing without this parameter |
59 |
-v --verbose: Be verbose |
60 |
-t --test: Test mode, does not delete records |
61 |
-i --delete-items: Try deleting items before deleting record. |
62 |
Records with items cannot be deleted. |
63 |
}; |
64 |
exit(); |
65 |
} |
66 |
|
67 |
my $schema = Koha::Database->new()->schema(); |
68 |
my @biblioitems = |
69 |
$schema->resultset('Biblioitem')->search( { marc => { LIKE => '_____d%' } } ); |
70 |
|
71 |
foreach my $biblioitem (@biblioitems) { |
72 |
my $biblionumber = $biblioitem->get_column('biblionumber'); |
73 |
|
74 |
say "Working on " |
75 |
. $biblioitem->biblionumber->title() |
76 |
. " ( $biblionumber )" |
77 |
if $verbose; |
78 |
|
79 |
if ($delete_items) { |
80 |
say "Attempting to delete items for this record" if $verbose; |
81 |
foreach my $item ( $biblioitem->items() ) { |
82 |
my $error = $test ? "Test mode enabled" : DelItemCheck( undef, $biblionumber, $item->itemnumber() ); |
83 |
$error = undef if ( $error eq '1' ); |
84 |
|
85 |
say "ERROR - Cannot delete item: barcode " . $item->barcode() . ", itemnumber " . $item->itemnumber() . ": $error" if $error; |
86 |
} |
87 |
|
88 |
} |
89 |
|
90 |
my $error = $test ? q{Test mode enabled} : DelBiblio($biblionumber); |
91 |
say "ERROR - Cannot delete biblionumber $biblionumber: $error" if $error; |
92 |
} |