|
Lines 36-46
use C4::Log qw( cronlogaction );
Link Here
|
| 36 |
use HTTP::OAI; |
36 |
use HTTP::OAI; |
| 37 |
use HTTP::OAI::Metadata::OAI_DC; |
37 |
use HTTP::OAI::Metadata::OAI_DC; |
| 38 |
use Koha::DateUtils qw( dt_from_string ); |
38 |
use Koha::DateUtils qw( dt_from_string ); |
| 39 |
use Koha::OaiServers; |
39 |
use Koha::OAIServers; |
| 40 |
use Koha::Import::Oaipmh::Biblio; |
40 |
use Koha::Import::OAI::Biblio; |
| 41 |
use Koha::Import::Oaipmh::Biblios; |
41 |
use Koha::Import::OAI::Biblios; |
| 42 |
use Koha::Import::Oaipmh::Authority; |
42 |
use Koha::Import::OAI::Authority; |
| 43 |
use Koha::Import::Oaipmh::Authorities; |
43 |
use Koha::Import::OAI::Authorities; |
| 44 |
use Koha::XSLT::Base; |
44 |
use Koha::XSLT::Base; |
| 45 |
use MARC::File::XML; |
45 |
use MARC::File::XML; |
| 46 |
use MARC::Record; |
46 |
use MARC::Record; |
|
Lines 61-79
my $strp = DateTime::Format::Strptime->new(
Link Here
|
| 61 |
our $xslt_engine = Koha::XSLT::Base->new; |
61 |
our $xslt_engine = Koha::XSLT::Base->new; |
| 62 |
|
62 |
|
| 63 |
=head2 new |
63 |
=head2 new |
| 64 |
|
64 |
$harvester = Koha::OAI::Client::Harvester->new( { server => $server, days => $days, force => $force, logger => \&logger } ); |
| 65 |
$harvester = Koha::OAI::Client::Harvester->new( { server => $server, verbose => $verbose, days => $days, force => $force } ); |
|
|
| 66 |
|
65 |
|
| 67 |
New instance of Koha::OAI::Client::Harvester |
66 |
New instance of Koha::OAI::Client::Harvester |
| 68 |
|
67 |
|
| 69 |
C<$server> An OAI repository (Koha::OaiServer) |
68 |
C<$server> An OAI repository (Koha::OAIServer) |
| 70 |
|
|
|
| 71 |
C<$verbose> print log messages to stdout when enabled |
| 72 |
|
69 |
|
| 73 |
C<$days> number of days to harvest from (optional) |
70 |
C<$days> number of days to harvest from (optional) |
| 74 |
|
71 |
|
| 75 |
C<$force> force harvesting (ignore records datestamps) |
72 |
C<$force> force harvesting (ignore records datestamps) |
| 76 |
|
73 |
|
|
|
74 |
C<$logger> a callback function to handle logs (optional) |
| 75 |
|
| 77 |
=cut |
76 |
=cut |
| 78 |
|
77 |
|
| 79 |
sub new { |
78 |
sub new { |
|
Lines 250-256
sub processRecord {
Link Here
|
| 250 |
} |
249 |
} |
| 251 |
my $imported_record; |
250 |
my $imported_record; |
| 252 |
if ( $server->recordtype eq "biblio" ) { |
251 |
if ( $server->recordtype eq "biblio" ) { |
| 253 |
$imported_record = Koha::Import::Oaipmh::Biblios->find( |
252 |
$imported_record = Koha::Import::OAI::Biblios->find( |
| 254 |
{ |
253 |
{ |
| 255 |
repository => $server->endpoint, |
254 |
repository => $server->endpoint, |
| 256 |
identifier => $oai_record->identifier, |
255 |
identifier => $oai_record->identifier, |
|
Lines 258-264
sub processRecord {
Link Here
|
| 258 |
} |
257 |
} |
| 259 |
); |
258 |
); |
| 260 |
} else { |
259 |
} else { |
| 261 |
$imported_record = Koha::Import::Oaipmh::Authorities->find( |
260 |
$imported_record = Koha::Import::OAI::Authorities->find( |
| 262 |
{ |
261 |
{ |
| 263 |
repository => $server->endpoint, |
262 |
repository => $server->endpoint, |
| 264 |
identifier => $oai_record->identifier, |
263 |
identifier => $oai_record->identifier, |
|
Lines 318-324
sub processRecord {
Link Here
|
| 318 |
if ( $server->recordtype eq "biblio" ) { |
317 |
if ( $server->recordtype eq "biblio" ) { |
| 319 |
my ( $biblionumber, $biblioitemnumber ) = AddBiblio($marcrecord); |
318 |
my ( $biblionumber, $biblioitemnumber ) = AddBiblio($marcrecord); |
| 320 |
$self->printlog( $oai_record->identifier . " added, biblionumber: $biblionumber" ); |
319 |
$self->printlog( $oai_record->identifier . " added, biblionumber: $biblionumber" ); |
| 321 |
Koha::Import::Oaipmh::Biblio->new( |
320 |
Koha::Import::OAI::Biblio->new( |
| 322 |
{ |
321 |
{ |
| 323 |
repository => $server->endpoint, |
322 |
repository => $server->endpoint, |
| 324 |
identifier => $oai_record->identifier, |
323 |
identifier => $oai_record->identifier, |
|
Lines 330-336
sub processRecord {
Link Here
|
| 330 |
} else { |
329 |
} else { |
| 331 |
my $authid = AddAuthority( $marcrecord, "", GuessAuthTypeCode($marcrecord) ); |
330 |
my $authid = AddAuthority( $marcrecord, "", GuessAuthTypeCode($marcrecord) ); |
| 332 |
$self->printlog( $oai_record->identifier . " added, authid: $authid" ); |
331 |
$self->printlog( $oai_record->identifier . " added, authid: $authid" ); |
| 333 |
Koha::Import::Oaipmh::Authority->new( |
332 |
Koha::Import::OAI::Authority->new( |
| 334 |
{ |
333 |
{ |
| 335 |
repository => $server->endpoint, |
334 |
repository => $server->endpoint, |
| 336 |
identifier => $oai_record->identifier, |
335 |
identifier => $oai_record->identifier, |
|
Lines 350-364
sub processRecord {
Link Here
|
| 350 |
|
349 |
|
| 351 |
=head2 $self->printlog |
350 |
=head2 $self->printlog |
| 352 |
|
351 |
|
| 353 |
This method adds a cronlog and prints to stdout if verbose is enabled |
352 |
This method gives the caller an opportunity to handle log messages |
| 354 |
|
353 |
|
| 355 |
=cut |
354 |
=cut |
| 356 |
|
355 |
|
| 357 |
sub printlog { |
356 |
sub printlog { |
| 358 |
my ( $self, $message ) = @_; |
357 |
my ( $self, $message ) = @_; |
|
|
358 |
return unless $self->{logger}; |
| 359 |
$message = $self->{server}->servername . ": " . $message; |
359 |
$message = $self->{server}->servername . ": " . $message; |
| 360 |
print $message . "\n" if ( $self->{verbose} ); |
360 |
$self->{logger}->($message); |
| 361 |
cronlogaction( { info => $message } ); |
|
|
| 362 |
} |
361 |
} |
| 363 |
|
362 |
|
| 364 |
1; |
363 |
1; |