/[webpac2]/trunk/lib/WebPAC/Input/Koha.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/WebPAC/Input/Koha.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1232 - (show annotations)
Thu Jul 9 22:01:11 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 1742 byte(s)
dump items without marc instead of dieing

1 package WebPAC::Input::Koha;
2
3 use warnings;
4 use strict;
5
6 use DBI;
7 use MARC::Fast;
8 use base qw/WebPAC::Common/;
9 use Carp qw/confess/;
10 use Data::Dump qw/dump/;
11
12 =head1 NAME
13
14 WebPAC::Input::Koha - read MARC records from Koha
15
16 =cut
17
18 our $VERSION = '0.01';
19
20 =head1 FUNCTIONS
21
22 =head2 new
23
24 my $input = new WebPAC::Input::Koha(
25 dsn => '',
26 filter => \&code_ref,
27 }
28
29 =cut
30
31 sub new {
32 my $class = shift;
33 my $self = {@_};
34 bless($self, $class);
35
36 my $arg = {@_};
37
38 my $log = $self->_get_logger();
39
40 $log->info("opening Koha database '$arg->{dsn}'");
41
42 $self->{_dbh} = DBI->connect( $arg->{dsn}, $arg->{user}, $arg->{passwd}, { RaiseError => 1 } );
43 $self->{_sth} = $self->{_dbh}->prepare( $arg->{sql} );
44 $self->{_sth}->execute;
45
46 warn "got ", $self->{_sth}->rows, " rows for ", $arg->{sql};
47
48 open( $self->{_koha_fh}, '>', $arg->{path} ) || warn "not creating $arg->{path}: $!";
49
50 $self ? return $self : return undef;
51 }
52
53 =head2 fetch_rec
54
55 Return record with ID C<$mfn> from database
56
57 my $rec = $input->fetch_rec( $mfn );
58
59 =cut
60
61 sub fetch_rec {
62 my $self = shift;
63
64 my $mfn = shift;
65
66 my $row = $self->{_sth}->fetchrow_hashref;
67
68 if ( my $fh = $self->{_koha_fh} ) {
69 if ( my $marc = $row->{marc} ) {
70 print $fh $marc;
71 } else {
72 warn "MFN $mfn no marc in ",dump($row);
73 }
74 }
75
76 push @{$row->{'000'}}, $mfn;
77 return $row;
78 }
79
80 =head2 size
81
82 Return number of records in database
83
84 my $size = $isis->size;
85
86 =cut
87
88 sub size {
89 my $self = shift;
90 return $self->{_sth}->rows;
91 }
92
93
94 =head1 AUTHOR
95
96 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
97
98 =head1 COPYRIGHT & LICENSE
99
100 Copyright 2009 Dobrica Pavlinusic, All Rights Reserved.
101
102 This program is free software; you can redistribute it and/or modify it
103 under the same terms as Perl itself.
104
105 =cut
106
107 1;

  ViewVC Help
Powered by ViewVC 1.1.26