1 # Copyright Tamil s.a.r.l. 2008-2015
2 # Copyright Biblibre 2008-2015
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 package Koha::OAI::Server::ListIdentifiers;
25 use base ("HTTP::OAI::ListIdentifiers");
29 my ($class, $repository, %args) = @_;
31 my $self = HTTP::OAI::ListIdentifiers->new(%args);
33 my $token = new Koha::OAI::Server::ResumptionToken( %args );
34 my $dbh = C4::Context->dbh;
36 if(defined $token->{'set'}) {
37 $set = GetOAISetBySpec($token->{'set'});
39 my $max = $repository->{koha_max_count};
41 (SELECT biblioitems.biblionumber, biblioitems.timestamp
44 $sql .= " JOIN oai_sets_biblios ON biblioitems.biblionumber = oai_sets_biblios.biblionumber " if defined $set;
45 $sql .= " WHERE timestamp >= ? AND timestamp <= ? ";
46 $sql .= " AND oai_sets_biblios.set_id = ? " if defined $set;
48 (SELECT deletedbiblio.biblionumber, timestamp FROM deletedbiblio";
49 $sql .= " JOIN oai_sets_biblios ON deletedbiblio.biblionumber = oai_sets_biblios.biblionumber " if defined $set;
50 $sql .= " WHERE DATE(timestamp) >= ? AND DATE(timestamp) <= ? ";
51 $sql .= " AND oai_sets_biblios.set_id = ? " if defined $set;
53 $sql .= ") ORDER BY biblionumber
54 LIMIT " . ($max+1) . "
55 OFFSET $token->{offset}
57 my $sth = $dbh->prepare( $sql );
58 my @bind_params = ($token->{'from_arg'}, $token->{'until_arg'});
59 push @bind_params, $set->{'id'} if defined $set;
60 push @bind_params, ($token->{'from'}, $token->{'until'});
61 push @bind_params, $set->{'id'} if defined $set;
62 $sth->execute( @bind_params );
65 while ( my ($biblionumber, $timestamp) = $sth->fetchrow ) {
67 if ( $count > $max ) {
68 $self->resumptionToken(
69 new Koha::OAI::Server::ResumptionToken(
70 metadataPrefix => $token->{metadata_prefix},
71 from => $token->{from},
72 until => $token->{until},
73 offset => $token->{offset} + $max,
79 $timestamp =~ s/ /T/, $timestamp .= 'Z';
80 $self->identifier( new HTTP::OAI::Header(
81 identifier => $repository->{ koha_identifier} . ':' . $biblionumber,
82 datestamp => $timestamp,
86 # Return error if no results
88 return HTTP::OAI::Response->new(
89 requestURL => $repository->self_url(),
90 errors => [ new HTTP::OAI::Error( code => 'noRecordsMatch' ) ],