1 package WebPAC::Input::Koha;
8 use base qw/WebPAC::Common/;
10 use Data::Dump qw/dump/;
14 WebPAC::Input::Koha - read MARC records from Koha
18 our $VERSION = '0.01';
24 my $input = new WebPAC::Input::Koha(
38 my $log = $self->_get_logger();
40 if ( -e $arg->{path} ) {
41 $log->info("Koha marc dump ", $arg->{path}, " exists");
42 $self->{_koha_size} = 0;
45 $arg->{dsn} ||= 'dbi:mysql:database=koha';
46 $arg->{user} ||= $ENV{KOHA_USER};
47 $arg->{passwd} ||= $ENV{KOHA_PASSWD},
48 $arg->{sql} ||= 'select biblioitemnumber as mfn, marc from biblioitems';
50 $log->info("opening Koha database '$arg->{dsn}'");
52 $self->{_dbh} = DBI->connect( $arg->{dsn}, $arg->{user}, $arg->{passwd}, { RaiseError => 1 } );
53 $self->{_sth} = $self->{_dbh}->prepare( $arg->{sql} );
54 $self->{_sth}->execute;
55 $self->{_koha_size} = $self->{_sth}->rows;
57 warn "got ", $self->{_koha_size}, " rows for ", $arg->{sql};
59 open( $self->{_koha_fh}, '>', $arg->{path} ) || die "can't create $arg->{path}: $!";
63 $self ? return $self : return undef;
68 Return record with ID C<$mfn> from database
70 my $rec = $input->fetch_rec( $mfn );
79 my $row = $self->{_sth}->fetchrow_hashref;
81 if ( my $fh = $self->{_koha_fh} ) {
82 if ( my $marc = $row->{marc} ) {
85 warn "MFN $mfn no marc in ",dump($row);
89 push @{$row->{'000'}}, $mfn;
95 Return number of records in database
97 my $size = $isis->size;
103 return $self->{_koha_size};
109 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
111 =head1 COPYRIGHT & LICENSE
113 Copyright 2009 Dobrica Pavlinusic, All Rights Reserved.
115 This program is free software; you can redistribute it and/or modify it
116 under the same terms as Perl itself.