/[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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1234 by dpavlin, Fri Jul 10 13:53:28 2009 UTC revision 1365 by dpavlin, Wed May 4 13:44:07 2011 UTC
# Line 15  WebPAC::Input::Koha - read MARC records Line 15  WebPAC::Input::Koha - read MARC records
15    
16  =cut  =cut
17    
18  our $VERSION = '0.01';  our $VERSION = '0.03';
19    
20  =head1 FUNCTIONS  =head1 FUNCTIONS
21    
22  =head2 new  =head2 new
23    
24    my $input = new WebPAC::Input::Koha(    my $input = new WebPAC::Input::Koha(
25          dsn => '',          dsn    => $ENV{KOHA_DSN}, # 'dbi:mysql:database=koha;host=koha.example.com',
26          filter => \&code_ref,          user   => $ENV{KOHA_USER},
27            passwd => $ENV{KOHA_PASSWD},
28    }    }
29    
30  =cut  =cut
# Line 36  sub new { Line 37  sub new {
37          my $arg = {@_};          my $arg = {@_};
38    
39          my $log = $self->_get_logger();          my $log = $self->_get_logger();
40            $log->debug( 'arg = ', dump($arg) );
41    
42          if ( -e $arg->{path} ) {          if ( -e $arg->{path} ) {
43                  $log->info("Koha marc dump ", $arg->{path}, " exists");                  $log->info("Koha marc dump ", $arg->{path}, " exists");
44                  $self->{_koha_size} = 0;                  $self->{_koha_size} = 0;
45          } else {          } else {
46    
47                    $arg->{dsn}    ||= $ENV{KOHA_DSN};
48                    $arg->{user}   ||= $ENV{KOHA_USER};
49                    $arg->{passwd} ||= $ENV{KOHA_PASSWD};
50                    $arg->{sql}    ||= 'select biblionumber, marc from biblioitems order by biblionumber asc';
51                    $arg->{sql}    .= ' limit ' . $arg->{limit} if $arg->{limit};
52                    $arg->{sql}    .= ' offset ' . $arg->{offset} if $arg->{offset};
53    
54                  $log->info("opening Koha database '$arg->{dsn}'");                  $log->info("opening Koha database '$arg->{dsn}'");
55    
56                  $self->{_dbh} = DBI->connect( $arg->{dsn}, $arg->{user}, $arg->{passwd}, { RaiseError => 1 } );                  $self->{_dbh} = DBI->connect( $arg->{dsn}, $arg->{user}, $arg->{passwd}, {
57                            RaiseError => 1,
58                            #mysql_enable_utf8 => 1, # not really needed
59                    } );
60                  $self->{_sth} = $self->{_dbh}->prepare( $arg->{sql} );                  $self->{_sth} = $self->{_dbh}->prepare( $arg->{sql} );
61                  $self->{_sth}->execute;                  $self->{_sth}->execute;
62                  $self->{_koha_size} = $self->{_sth}->rows;                  $self->{_koha_size} = $self->{_sth}->rows;
# Line 73  sub fetch_rec { Line 85  sub fetch_rec {
85    
86          my $row = $self->{_sth}->fetchrow_hashref;          my $row = $self->{_sth}->fetchrow_hashref;
87    
88            sub _error {
89                    my ( $mfn, $error, $row ) = @_;
90                    $self->_get_logger()->error( "MFN $mfn $error ", dump($row) );
91            }
92    
93          if ( my $fh = $self->{_koha_fh} ) {          if ( my $fh = $self->{_koha_fh} ) {
94                  if ( my $marc = $row->{marc} ) {                  if ( my $marc = $row->{marc} ) {
95                          print $fh $marc;                          if ( length($marc) != substr( $marc, 0, 5 ) ) {
96                                    _error $mfn => "wrong length " . length($marc), $row;
97                            } elsif ( $marc !~ /\x1E\x1D$/ ) {
98                                    _error $mfn => "wrong end", $row;
99                            } else {
100                                    print $fh $marc;
101                            }
102                  } else {                  } else {
103                          warn "MFN $mfn no marc in ",dump($row);                          _error $mfn => "no marc",$row;
104                  }                  }
105          }          }
106    
# Line 95  Return number of records in database Line 118  Return number of records in database
118    
119  sub size {  sub size {
120          my $self = shift;          my $self = shift;
121          return $self->{_koha_size};          return $self->{_koha_size} + $self->{offset};
122  }  }
123    
124    

Legend:
Removed from v.1234  
changed lines
  Added in v.1365

  ViewVC Help
Powered by ViewVC 1.1.26