Bug 22071: (follow-up) Simplify code
[koha.git] / Koha / OAI / Server / Identify.pm
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-2017
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 package Koha::OAI::Server::Identify;
21
22 use Modern::Perl;
23 use HTTP::OAI;
24 use C4::Context;
25
26 use base ("HTTP::OAI::Identify");
27
28 sub new {
29     my ($class, $repository) = @_;
30
31     my ($baseURL) = $repository->self_url() =~ /(.*)\?.*/;
32     my $self = $class->SUPER::new(
33         baseURL             => $baseURL,
34         repositoryName      => C4::Context->preference("LibraryName"),
35         adminEmail          => C4::Context->preference("KohaAdminEmailAddress"),
36         MaxCount            => C4::Context->preference("OAI-PMH:MaxCount"),
37         granularity         => 'YYYY-MM-DDThh:mm:ssZ',
38         earliestDatestamp   => _get_earliest_datestamp() || '0001-01-01T00:00:00Z',
39         deletedRecord       => C4::Context->preference("OAI-PMH:DeletedRecord") || 'no',
40     );
41
42     # FIXME - alas, the description element is not so simple; to validate
43     # against the OAI-PMH schema, it cannot contain just a string,
44     # but one or more elements that validate against another XML schema.
45     # For now, simply omitting it.
46     # $self->description( "Koha OAI Repository" );
47
48     $self->compression( 'gzip' );
49
50     return $self;
51 }
52
53 # Find the earliest timestamp in the biblio table. If this table is empty, undef
54 # will be returned and we will report the fallback 0001-01-01.
55 sub _get_earliest_datestamp {
56     my $dbh = C4::Context->dbh;
57     my ( $earliest ) = $dbh->selectrow_array("SELECT MIN(timestamp) AS earliest FROM biblio" );
58     return $earliest
59 }
60
61 1;