add agerestriction
[koha-eprints] / mkp-marc.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use autodie;
7 use DBI;
8 use Data::Dump qw/dump/;
9
10 my $limit = $ENV{LIMIT} || 9999;
11
12 my $dsn = 'DBI:mysql:dbname=koha_ffzg';
13 my $sql = qq{
14 select
15         biblionumber,itemnumber,title,
16         agerestriction,
17         marc
18 from items
19         join biblioitems using (biblionumber)
20         join biblio using (biblionumber)
21 where location = 'MKP'
22         or homebranch = 'MKP'
23         or agerestriction > 0
24 limit $limit
25 };
26
27 my $path = "/dev/shm/$1" if $dsn =~ m/=(.+)/;
28
29 open(my $marc_fh, '>', "$path.marc");
30 open(my $tsv_fh,  '>', "$path.tsv");
31
32 warn "# dsn = $dsn";
33 my $dbh = DBI->connect( $dsn, '', '', { RaiseError => 1 } ) || die $DBI::errstr;
34 #$dbh->do( qq{ set client_encoding='utf-8' } );
35
36 warn "# sql $sql";
37 my $sth = $dbh->prepare( $sql );
38 $sth->execute();
39
40 warn "# ", $sth->rows,"\n";
41 my @cols = @{ $sth->{NAME} };
42 print $tsv_fh "#", join("\t", 'offset', @cols), "\n";
43
44 my $i = 1;
45
46 while ( my $row = $sth->fetchrow_hashref ) {
47
48         warn "# row = ",dump( $row );
49
50         my $rec = tell $marc_fh;
51         foreach ( @cols ) {
52                 my $d = $row->{$_};
53
54                 if ( m/marc/ ) {
55                         print $marc_fh $row->{marc};
56                         next;
57                 }
58
59                 $rec .= "\t$d";
60
61         }
62
63         print $tsv_fh "$rec\n";
64 }
65
66 warn "# rows ", $sth->rows,"\n";
67 system "ls -al $path*";
68 system "rsync -v $path* 10.60.0.82:/tmp/";