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