Bug 5786 - Move AllowOnShelfHolds and OPACItemHolds system prefs to the Circulation...
[koha.git] / misc / batchdeletebiblios.pl
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4 use Getopt::Long;
5 use Pod::Usage;
6 use IO::File;
7
8 use C4::Biblio;
9
10 my ($help, $files);
11 GetOptions(
12     'h|help' => \$help,
13 );
14
15 pod2usage(1) if $help or not @ARGV;
16
17 for my $file ( @ARGV ) {
18     say "Find biblionumber in file $file";
19     my $fh;
20     open($fh, '<', $file) or say "Error: '$file' $!" and next;
21
22     while ( <$fh> ) {
23         my $biblionumber = $_;
24         $biblionumber =~ s/$1/\n/g if $biblionumber =~ m/(\r\n?|\n\r?)/;
25         chomp $biblionumber;
26         my $dbh = C4::Context->dbh;
27         next if not $biblionumber =~ /^\d*$/;
28         print "Delete biblionumber $biblionumber ";
29         my $error;
30         eval {
31             $error = DelBiblio $biblionumber;
32         };
33         if ( $@ or $error) {
34             say "KO $@ ($! | $error)";
35         } else {
36             say "OK";
37         }
38     }
39 }
40
41 exit(0);
42
43 __END__
44
45 =head1 NAME
46
47 batchdeletebiblios.pl
48
49 =head1 SYNOPSIS
50
51 ./batchdeletebiblio.pl file1 [file2 ... filen]
52
53 This script batch deletes biblios which contain a biblionumber present in file passed in parameter.
54 If one biblio has items, it is not deleted.
55
56 =head1 OPTIONS
57
58 =over 8
59
60 =item B<-h|--help>
61
62 prints this help message
63
64 =back
65
66 =head1 AUTHOR
67
68 Jonathan Druart <jonathan.druart@biblibre.com>
69
70 =head1 COPYRIGHT
71
72 Copyright 2012 BibLibre
73
74 =head1 LICENSE
75
76 This file is part of Koha.
77
78 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
79 Foundation; either version 2 of the License, or (at your option) any later version.
80
81 You should have received a copy of the GNU General Public License along
82 with Koha; if not, write to the Free Software Foundation, Inc.,
83 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
84
85 =head1 DISCLAIMER OF WARRANTY
86
87 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
88 A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
89
90 =cut