1 # Copyright Tamil s.a.r.l. 2008-2015
2 # Copyright Biblibre 2008-2015
3 # Copyright The National Library of Finland, University of Helsinki 2016-2021
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 package Koha::OAI::Server::ResumptionToken;
26 use base ("HTTP::OAI::ResumptionToken");
29 # Extends HTTP::OAI::ResumptionToken
30 # A token is identified by:
36 # - deleted count (not used anymore, but preserved for back-compatibility)
40 my ($class, %args) = @_;
42 my $self = $class->SUPER::new(%args);
44 my ($metadata_prefix, $cursor, $from, $until, $set, $deleted, $next_id);
45 if ( $args{ resumptionToken } ) {
46 # Note: undef in place of deleted record count for back-compatibility
47 ($metadata_prefix, $cursor, $from, $until, $set, $deleted, undef, $next_id)
48 = split( '/', $args{resumptionToken} );
49 $next_id = 0 unless $next_id;
52 $metadata_prefix = $args{ metadataPrefix };
53 $from = $args{ from } || '';
54 $until = $args{ until } || '';
55 # Add times to the arguments, when necessary, so they correctly match against the DB timestamps
56 $from .= 'T00:00:00Z' if length($from) == 10;
57 $until .= 'T23:59:59Z' if length($until) == 10;
58 $cursor = $args{ cursor } // 0;
59 $set = $args{ set } || '';
60 $deleted = defined $args{ deleted } ? $args{ deleted } : 1;
61 $next_id = $args{ next_id } // 0;
64 # metadata_prefix can be undef (e.g. listSets)
65 $metadata_prefix //= '';
67 $self->{ metadata_prefix } = $metadata_prefix;
68 $self->{ cursor } = $cursor;
69 $self->{ from } = $from;
70 $self->{ until } = $until;
71 $self->{ set } = $set;
72 $self->{ from_arg } = _strip_UTC_designators($from);
73 $self->{ until_arg } = _strip_UTC_designators($until);
74 $self->{ deleted } = $deleted;
75 $self->{ next_id } = $next_id;
77 # Note: put zero where deleted record count used to be for back-compatibility
78 $self->resumptionToken(
79 join( '/', $metadata_prefix, $cursor, $from, $until, $set, $deleted, 0, $next_id ) );
80 $self->cursor( $cursor );
85 sub _strip_UTC_designators {
86 my ( $timestamp ) = @_;
87 $timestamp =~ s/T/ /g;