Lines 152-158
sub new {
Link Here
|
152 |
MaxCount => C4::Context->preference("OAI-PMH:MaxCount"), |
152 |
MaxCount => C4::Context->preference("OAI-PMH:MaxCount"), |
153 |
granularity => 'YYYY-MM-DD', |
153 |
granularity => 'YYYY-MM-DD', |
154 |
earliestDatestamp => '0001-01-01', |
154 |
earliestDatestamp => '0001-01-01', |
155 |
deletedRecord => 'no', |
155 |
deletedRecord => C4::Context->preference("OAI-PMH:DeletedRecord") || 'no', |
156 |
); |
156 |
); |
157 |
|
157 |
|
158 |
# FIXME - alas, the description element is not so simple; to validate |
158 |
# FIXME - alas, the description element is not so simple; to validate |
Lines 252-257
sub new {
Link Here
|
252 |
|
252 |
|
253 |
# __END__ C4::OAI::Record |
253 |
# __END__ C4::OAI::Record |
254 |
|
254 |
|
|
|
255 |
package C4::OAI::DeletedRecord; |
256 |
|
257 |
use strict; |
258 |
use warnings; |
259 |
use HTTP::OAI; |
260 |
use HTTP::OAI::Metadata::OAI_DC; |
261 |
|
262 |
use base ("HTTP::OAI::Record"); |
263 |
|
264 |
sub new { |
265 |
my ($class, $timestamp, $setSpecs, %args) = @_; |
266 |
|
267 |
my $self = $class->SUPER::new(%args); |
268 |
|
269 |
$timestamp =~ s/ /T/, $timestamp .= 'Z'; |
270 |
$self->header( new HTTP::OAI::Header( |
271 |
status => 'deleted', |
272 |
identifier => $args{identifier}, |
273 |
datestamp => $timestamp, |
274 |
) ); |
275 |
|
276 |
foreach my $setSpec (@$setSpecs) { |
277 |
$self->header->setSpec($setSpec); |
278 |
} |
279 |
|
280 |
return $self; |
281 |
} |
282 |
|
283 |
# __END__ C4::OAI::DeletedRecord |
284 |
|
255 |
|
285 |
|
256 |
|
286 |
|
257 |
package C4::OAI::GetRecord; |
287 |
package C4::OAI::GetRecord; |
Lines 278-284
sub new {
Link Here
|
278 |
my ($biblionumber) = $args{identifier} =~ /^$prefix(.*)/; |
308 |
my ($biblionumber) = $args{identifier} =~ /^$prefix(.*)/; |
279 |
$sth->execute( $biblionumber ); |
309 |
$sth->execute( $biblionumber ); |
280 |
my ($marcxml, $timestamp); |
310 |
my ($marcxml, $timestamp); |
|
|
311 |
my $deleted = 0; |
281 |
unless ( ($marcxml, $timestamp) = $sth->fetchrow ) { |
312 |
unless ( ($marcxml, $timestamp) = $sth->fetchrow ) { |
|
|
313 |
$sth = $dbh->prepare(" |
314 |
SELECT biblionumber, timestamp |
315 |
FROM deletedbiblio |
316 |
WHERE biblionumber=? " ); |
317 |
$sth->execute( $biblionumber ); |
318 |
|
319 |
unless ( ($marcxml, $timestamp) = $sth->fetchrow ) { |
320 |
|
282 |
return HTTP::OAI::Response->new( |
321 |
return HTTP::OAI::Response->new( |
283 |
requestURL => $repository->self_url(), |
322 |
requestURL => $repository->self_url(), |
284 |
errors => [ new HTTP::OAI::Error( |
323 |
errors => [ new HTTP::OAI::Error( |
Lines 286-293
sub new {
Link Here
|
286 |
message => "There is no biblio record with this identifier", |
325 |
message => "There is no biblio record with this identifier", |
287 |
) ] , |
326 |
) ] , |
288 |
); |
327 |
); |
|
|
328 |
} else { |
329 |
$deleted = 1; |
330 |
} |
289 |
} |
331 |
} |
290 |
|
|
|
291 |
my $oai_sets = GetOAISetsBiblio($biblionumber); |
332 |
my $oai_sets = GetOAISetsBiblio($biblionumber); |
292 |
my @setSpecs; |
333 |
my @setSpecs; |
293 |
foreach (@$oai_sets) { |
334 |
foreach (@$oai_sets) { |
Lines 295-303
sub new {
Link Here
|
295 |
} |
336 |
} |
296 |
|
337 |
|
297 |
#$self->header( HTTP::OAI::Header->new( identifier => $args{identifier} ) ); |
338 |
#$self->header( HTTP::OAI::Header->new( identifier => $args{identifier} ) ); |
298 |
$self->record( C4::OAI::Record->new( |
339 |
($deleted == 1) ? $self->record( C4::OAI::DeletedRecord->new( |
|
|
340 |
$timestamp, \@setSpecs, %args ) ) |
341 |
: $self->record( C4::OAI::Record->new( |
299 |
$repository, $marcxml, $timestamp, \@setSpecs, %args ) ); |
342 |
$repository, $marcxml, $timestamp, \@setSpecs, %args ) ); |
300 |
|
|
|
301 |
return $self; |
343 |
return $self; |
302 |
} |
344 |
} |
303 |
|
345 |
|
Lines 328-346
sub new {
Link Here
|
328 |
} |
370 |
} |
329 |
my $max = $repository->{koha_max_count}; |
371 |
my $max = $repository->{koha_max_count}; |
330 |
my $sql = " |
372 |
my $sql = " |
331 |
SELECT biblioitems.biblionumber, biblioitems.timestamp |
373 |
(SELECT biblioitems.biblionumber, timestamp |
332 |
FROM biblioitems |
374 |
FROM biblioitems |
333 |
"; |
375 |
"; |
334 |
$sql .= " JOIN oai_sets_biblios ON biblioitems.biblionumber = oai_sets_biblios.biblionumber " if defined $set; |
376 |
$sql .= " JOIN oai_sets_biblios ON biblioitems.biblionumber = oai_sets_biblios.biblionumber " if defined $set; |
335 |
$sql .= " WHERE timestamp >= ? AND timestamp <= ? "; |
377 |
$sql .= " WHERE timestamp >= ? AND timestamp <= ? "; |
336 |
$sql .= " AND oai_sets_biblios.set_id = ? " if defined $set; |
378 |
$sql .= " AND oai_sets_biblios.set_id = ? " if defined $set; |
337 |
$sql .= " |
379 |
$sql .= ") UNION |
|
|
380 |
(SELECT deletedbiblio.biblionumber, timestamp FROM deletedbiblio"; |
381 |
$sql .= " JOIN oai_sets_biblios ON deletedbiblio.biblionumber = oai_sets_biblios.biblionumber " if defined $set; |
382 |
$sql .= " WHERE DATE(timestamp) >= ? AND DATE(timestamp) <= ? "; |
383 |
$sql .= " AND oai_sets_biblios.set_id = ? " if defined $set; |
384 |
|
385 |
$sql .= ") ORDER BY biblionumber |
338 |
LIMIT " . ($max+1) . " |
386 |
LIMIT " . ($max+1) . " |
339 |
OFFSET $token->{offset} |
387 |
OFFSET $token->{offset} |
340 |
"; |
388 |
"; |
341 |
my $sth = $dbh->prepare( $sql ); |
389 |
my $sth = $dbh->prepare( $sql ); |
342 |
my @bind_params = ($token->{'from_arg'}, $token->{'until_arg'}); |
390 |
my @bind_params = ($token->{'from_arg'}, $token->{'until_arg'}); |
343 |
push @bind_params, $set->{'id'} if defined $set; |
391 |
push @bind_params, $set->{'id'} if defined $set; |
|
|
392 |
push @bind_params, ($token->{'from'}, $token->{'until'}); |
393 |
push @bind_params, $set->{'id'} if defined $set; |
344 |
$sth->execute( @bind_params ); |
394 |
$sth->execute( @bind_params ); |
345 |
|
395 |
|
346 |
my $count = 0; |
396 |
my $count = 0; |
Lines 485-504
sub new {
Link Here
|
485 |
} |
535 |
} |
486 |
my $max = $repository->{koha_max_count}; |
536 |
my $max = $repository->{koha_max_count}; |
487 |
my $sql = " |
537 |
my $sql = " |
488 |
SELECT biblioitems.biblionumber, biblioitems.marcxml, biblioitems.timestamp |
538 |
(SELECT biblioitems.biblionumber, marcxml, timestamp |
489 |
FROM biblioitems |
539 |
FROM biblioitems |
490 |
"; |
540 |
"; |
491 |
$sql .= " JOIN oai_sets_biblios ON biblioitems.biblionumber = oai_sets_biblios.biblionumber " if defined $set; |
541 |
$sql .= " JOIN oai_sets_biblios ON biblioitems.biblionumber = oai_sets_biblios.biblionumber " if defined $set; |
492 |
$sql .= " WHERE timestamp >= ? AND timestamp <= ? "; |
542 |
$sql .= " WHERE timestamp >= ? AND timestamp <= ? "; |
493 |
$sql .= " AND oai_sets_biblios.set_id = ? " if defined $set; |
543 |
$sql .= " AND oai_sets_biblios.set_id = ? " if defined $set; |
494 |
$sql .= " |
544 |
$sql .= ") UNION |
|
|
545 |
(SELECT deletedbiblio.biblionumber, null as marcxml, timestamp FROM deletedbiblio"; |
546 |
$sql .= " JOIN oai_sets_biblios ON deletedbiblio.biblionumber = oai_sets_biblios.biblionumber " if defined $set; |
547 |
$sql .= " WHERE DATE(timestamp) >= ? AND DATE(timestamp) <= ? "; |
548 |
$sql .= " AND oai_sets_biblios.set_id = ? " if defined $set; |
549 |
|
550 |
$sql .= ") ORDER BY biblionumber |
495 |
LIMIT " . ($max + 1) . " |
551 |
LIMIT " . ($max + 1) . " |
496 |
OFFSET $token->{offset} |
552 |
OFFSET $token->{offset} |
497 |
"; |
553 |
"; |
498 |
|
|
|
499 |
my $sth = $dbh->prepare( $sql ); |
554 |
my $sth = $dbh->prepare( $sql ); |
500 |
my @bind_params = ($token->{'from_arg'}, $token->{'until_arg'}); |
555 |
my @bind_params = ($token->{'from_arg'}, $token->{'until_arg'}); |
501 |
push @bind_params, $set->{'id'} if defined $set; |
556 |
push @bind_params, $set->{'id'} if defined $set; |
|
|
557 |
push @bind_params, ($token->{'from'}, $token->{'until'}); |
558 |
push @bind_params, $set->{'id'} if defined $set; |
502 |
$sth->execute( @bind_params ); |
559 |
$sth->execute( @bind_params ); |
503 |
|
560 |
|
504 |
my $count = 0; |
561 |
my $count = 0; |
Lines 521-531
sub new {
Link Here
|
521 |
foreach (@$oai_sets) { |
578 |
foreach (@$oai_sets) { |
522 |
push @setSpecs, $_->{spec}; |
579 |
push @setSpecs, $_->{spec}; |
523 |
} |
580 |
} |
524 |
$self->record( C4::OAI::Record->new( |
581 |
if ($marcxml) { |
525 |
$repository, $marcxml, $timestamp, \@setSpecs, |
582 |
$self->record( C4::OAI::Record->new( |
526 |
identifier => $repository->{ koha_identifier } . ':' . $biblionumber, |
583 |
$repository, $marcxml, $timestamp, \@setSpecs, |
527 |
metadataPrefix => $token->{metadata_prefix} |
584 |
identifier => $repository->{ koha_identifier } . ':' . $biblionumber, |
528 |
) ); |
585 |
metadataPrefix => $token->{metadata_prefix} |
|
|
586 |
) ); |
587 |
} else { |
588 |
$self->record( C4::OAI::DeletedRecord->new( |
589 |
$timestamp, \@setSpecs, identifier => $repository->{ koha_identifier } . ':' . $biblionumber ) ); |
590 |
} |
529 |
} |
591 |
} |
530 |
|
592 |
|
531 |
return $self; |
593 |
return $self; |
532 |
- |
|
|