-# list metadata records from the archive
-sub Archive_ListRecords
-{
- my ($self, $set, $from, $until, $metadataPrefix, $resumptionToken) = @_;
-
- my @allrows = ();
- my $marc;
- my $offset;
- my $tokenInfo;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT biblionumber,timestamp FROM biblio WHERE DATE(timestamp) >= ? and DATE(timestamp) <= ? LIMIT ? OFFSET ?");
- my $count;
-
- ($metadataPrefix, $offset, $from, $until ) = &parseResumptionToken($from, $until, $metadataPrefix, $resumptionToken);
-
-warn( "Archive_ListRecords : $set, $from, $until, $metadataPrefix, $resumptionToken\n");
- $sth->execute( $from,$until,$self->{'MaxCount'}?$self->{'MaxCount'}:100000, $offset );
-
- while( my $r = $sth->fetchrow_hashref() ) {
- my $marc = new MARC::Record::KOHADC( ::GetMarcBiblio( $r->{'biblionumber'} ) );
- $marc->{'biblio.timestamp'} = $r->{'timestamp'};
- push( @allrows, $marc );
- }
-
- $sth = $dbh->prepare("SELECT count(*) FROM biblioitems WHERE DATE(timestamp) >= ? and DATE(timestamp) <= ?");
- $sth->execute($from, $until);
- ( $count ) = $sth->fetchrow_array();
-
- unless( @allrows ) {
- $self->AddError ('noRecordsMatch', 'The combination of the values of arguments results in an empty set');
- }
-
- if( $offset + $self->{'MaxCount'} < $count ) { # Not at the end
- $offset = $offset + $self->{'MaxCount'};
- $resumptionToken = &buildResumptionToken($metadataPrefix,$offset,$from,$until);
- $tokenInfo = { 'completeListSize' => $count, 'cursor' => $offset };
- }
- else {
- $resumptionToken = '';
- $tokenInfo = {};
- }
- ( \@allrows, $resumptionToken, $metadataPrefix, $tokenInfo );
+
+sub new {
+ my ($class, $repository, %args) = @_;
+
+ my $self = HTTP::OAI::ListRecords->new(%args);
+
+ my $token = new C4::OAI::ResumptionToken( %args );
+ my $dbh = C4::Context->dbh;
+ my $set;
+ if(defined $token->{'set'}) {
+ $set = GetOAISetBySpec($token->{'set'});
+ }
+ my $sql = "
+ SELECT biblioitems.biblionumber, biblioitems.marcxml, biblioitems.timestamp
+ FROM biblioitems
+ ";
+ $sql .= " JOIN oai_sets_biblios ON biblioitems.biblionumber = oai_sets_biblios.biblionumber " if defined $set;
+ $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'}
+ ";
+
+ 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};
+ while ( my ($biblionumber, $marcxml, $timestamp) = $sth->fetchrow ) {
+ my $oai_sets = GetOAISetsBiblio($biblionumber);
+ my @setSpecs;
+ foreach (@$oai_sets) {
+ push @setSpecs, $_->{spec};
+ }
+ $self->record( C4::OAI::Record->new(
+ $repository, $marcxml, $timestamp, \@setSpecs,
+ 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;