Bug 26327: Add exec flag on .t file
[koha.git] / misc / batchdeletebiblios.pl
blob3ae5cd96830ccfa6cb4b9ee1c5ec399c3ac07d5f
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use Getopt::Long;
5 use Pod::Usage;
6 use IO::File;
8 use Koha::Script;
9 use C4::Biblio;
11 my $help;
12 GetOptions(
13 'h|help' => \$help,
16 pod2usage(1) if $help or not @ARGV;
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;
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;
34 if ( $@ or $error) {
35 say "KO $@ ($! | $error)";
36 } else {
37 say "OK";
42 exit(0);
44 __END__
46 =head1 NAME
48 batchdeletebiblios.pl
50 =head1 SYNOPSIS
52 ./batchdeletebiblio.pl file1 [file2 ... filen]
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.
57 =head1 OPTIONS
59 =over 8
61 =item B<-h|--help>
63 prints this help message
65 =back
67 =head1 AUTHOR
69 Jonathan Druart <jonathan.druart@biblibre.com>
71 =head1 COPYRIGHT
73 Copyright 2012 BibLibre
75 =head1 LICENSE
77 This file is part of Koha.
79 Koha is free software; you can redistribute it and/or modify it
80 under the terms of the GNU General Public License as published by
81 the Free Software Foundation; either version 3 of the License, or
82 (at your option) any later version.
84 Koha is distributed in the hope that it will be useful, but
85 WITHOUT ANY WARRANTY; without even the implied warranty of
86 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87 GNU General Public License for more details.
89 You should have received a copy of the GNU General Public License
90 along with Koha; if not, see <http://www.gnu.org/licenses>.
92 =head1 DISCLAIMER OF WARRANTY
94 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
95 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
97 =cut