#
# This file is part of Koha.
#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
# - from
# - until
# - offset
-#
+#
package C4::OAI::ResumptionToken;
use strict;
if(defined $token->{'set'}) {
$set = GetOAISetBySpec($token->{'set'});
}
+ my $max = $repository->{koha_max_count};
my $sql = "
SELECT biblioitems.biblionumber, biblioitems.timestamp
FROM biblioitems
$sql .= " WHERE DATE(timestamp) >= ? AND DATE(timestamp) <= ? ";
$sql .= " AND oai_sets_biblios.set_id = ? " if defined $set;
$sql .= "
- LIMIT $repository->{'koha_max_count'}
- OFFSET $token->{'offset'}
+ LIMIT " . ($max+1) . "
+ OFFSET $token->{offset}
";
my $sth = $dbh->prepare( $sql );
my @bind_params = ($token->{'from'}, $token->{'until'});
push @bind_params, $set->{'id'} if defined $set;
$sth->execute( @bind_params );
- my $pos = $token->{offset};
+ my $count = 0;
while ( my ($biblionumber, $timestamp) = $sth->fetchrow ) {
+ $count++;
+ if ( $count > $max ) {
+ $self->resumptionToken(
+ new C4::OAI::ResumptionToken(
+ metadataPrefix => $token->{metadata_prefix},
+ from => $token->{from},
+ until => $token->{until},
+ offset => $token->{offset} + $max,
+ set => $token->{set}
+ )
+ );
+ last;
+ }
$timestamp =~ s/ /T/, $timestamp .= 'Z';
$self->identifier( new HTTP::OAI::Header(
identifier => $repository->{ koha_identifier} . ':' . $biblionumber,
datestamp => $timestamp,
) );
- $pos++;
}
- $self->resumptionToken(
- new C4::OAI::ResumptionToken(
- metadataPrefix => $token->{metadata_prefix},
- from => $token->{from},
- until => $token->{until},
- offset => $pos,
- set => $token->{set}
- )
- ) if ($pos > $token->{offset});
return $self;
}
if(defined $token->{'set'}) {
$set = GetOAISetBySpec($token->{'set'});
}
+ my $max = $repository->{koha_max_count};
my $sql = "
SELECT biblioitems.biblionumber, biblioitems.marcxml, biblioitems.timestamp
FROM biblioitems
$sql .= " WHERE DATE(timestamp) >= ? AND DATE(timestamp) <= ? ";
$sql .= " AND oai_sets_biblios.set_id = ? " if defined $set;
$sql .= "
- LIMIT $repository->{'koha_max_count'}
- OFFSET $token->{'offset'}
+ LIMIT " . ($max + 1) . "
+ OFFSET $token->{offset}
";
my $sth = $dbh->prepare( $sql );
push @bind_params, $set->{'id'} if defined $set;
$sth->execute( @bind_params );
- my $pos = $token->{offset};
+ my $count = 0;
while ( my ($biblionumber, $marcxml, $timestamp) = $sth->fetchrow ) {
+ $count++;
+ if ( $count > $max ) {
+ $self->resumptionToken(
+ new C4::OAI::ResumptionToken(
+ metadataPrefix => $token->{metadata_prefix},
+ from => $token->{from},
+ until => $token->{until},
+ offset => $token->{offset} + $max,
+ set => $token->{set}
+ )
+ );
+ last;
+ }
my $oai_sets = GetOAISetsBiblio($biblionumber);
my @setSpecs;
foreach (@$oai_sets) {
identifier => $repository->{ koha_identifier } . ':' . $biblionumber,
metadataPrefix => $token->{metadata_prefix}
) );
- $pos++;
}
- $self->resumptionToken(
- new C4::OAI::ResumptionToken(
- metadataPrefix => $token->{metadata_prefix},
- from => $token->{from},
- until => $token->{until},
- offset => $pos,
- set => $token->{set}
- )
- ) if ($pos > $token->{offset});
return $self;
}
This object extend HTTP::OAI::Repository object.
It accepts OAI-PMH HTTP requests and returns result.
-This OAI-PMH server can operate in a simple mode and extended one.
+This OAI-PMH server can operate in a simple mode and extended one.
In simple mode, repository configuration comes entirely from Koha system
preferences (OAI-PMH:archiveID and OAI-PMH:MaxCount) and the server returns