New script:
[koha.git] / export / export_filtered.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 ## This script allows you to export a rel_2_2 bibliographic db in
19 #MARC21 format from the command line.
20 #
21
22 use strict;
23 require Exporter;
24 use C4::Auth;
25 use C4::Output;    # contains gettemplate
26 use C4::Biblio;
27 use CGI;
28 use C4::Auth;
29
30 my $outfile = $ARGV[0];
31 open( OUT, ">$outfile" ) or die $!;
32 my $query                = new CGI;
33 # my $StartingBiblionumber = $query->param("StartingBiblionumber");
34 # my $EndingBiblionumber   = $query->param("EndingBiblionumber");
35 my $StartingBiblionumber = $ARGV[1];
36 my $EndingBiblionumber   = $ARGV[2];
37 my $dbh                  = C4::Context->dbh;
38 my $sth;
39
40 warn "start ->".$StartingBiblionumber;
41 warn "stop ->".$EndingBiblionumber;
42
43     my $query =
44          my $query = "
45         SELECT biblionumber
46         FROM   biblioitems
47         WHERE  biblionumber >=?
48         AND   biblionumber <=?
49         AND NOT EXISTS (
50                 SELECT DISTINCT (biblio_auth_number) FROM zebraqueue
51                 WHERE ( biblioitems.biblionumber  =  zebraqueue.biblio_auth_number)
52                 AND (zebraqueue.server = 'biblioserver' 
53                         OR zebraqueue.server = '')
54                 )
55         ORDER BY biblionumber
56         ";
57     $sth = $dbh->prepare($query);
58     $sth->execute( $StartingBiblionumber, $EndingBiblionumber );
59 binmode(OUT, 'utf8');
60 my $i = 0;
61 while ( my ($biblionumber) = $sth->fetchrow ) {
62     my $record = GetMarcBiblio($biblionumber);
63     print $i++ . "\n";
64
65     print OUT $record->as_usmarc();
66 }
67
68 close(OUT);