View | Details | Raw Unified | Return to bug 35659
Collapse All | Expand All

(-)a/Koha/Import/Oaipmh/Authorities.pm (+51 lines)
Line 0 Link Here
1
package Koha::Import::Oaipmh::Authorities;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
17
use Modern::Perl;
18
19
use Koha::Import::Oaipmh::Authority;
20
21
use base qw(Koha::Objects);
22
23
=head1 NAME
24
25
Koha::Import::Oaipmh::Authorities
26
27
This object represents a collection of OAI-PMH records being imported as authorities
28
29
=head1 API
30
31
=head2 Methods
32
33
34
=head3 type
35
36
=cut
37
38
sub _type {
39
    return 'ImportOaipmhAuthority';
40
}
41
42
=head3 object_class
43
44
Koha::Object class
45
46
=cut
47
48
sub object_class {
49
    return 'Koha::Import::Oaipmh::Authority';
50
}
51
1;
(-)a/Koha/Import/Oaipmh/Authority.pm (+41 lines)
Line 0 Link Here
1
package Koha::Import::Oaipmh::Authority;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
17
use Modern::Perl;
18
19
use base qw(Koha::Object);
20
21
=head1 NAME
22
23
Koha::Import::Oaipmh::Authority
24
25
This object represents an OAI-PMH record being imported as an authority
26
27
=head1 API
28
29
=head2 Class Methods
30
31
=cut
32
33
=head3 _type
34
35
=cut
36
37
sub _type {
38
    return 'ImportOaipmhAuthority';
39
}
40
41
1;
(-)a/Koha/Import/Oaipmh/Biblio.pm (+40 lines)
Line 0 Link Here
1
package Koha::Import::Oaipmh::Biblio;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
17
use Modern::Perl;
18
19
use base qw(Koha::Object);
20
21
=head1 NAME
22
23
Koha::Import::Oaipmh::Biblio
24
25
This object represents an OAI-PMH record being imported as a bibliographic record
26
27
=head1 API
28
29
=head2 Methods
30
31
32
=head3 _type
33
34
=cut
35
36
sub _type {
37
    return 'ImportOaipmhBiblio';
38
}
39
40
1;
(-)a/Koha/Import/Oaipmh/Biblios.pm (+51 lines)
Line 0 Link Here
1
package Koha::Import::Oaipmh::Biblios;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
17
use Modern::Perl;
18
19
use Koha::Import::Oaipmh::Biblio;
20
21
use base qw(Koha::Objects);
22
23
=head1 NAME
24
25
Koha::Import::Oaipmh::Biblios
26
27
This object represents a collection of OAI-PMH records being imported as bibliographic records
28
29
=head1 API
30
31
=head2 Methods
32
33
34
=head3 type
35
36
=cut
37
38
sub _type {
39
    return 'ImportOaipmhBiblio';
40
}
41
42
=head3 object_class
43
44
Koha::Object class
45
46
=cut
47
48
sub object_class {
49
    return 'Koha::Import::Oaipmh::Biblio';
50
}
51
1;
(-)a/Koha/OAI/Client/Harvester.pm (+354 lines)
Line 0 Link Here
1
# Copyright BibLibre 2023
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
package Koha::OAI::Client::Harvester;
19
20
=head1 NAME
21
22
Koha::OAI::Client::Harvester - OAI Harvester
23
24
=head1 DESCRIPTION
25
26
Koha::OAI::Client::Harvester contains OAI-PMH harvester main functions
27
28
=cut
29
30
use utf8;
31
use open qw( :std :utf8 );
32
33
use C4::Biblio qw( AddBiblio GetFrameworkCode ModBiblio DelBiblio );
34
use C4::AuthoritiesMarc qw (AddAuthority GuessAuthTypeCode ModAuthority DelAuthority );
35
use C4::Log qw( cronlogaction );
36
use HTTP::OAI;
37
use HTTP::OAI::Metadata::OAI_DC;
38
use Koha::DateUtils qw( dt_from_string );
39
use Koha::OaiServers;
40
use Koha::Import::Oaipmh::Biblio;
41
use Koha::Import::Oaipmh::Biblios;
42
use Koha::Import::Oaipmh::Authority;
43
use Koha::Import::Oaipmh::Authorities;
44
use Koha::XSLT::Base;
45
use MARC::File::XML;
46
use MARC::Record;
47
use Modern::Perl;
48
use DateTime;
49
use DateTime::Format::Strptime;
50
use Try::Tiny qw( catch try );
51
use Date::Calc qw(
52
    Add_Delta_Days
53
    Today
54
);
55
56
my $strp = DateTime::Format::Strptime->new(
57
    pattern   => '%FT%TZ',
58
    time_zone => 'floating',
59
);
60
61
our $verbose    = 0;
62
our $servername = '';
63
64
=head2 new
65
66
$harvester = Koha::OAI::Client::Harvester->new( { server => $id, verbose => $verbose, days => $days, force => $force } );
67
68
Starts an harvest
69
70
C<$id> id of the OAI repository
71
72
C<$verbose> print log messages to stdout when enabled
73
74
C<$days> number of days to harvest from (optional)
75
76
C<$force> force harvesting (ignore records datestamps)
77
78
=cut
79
80
sub new {
81
82
    my ( $self, $args ) = @_;
83
84
    my $id = $args->{'server'};
85
    $verbose = $args->{'verbose'};
86
    my $days  = $args->{'days'};
87
    my $force = $args->{'force'};
88
89
    return unless $id;
90
91
    my $server = Koha::OaiServers->find($id);
92
    $servername = $server->servername;
93
94
    unless ($server) {
95
        printlog("OAI Server $id unknown\n");
96
        return;
97
    }
98
99
    printlog("Starting OAI Harvest from repository");
100
101
    my $h = HTTP::OAI::Harvester->new(
102
        repository => HTTP::OAI::Identify->new(
103
            baseURL => $server->endpoint,
104
            version => '2.0',
105
        )
106
    );
107
108
    printlog( "Using HTTP::OAI::Harvester version " . $HTTP::OAI::Harvester::VERSION );
109
110
    printlog( "Using endpoint "
111
            . $server->endpoint
112
            . ", set "
113
            . $server->oai_set
114
            . ", dataformat "
115
            . $server->dataformat
116
            . ", recordtype "
117
            . $server->recordtype );
118
119
    try {
120
        my $lmdf    = $h->ListMetadataFormats();
121
        my $lmdflog = "";
122
        for ( $lmdf->metadataFormat ) {
123
            $lmdflog .= $_->metadataPrefix . " ";
124
        }
125
        printlog("Available metadata formats for this repository: $lmdflog");
126
    } catch {
127
        printlog("ListMetadataFormats failed");
128
    };
129
130
    #my $response = $h->Identify;
131
    #print "Repository supports protocol version ", $response->version, "\n";
132
    if ( $server->add_xslt ) {
133
        printlog( "Using XSLT file " . $server->add_xslt );
134
    } else {
135
        printlog("Not using an XSLT file");
136
    }
137
138
    my $start_date = '';
139
    my $today_date = '';
140
141
    if ($days) {
142
143
        # Change this to yyyy-mm-dd
144
        my $dt_today = dt_from_string();
145
        my ( $nowyear, $nowmonth, $nowday ) = Today();
146
        my @date     = Add_Delta_Days( $nowyear, $nowmonth, $nowday, -$days );
147
        my $dt_start = DateTime->new( year => $date[0], month => $date[1], day => $date[2] );
148
        $start_date = $dt_start->ymd();
149
        printlog("Harvesting from $start_date");
150
    }
151
152
    printlog("Asking for records");
153
    my $response = $h->ListRecords(
154
        metadataPrefix => $server->dataformat,
155
        set            => $server->oai_set,
156
        from           => $start_date,
157
    );
158
    if ( $response->is_error ) {
159
        printlog( "Error requesting ListRecords: " . $response->code . " " . $response->message );
160
        exit;
161
    }
162
    printlog( "Request URL: " . $response->requestURL );
163
164
    my $xslt_engine = Koha::XSLT::Base->new;
165
    my $added       = 0;
166
    my $updated     = 0;
167
    my $deleted     = 0;
168
    my $in_error    = 0;
169
    my $skipped     = 0;
170
    my $total       = 0;
171
172
    printlog("Starting processing results");
173
    while ( my $oai_record = $response->next ) {
174
        $total++;
175
        unless ( $oai_record->identifier ) {
176
            printlog("No identifier found");
177
            $skipped++;
178
            next;
179
        }
180
181
        my $to_delete;
182
        my $outputUnimarc;
183
        my $marcrecord;
184
        if ( $oai_record->status && $oai_record->status eq "deleted" ) {
185
            $to_delete = 1;
186
        } else {
187
            if ( $server->add_xslt ) {
188
                $outputUnimarc = $xslt_engine->transform( $oai_record->metadata->dom, $server->add_xslt );
189
                my $err = $xslt_engine->err;
190
                if ($err) {
191
                    printlog("XSLT::Base error: $err");
192
                    $in_error++;
193
                    next;
194
                }
195
            } else {
196
                $outputUnimarc = $oai_record->metadata->dom;
197
            }
198
            $marcrecord = MARC::Record->new_from_xml( $outputUnimarc, 'UTF-8' );
199
        }
200
        my $imported_record;
201
        if ( $server->recordtype eq "biblio" ) {
202
            $imported_record = Koha::Import::Oaipmh::Biblios->find(
203
                {
204
                    repository => $server->endpoint,
205
                    identifier => $oai_record->identifier,
206
                    recordtype => $server->recordtype,
207
                }
208
            );
209
        } else {
210
            $imported_record = Koha::Import::Oaipmh::Authorities->find(
211
                {
212
                    repository => $server->endpoint,
213
                    identifier => $oai_record->identifier,
214
                    recordtype => $server->recordtype,
215
                }
216
            );
217
        }
218
219
        if ($imported_record) {
220
            if ($to_delete) {
221
                if ( $server->recordtype eq "biblio" ) {
222
                    my $biblionumber = $imported_record->biblionumber;
223
                    my $error        = DelBiblio($biblionumber);
224
                    if ($error) {
225
                        printlog( "Record "
226
                                . $oai_record->identifier
227
                                . " not deleted, biblionumber: $biblionumber ($error)" );
228
                        $in_error++;
229
                    } else {
230
                        $imported_record->delete;
231
                        printlog( "Record " . $oai_record->identifier . " deleted, biblionumber: $biblionumber" );
232
                        $deleted++;
233
                    }
234
                } else {
235
                    my $authid = $imported_record->authid;
236
                    DelAuthority( { authid => $authid } );
237
                    $imported_record->delete;
238
                    printlog( "Record " . $oai_record->identifier . " deleted, authid: $authid" );
239
                    $deleted++;
240
                }
241
            } else {
242
                my $incoming_dt = $strp->parse_datetime( $imported_record->datestamp );
243
                my $existing_dt = $strp->parse_datetime( $oai_record->datestamp );
244
                if ( $force || !$incoming_dt || !$existing_dt || $incoming_dt > $existing_dt ) {
245
                    if ( $server->recordtype eq "biblio" ) {
246
                        my $biblionumber = $imported_record->biblionumber;
247
                        my $result       = ModBiblio( $marcrecord, $biblionumber, GetFrameworkCode($biblionumber) );
248
                        printlog( "Record " . $oai_record->identifier . " updated, biblionumber: $biblionumber" );
249
                    } else {
250
                        my $authid = $imported_record->authid;
251
                        my $result = ModAuthority( $authid, $marcrecord, GuessAuthTypeCode($marcrecord) );
252
                        printlog( "Record " . $oai_record->identifier . " updated, authid: $authid" );
253
                    }
254
                    $imported_record->update(
255
                        {
256
                            datestamp => $imported_record->datestamp,
257
                        }
258
                    );
259
                    $updated++;
260
                } else {
261
                    printlog( "Record "
262
                            . $oai_record->identifier
263
                            . " skipped (incoming record was not newer than existing record)" );
264
                    $skipped++;
265
                }
266
            }
267
        } elsif ( !$to_delete ) {
268
            if ( $server->recordtype eq "biblio" ) {
269
                my ( $biblionumber, $biblioitemnumber ) = AddBiblio($marcrecord);
270
                printlog( $oai_record->identifier . " added, biblionumber: $biblionumber" );
271
                Koha::Import::Oaipmh::Biblio->new(
272
                    {
273
                        repository   => $server->endpoint,
274
                        identifier   => $oai_record->identifier,
275
                        biblionumber => $biblionumber,
276
                        recordtype   => $server->recordtype,
277
                        datestamp    => $oai_record->datestamp,
278
                    }
279
                )->store;
280
            } else {
281
                my $authid = AddAuthority( $marcrecord, "", GuessAuthTypeCode($marcrecord) );
282
                printlog( $oai_record->identifier . " added, authid: $authid" );
283
                Koha::Import::Oaipmh::Authority->new(
284
                    {
285
                        repository => $server->endpoint,
286
                        identifier => $oai_record->identifier,
287
                        authid     => $authid,
288
                        recordtype => $server->recordtype,
289
                        datestamp  => $oai_record->datestamp,
290
                    }
291
                )->store;
292
            }
293
            $added++;
294
        } else {
295
            printlog( "Record " . $oai_record->identifier . " skipped (record not present or already deleted)" );
296
            $skipped++;
297
        }
298
    }
299
    printlog(
300
        "Harvest results:\n$added added\n$updated updated\n$deleted deleted\n$skipped skipped\n$in_error errors\n$total total"
301
    );
302
303
    if ( C4::Context->preference("OAI-PMH:HarvestEmailReport") ) {
304
305
        my $letter = C4::Letters::GetPreparedLetter(
306
            (
307
                module      => 'catalogue',
308
                letter_code => 'OAI_HARVEST_REPORT',
309
                substitute  => {
310
                    servername => $servername,
311
                    endpoint   => $server->endpoint,
312
                    set        => $server->oai_set,
313
                    dataformat => $server->dataformat,
314
                    recordtype => $server->recordtype,
315
                    added      => $added,
316
                    updated    => $updated,
317
                    deleted    => $deleted,
318
                    skipped    => $skipped,
319
                    in_error   => $in_error,
320
                    total      => $total
321
                },
322
            )
323
        ) or printlog("OAI_HARVEST_REPORT letter not found");
324
325
        my $success = C4::Letters::EnqueueLetter(
326
            {
327
                letter     => $letter,
328
                to_address => C4::Context->preference("OAI-PMH:HarvestEmailReport"), message_transport_type => 'email'
329
            }
330
        );
331
        if ($success) {
332
            printlog("Email report enqueued");
333
        } else {
334
            printlog("Unable to enqueue report email");
335
        }
336
    }
337
338
    printlog("Ending OAI Harvest from repository");
339
}
340
341
=head2 printlog
342
343
This method adds a cronlog and prints to stdout if verbose is enabled
344
345
=cut
346
347
sub printlog {
348
    my $message = shift;
349
    $message = $servername . ": " . $message;
350
    print $message . "\n" if ($verbose);
351
    cronlogaction( { info => $message } );
352
}
353
354
1;
(-)a/Koha/OaiServer.pm (+45 lines)
Line 0 Link Here
1
package Koha::OaiServer;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
21
use Koha::Database;
22
23
use base qw(Koha::Object);
24
25
=head1 NAME
26
27
Koha::OaiServer - Koha OaiServer Object class
28
29
=head1 API
30
31
=head2 Class Methods
32
33
=cut
34
35
=head3 _type
36
37
Return type of Object relating to Schema ResultSet
38
39
=cut
40
41
sub _type {
42
    return 'Oaiserver';
43
}
44
45
1;
(-)a/Koha/OaiServers.pm (+57 lines)
Line 0 Link Here
1
package Koha::OaiServers;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
21
use Koha::Database;
22
23
use Koha::OaiServer;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::OaiServers - Koha OaiServer Object set class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 _type
38
39
Return type of object, relating to Schema ResultSet
40
41
=cut
42
43
sub _type {
44
    return 'Oaiserver';
45
}
46
47
=head3 object_class
48
49
Return object class
50
51
=cut
52
53
sub object_class {
54
    return 'Koha::OaiServer';
55
}
56
57
1;
(-)a/admin/oaiservers.pl (+122 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
# This script is used to maintain the OAI servers table.
19
# Parameter $op is operation: list, new, edit, add_validated, delete_confirmed.
20
# add_validated saves a validated record and goes to list view.
21
# delete_confirmed deletes a record and goes to list view.
22
23
use Modern::Perl;
24
use CGI qw ( -utf8 );
25
use C4::Context;
26
use C4::Auth qw( get_template_and_user );
27
use C4::Output qw( output_html_with_http_headers );
28
use Koha::Database;
29
use Koha::OaiServers;
30
31
# Initialize CGI, template, database
32
33
my $input       = CGI->new;
34
my $op          = $input->param('op') || 'list';
35
my $id          = $input->param('id') || 0;
36
my $type        = $input->param('type') || '';
37
my $searchfield = '';
38
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40
    {
41
        template_name => "admin/oaiservers.tt",
42
        query         => $input,
43
        type          => "intranet",
44
        flagsrequired => { parameters => 'manage_search_targets' },
45
    }
46
);
47
my $script_name = "/cgi-bin/koha/admin/oaiservers.pl";
48
my $path        = C4::Context->config('intrahtdocs') . "/prog/";
49
50
$template->param( script_name => $script_name, xslt_path => $path );
51
52
my $schema = Koha::Database->new()->schema();
53
54
# Main code
55
# First process a confirmed delete, or save a validated record
56
57
if ( $op eq 'delete_confirmed' && $id ) {
58
    my $server = Koha::OaiServers->find($id);
59
    if ($server) {
60
        $server->delete;
61
        $template->param( msg_deleted => 1, msg_add => $server->servername );
62
    } else {
63
        $template->param( msg_notfound => 1, msg_add => $id );
64
    }
65
    $id = 0;
66
} elsif ( $op eq 'add_validated' ) {
67
    my @fields = qw/endpoint oai_set dataformat
68
        recordtype servername
69
        add_xslt/;
70
    my $formdata = _form_data_hashref( $input, \@fields );
71
    if ($id) {
72
        my $server = Koha::OaiServers->find($id);
73
        if ($server) {
74
            $server->set($formdata)->store;
75
            $template->param( msg_updated => 1, msg_add => $formdata->{servername} );
76
        } else {
77
            $template->param( msg_notfound => 1, msg_add => $id );
78
        }
79
        $id = 0;
80
    } else {
81
        Koha::OaiServer->new($formdata)->store;
82
        $template->param( msg_added => 1, msg_add => $formdata->{servername} );
83
    }
84
} else {
85
86
    #use searchfield only in remaining operations
87
    $searchfield = $input->param('searchfield') || '';
88
}
89
90
# Now list multiple records, or edit one record
91
92
my $data = [];
93
if ( $op eq 'add' || $op eq 'edit' ) {
94
    $data = ServerSearch( $schema, $id, $searchfield ) if $searchfield || $id;
95
    delete $data->[0]->{id} if @$data && $op eq 'add';    #cloning record
96
    $template->param(
97
        add_form => 1, server => @$data ? $data->[0] : undef,
98
        op => $op, type => $op eq 'add' ? lc $type : ''
99
    );
100
} else {
101
    $data = ServerSearch( $schema, $id, $searchfield );
102
    $template->param(
103
        loop => \@$data, searchfield => $searchfield, id => $id,
104
        op   => 'list'
105
    );
106
}
107
output_html_with_http_headers $input, $cookie, $template->output;
108
109
# End of main code
110
111
sub ServerSearch {    #find server(s) by id or name
112
    my ( $schema, $id, $searchstring ) = @_;
113
114
    return Koha::OaiServers->search(
115
        $id ? { id => $id } : { servername => { like => $searchstring . '%' } },
116
    )->unblessed;
117
}
118
119
sub _form_data_hashref {
120
    my ( $input, $fieldref ) = @_;
121
    return { map { ( $_ => scalar $input->param($_) // '' ) } @$fieldref };
122
}
(-)a/installer/data/mysql/atomicupdate/Bug-35659.pl (+88 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "35659",
5
    description => "OAI-PMH Harvester",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
        $dbh->do(q{DROP TABLE IF EXISTS `oaiservers`;});
10
        $dbh->do(
11
            q{
12
            CREATE TABLE `oaiservers` (
13
              `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
14
              `endpoint` varchar(255) NOT NULL COMMENT 'OAI endpoint (host + port + path)',
15
              `oai_set` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
16
              `servername` longtext NOT NULL COMMENT 'name given to the target by the library',
17
              `dataformat` enum('oai_dc','marc-xml', 'marcxml') NOT NULL DEFAULT 'oai_dc' COMMENT 'data format',
18
              `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'server contains bibliographic or authority records',
19
              `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results',
20
              PRIMARY KEY (`id`)
21
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
22
        }
23
        );
24
        say $out "Added new table 'oaiservers'";
25
26
        $dbh->do(q{DROP TABLE IF EXISTS `import_oaipmh_biblios`;});
27
        $dbh->do(
28
            q{
29
            CREATE TABLE `import_oaipmh_biblios` (
30
              `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
31
              `biblionumber` int(11) NOT NULL COMMENT 'unique identifier assigned to each koha record',
32
              `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier',
33
              `repository` varchar(255) NOT NULL COMMENT 'OAI repository',
34
              `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
35
              `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
36
              `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
37
              PRIMARY KEY (id),
38
              KEY biblionumber (biblionumber),
39
              CONSTRAINT FK_import_oaipmh_biblios_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE NO ACTION
40
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
41
        }
42
        );
43
44
        $dbh->do(q{DROP TABLE IF EXISTS `import_oaipmh_authorities`;});
45
        $dbh->do(
46
            q{
47
            CREATE TABLE `import_oaipmh_authorities` (
48
              `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
49
              `authid` bigint(20) unsigned NOT NULL COMMENT 'unique identifier assigned to each koha record',
50
              `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier',
51
              `repository` varchar(255) NOT NULL COMMENT 'OAI repository',
52
              `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
53
              `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
54
              `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
55
              PRIMARY KEY (id),
56
              KEY authid (authid),
57
              CONSTRAINT FK_import_oaipmh_authorities_1 FOREIGN KEY (authid) REFERENCES auth_header (authid) ON DELETE CASCADE ON UPDATE NO ACTION
58
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
59
        }
60
        );
61
        say $out "Added new tables 'import_oaipmh_biblios' and import_oaipmh_authorities";
62
63
        $dbh->do(
64
            q{
65
            UPDATE `permissions` SET description='Manage Z39.50 and SRU servers, OAI repositories configuration' WHERE code='manage_search_targets';
66
        }
67
        );
68
        say $out "Updated manage_search_targets permission description";
69
70
        $dbh->do(
71
            q{
72
            INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES
73
            ('OAI-PMH:HarvestEmailReport','','','If set, a report email will be sent to this address after an OAI harvest','Free');
74
        }
75
        );
76
        say $out "Added OAI-PMH:HarvestEmailReport system preference";
77
78
        $dbh->do(
79
            q{
80
            INSERT IGNORE INTO letter
81
            (module, code, branchcode, name, is_html, title, content, message_transport_type, lang)
82
            VALUES ('catalogue','OAI_HARVEST_REPORT','','OAI Harvest Report',0,'OAI Harvest report for [% servername %]','OAI Harvest report for [% servername %]:\n\nEndpoint: [% endpoint %]\nSet: [% set %]\nData format: [% dataformat %]\nRecord type: [% recordtype %]\n\n[% added %] records added\n[% updated %] records updated\n[% deleted %] records deleted\n[% skipped %] records skipped\n[% in_error %] records in error\n[% total %] total','email','default');
83
        }
84
        );
85
        say $out "Added OAI_HARVEST_REPORT letter";
86
87
    },
88
};
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+23 lines)
Lines 2467-2469 tables: Link Here
2467
            - "Your hold on [% hold.biblio.title %] ([% hold.biblio.id %]) has been confirmed."
2467
            - "Your hold on [% hold.biblio.title %] ([% hold.biblio.id %]) has been confirmed."
2468
            - "You will be notified by the library when your item is available for pickup."
2468
            - "You will be notified by the library when your item is available for pickup."
2469
            - "Thank you!"
2469
            - "Thank you!"
2470
2471
        - module: catalogue
2472
          code: OAI_HARVEST_REPORT
2473
          branchcode: ""
2474
          name: "OAI Harvest Report"
2475
          is_html: 0
2476
          title: "OAI Harvest report for [% servername %]"
2477
          message_transport_type: email
2478
          lang: default
2479
          content:
2480
            - "OAI Harvest report for [% servername %]:"
2481
            - ""
2482
            - "Endpoint: [% endpoint %]"
2483
            - "Set: [% set %]"
2484
            - "Data format: [% dataformat %]"
2485
            - "Record type: [% recordtype %]"
2486
            - ""
2487
            - "[% added %] records added"
2488
            - "[% updated %] records updated"
2489
            - "[% deleted %] records deleted"
2490
            - "[% skipped %] records skipped"
2491
            - "[% in_error %] records in error"
2492
            - "[% total %] total"
(-)a/installer/data/mysql/kohastructure.sql (+58 lines)
Lines 4819-4824 CREATE TABLE `oai_sets_mappings` ( Link Here
4819
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4819
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4820
/*!40101 SET character_set_client = @saved_cs_client */;
4820
/*!40101 SET character_set_client = @saved_cs_client */;
4821
4821
4822
--
4823
-- Table structure for table `oaiservers`
4824
--
4825
4826
DROP TABLE IF EXISTS `oaiservers`;
4827
/*!40101 SET @saved_cs_client     = @@character_set_client */;
4828
/*!40101 SET character_set_client = utf8 */;
4829
CREATE TABLE `oaiservers` (
4830
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
4831
  `endpoint` varchar(255) NOT NULL COMMENT 'OAI endpoint (host + port + path)',
4832
  `oai_set` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
4833
  `servername` longtext NOT NULL COMMENT 'name given to the target by the library',
4834
  `dataformat` enum('oai_dc','marc-xml', 'marcxml') NOT NULL DEFAULT 'oai_dc' COMMENT 'data format',
4835
  `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'server contains bibliographic or authority records',
4836
  `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results',
4837
  PRIMARY KEY (`id`)
4838
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4839
4840
--
4841
-- Table structure for table `import_oaipmh_biblios`
4842
--
4843
4844
DROP TABLE IF EXISTS `import_oaipmh_biblios`;
4845
/*!40101 SET @saved_cs_client     = @@character_set_client */;
4846
/*!40101 SET character_set_client = utf8 */;
4847
CREATE TABLE `import_oaipmh_biblios` (
4848
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
4849
  `biblionumber` int(11) NOT NULL COMMENT 'unique identifier assigned to each koha record',
4850
  `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier',
4851
  `repository` varchar(255) NOT NULL COMMENT 'OAI repository',
4852
  `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
4853
  `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
4854
  `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
4855
  PRIMARY KEY (id),
4856
  KEY biblionumber (biblionumber),
4857
  CONSTRAINT FK_import_oaipmh_biblios_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE NO ACTION
4858
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4859
4860
--
4861
-- Table structure for table `import_oaipmh_authorities`
4862
--
4863
4864
DROP TABLE IF EXISTS `import_oaipmh_authorities`;
4865
/*!40101 SET @saved_cs_client     = @@character_set_client */;
4866
/*!40101 SET character_set_client = utf8 */;
4867
CREATE TABLE `import_oaipmh_authorities` (
4868
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha',
4869
  `authid` bigint(20) unsigned NOT NULL COMMENT 'unique identifier assigned to each koha record',
4870
  `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier',
4871
  `repository` varchar(255) NOT NULL COMMENT 'OAI repository',
4872
  `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority',
4873
  `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest',
4874
  `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
4875
  PRIMARY KEY (id),
4876
  KEY authid (authid),
4877
  CONSTRAINT FK_import_oaipmh_authorities_1 FOREIGN KEY (authid) REFERENCES auth_header (authid) ON DELETE CASCADE ON UPDATE NO ACTION
4878
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4879
4822
--
4880
--
4823
-- Table structure for table `oauth_access_tokens`
4881
-- Table structure for table `oauth_access_tokens`
4824
--
4882
--
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 436-441 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
436
('OAI-PMH:ConfFile','',NULL,'If empty, Koha OAI Server operates in normal mode, otherwise it operates in extended mode.','File'),
436
('OAI-PMH:ConfFile','',NULL,'If empty, Koha OAI Server operates in normal mode, otherwise it operates in extended mode.','File'),
437
('OAI-PMH:DeletedRecord','persistent','Koha\'s deletedbiblio table will never be deleted (persistent), might be deleted (transient), or will never have any data in it (no)','transient|persistent|no','Choice'),
437
('OAI-PMH:DeletedRecord','persistent','Koha\'s deletedbiblio table will never be deleted (persistent), might be deleted (transient), or will never have any data in it (no)','transient|persistent|no','Choice'),
438
('OAI-PMH:MaxCount','50',NULL,'OAI-PMH maximum number of records by answer to ListRecords and ListIdentifiers queries','Integer'),
438
('OAI-PMH:MaxCount','50',NULL,'OAI-PMH maximum number of records by answer to ListRecords and ListIdentifiers queries','Integer'),
439
('OAI-PMH:HarvestEmailReport','','','If set, a report email will be sent to this address after an OAI harvest','Free'),
439
('OPACAcquisitionDetails','0','','Show the acquisition details at the OPAC','YesNo'),
440
('OPACAcquisitionDetails','0','','Show the acquisition details at the OPAC','YesNo'),
440
('OpacAddMastheadLibraryPulldown','0','','Adds a pulldown menu to select the library to search on the opac masthead.','YesNo'),
441
('OpacAddMastheadLibraryPulldown','0','','Adds a pulldown menu to select the library to search on the opac masthead.','YesNo'),
441
('OpacAdvSearchMoreOptions','pubdate,itemtype,language,subtype,sorting,location','Show search options for the expanded view (More options)','pubdate|itemtype|language|subtype|sorting|location','multiple'),
442
('OpacAdvSearchMoreOptions','pubdate,itemtype,language,subtype,sorting,location','Show search options for the expanded view (More options)','pubdate|itemtype|language|subtype|sorting|location','multiple'),
(-)a/installer/data/mysql/mandatory/userpermissions.sql (-1 / +1 lines)
Lines 29-35 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
29
   ( 3, 'manage_item_search_fields', 'Manage item search fields'),
29
   ( 3, 'manage_item_search_fields', 'Manage item search fields'),
30
   ( 3, 'manage_search_engine_config', 'Manage search engine configuration'),
30
   ( 3, 'manage_search_engine_config', 'Manage search engine configuration'),
31
   ( 3, 'manage_marc_overlay_rules', 'Manage MARC overlay rules configuration'),
31
   ( 3, 'manage_marc_overlay_rules', 'Manage MARC overlay rules configuration'),
32
   ( 3, 'manage_search_targets', 'Manage Z39.50 and SRU server configuration'),
32
   ( 3, 'manage_search_targets', 'Manage Z39.50 and SRU servers, OAI repositories configuration'),
33
   ( 3, 'manage_didyoumean', 'Manage Did you mean? configuration'),
33
   ( 3, 'manage_didyoumean', 'Manage Did you mean? configuration'),
34
   ( 3, 'manage_column_config', 'Manage column configuration'),
34
   ( 3, 'manage_column_config', 'Manage column configuration'),
35
   ( 3, 'manage_sms_providers', 'Manage SMS cellular providers'),
35
   ( 3, 'manage_sms_providers', 'Manage SMS cellular providers'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (+1 lines)
Lines 149-154 Link Here
149
            [% END %]
149
            [% END %]
150
            [% IF ( CAN_user_parameters_manage_search_targets ) %]
150
            [% IF ( CAN_user_parameters_manage_search_targets ) %]
151
                <li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></li>
151
                <li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></li>
152
                <li><a href="/cgi-bin/koha/admin/oaiservers.pl">OAI repositories</a></li>
152
            [% END %]
153
            [% END %]
153
            [% IF ( CAN_user_parameters_manage_smtp_servers ) %]
154
            [% IF ( CAN_user_parameters_manage_smtp_servers ) %]
154
                <li><a href="/cgi-bin/koha/admin/smtp_servers.pl">SMTP servers</a></li>
155
                <li><a href="/cgi-bin/koha/admin/smtp_servers.pl">SMTP servers</a></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/oai-admin-search.inc (+43 lines)
Line 0 Link Here
1
[% USE Koha %]
2
<!-- oai-admin-search.inc -->
3
<div id="header_search" role="tablist">
4
    <div class="tab-content">
5
        <div id="oai_search" role="tabpanel" class="tab-pane active">
6
            <form action="/cgi-bin/koha/admin/oaiservers.pl" method="post">
7
                <div class="form-title">
8
                    <label class="control-label">Search OAI repositories</label>
9
                </div>
10
11
                <div class="form-content">
12
                    <input class="head-searchbox form-control" type="text" name="searchfield" id="searchfield" value="[% searchfield | html %]" placeholder="OAI repository search" />
13
                </div>
14
15
                <button type="submit"><i class="fa fa-arrow-right"></i></button>
16
            </form>
17
        </div>
18
19
        [% IF ( CAN_user_circulate_circulate_remaining_permissions ) %]
20
            [% INCLUDE 'patron-search-box.inc' %]
21
        [% END %]
22
        [% IF ( CAN_user_catalogue ) %]
23
            [% INCLUDE 'catalogue-search-box.inc' %]
24
        [% END %]
25
26
    </div><!-- /.tab-content -->
27
    <ul class="nav nav-tabs" role="tablist">
28
        <li role="presentation" class="active">
29
            <a title="Search OAI repositories" href="#oai_search" aria-controls="z3950_search" role="tab" aria-expanded="true" data-toggle="tab" class="keep_text"><i class="fa fa-search"></i> <span class="tab-title">Search OAI repositories</span></a>
30
        </li>
31
        [% IF ( CAN_user_circulate_circulate_remaining_permissions ) %]
32
            <li role="presentation">
33
                <a title="Check out" href="#circ_search" aria-controls="circ_search" role="tab" data-toggle="tab" class="keep_text"><i class="fa fa-upload"></i> <span class="tab-title">Check out</span></a>
34
            </li>
35
        [% END %]
36
        [% IF ( CAN_user_catalogue ) %]
37
            <li role="presentation">
38
                <a title="Search catalog" href="#catalog_search" aria-controls="catalog_search" role="tab" data-toggle="tab" class="keep_text"><i class="fa fa-fw fa-search"></i> <span class="tab-title">Search catalog</span></a>
39
            </li>
40
        [% END %]
41
    </ul>
42
</div><!-- /#header_search -->
43
<!-- /oai-admin-search.inc -->
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc (-1 / +1 lines)
Lines 244-250 Link Here
244
        <span class="permissioncode">([% name | html %])</span>
244
        <span class="permissioncode">([% name | html %])</span>
245
    [%- CASE 'manage_search_targets' -%]
245
    [%- CASE 'manage_search_targets' -%]
246
        <span class="sub_permission manage_search_targets_subpermission">
246
        <span class="sub_permission manage_search_targets_subpermission">
247
            Manage Z39.50 and SRU server configuration
247
            Manage Z39.50 and SRU servers, OAI repositories configuration
248
        </span>
248
        </span>
249
        <span class="permissioncode">([% name | html %])</span>
249
        <span class="permissioncode">([% name | html %])</span>
250
    [%- CASE 'manage_didyoumean' -%]
250
    [%- CASE 'manage_didyoumean' -%]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+2 lines)
Lines 248-253 Link Here
248
                    [% IF ( CAN_user_parameters_manage_search_targets ) %]
248
                    [% IF ( CAN_user_parameters_manage_search_targets ) %]
249
                        <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></dt>
249
                        <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></dt>
250
                        <dd>Define which external servers to query for MARC data</dd>
250
                        <dd>Define which external servers to query for MARC data</dd>
251
                        <dt><a href="/cgi-bin/koha/admin/oaiservers.pl">OAI repositories</a></dt>
252
                        <dd>Define which OAI repositories to harvest data from</dd>
251
                    [% END %]
253
                    [% END %]
252
                    [% IF ( CAN_user_parameters_manage_smtp_servers ) %]
254
                    [% IF ( CAN_user_parameters_manage_smtp_servers ) %]
253
                        <dt><a href="/cgi-bin/koha/admin/smtp_servers.pl">SMTP servers</a></dt>
255
                        <dt><a href="/cgi-bin/koha/admin/smtp_servers.pl">SMTP servers</a></dt>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oaiservers.tt (+229 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% SET footerjs = 1 %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
6
<title>
7
    [% IF op == 'edit' %]
8
        Modify OAI repository [% server.servername | html %] &rsaquo; [% END %]
9
10
    [% IF op ==  'add' %]
11
        New OAI repository &rsaquo; [% END %]
12
13
    OAI repositories &rsaquo; Administration &rsaquo; Koha
14
</title>
15
[% INCLUDE 'doc-head-close.inc' %]
16
</head>
17
18
<body id="admin_oaiservers" class="admin">
19
[% WRAPPER 'header.inc' %]
20
    [% INCLUDE 'oai-admin-search.inc' %]
21
[% END %]
22
23
[% WRAPPER 'sub-header.inc' %]
24
    [% WRAPPER breadcrumbs %]
25
        [% WRAPPER breadcrumb_item %]
26
            <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
27
        [% END %]
28
29
        [% IF op == 'edit' || op == 'add' %]
30
            [% WRAPPER breadcrumb_item %]
31
                <a href="/cgi-bin/koha/admin/oaiservers.pl">OAI repositories</a>
32
           [% END %]
33
        [% END %]
34
35
        [% IF op == 'edit' %]
36
            [% WRAPPER breadcrumb_item bc_active= 1 %]
37
                <span>Modify OAI repository [% server.servername | html %]</span>
38
           [% END %]
39
40
        [% ELSIF op == 'add' %]
41
            [% WRAPPER breadcrumb_item bc_active= 1 %]
42
                <span>New OAI repository</span>
43
           [% END %]
44
45
        [% ELSE %]
46
            [% WRAPPER breadcrumb_item bc_active= 1 %]
47
                <span>OAI repositories</span>
48
           [% END %]
49
        [% END %]
50
    [% END #/ WRAPPER breadcrumbs %]
51
[% END #/ WRAPPER sub-header.inc %]
52
53
<div class="main container-fluid">
54
    <div class="row">
55
        <div class="col-sm-10 col-sm-push-2">
56
            <main>
57
58
[% IF msg_deleted %]
59
    <div class="dialog alert">OAI repository deleted ([% msg_add | html %])</div>
60
[% ELSIF msg_updated %]
61
    <div class="dialog message">OAI repository updated ([% msg_add | html %])</div>
62
[% ELSIF msg_added %]
63
    <div class="dialog message">OAI repository added ([% msg_add | html %])</div>
64
[% ELSIF msg_notfound %]
65
    <div class="dialog alert">Error: Server with ID [% msg_add | html %] not found</div>
66
[% END %]
67
68
[% IF ( add_form ) %]
69
    <form action="[% script_name | html %]" name="Aform" method="post" id="serverentry">
70
        <input type="hidden" name="op" value="add_validated" />
71
        [% IF op == 'edit' %]
72
            <h1>Modify OAI repository</h1>
73
            <input type="hidden" name="id" value="[% server.id | html %]" />
74
        [% ELSE %]
75
            <h1>New OAI repository</h1>
76
        [% END %]
77
        <fieldset class="rows">
78
        <ol>
79
        <li><label for="name" class="required">Repository name: </label>
80
            [% IF server.servername %]
81
                <input type="text" name="servername" id="servername" size="65" maxlength="100" value="[% server.servername | html %]" required="required" />
82
            [% ELSE %]
83
                <input type="text" name="servername" id="servername" class="focus" size="65" maxlength="100" value="[% server.servername | html %]" required="required" />
84
            [% END %]
85
             <span class="required">Required</span>
86
        </li>
87
88
        <li><label for="endpoint" class="required">Endpoint: </label> <input type="text" name="endpoint" id="endpoint" size="30" value="[% server.endpoint | html %]" required="required" /> <span class="required">Required</span>
89
        </li>
90
        <li><label for="oai_set">Set: </label> <input type="text" name="oai_set" id="oai_set" value="[% server.oai_set | html %]" />
91
        </li>
92
        <li>
93
            <label for="dataformat">Data format: </label>
94
        <select name="dataformat" id="dataformat">
95
            <option value="oai_dc">Dublin Core (oai_dc)</option>
96
            <option value="marc-xml">Marcxml (marc-xml)</option>
97
            <option value="marcxml">Marcxml (marcxml)</option>
98
        </select>
99
            <div class="hint">OAI can send records in various formats. Choose one.</div>
100
        </li>
101
102
        <li><label for="recordtype">Record type: </label>
103
        <select name="recordtype" id="recordtype">
104
            <option value="biblio">Bibliographic</option>
105
            <option value="authority">Authority</option>
106
        </select>
107
        </li>
108
        <li>
109
        <label for="add_xslt">XSLT file for transforming results: </label>
110
        <input type="text" name="add_xslt" id="add_xslt" size="100" placeholder="[% xslt_path | html %]" value="[% server.add_xslt | html %]"/>
111
        </li>
112
113
        </ol>
114
        </fieldset>
115
116
        <fieldset class="action"><input type="submit" class="btn btn-primary" value="Save" /> <a class="cancel" href="/cgi-bin/koha/admin/oaiservers.pl">Cancel</a></fieldset>
117
    </form>
118
[% END %]
119
120
[% IF op == 'list' %]
121
    <div id="toolbar" class="btn-toolbar">
122
        <a id="newserver" class="btn btn-default" href="/cgi-bin/koha/admin/oaiservers.pl?op=add"><i class="fa fa-plus"></i> New OAI repository</a>
123
    </div>
124
    <h1>OAI repositories administration</h1>
125
    [% IF id %]
126
        You searched for record [% id | html %]
127
    [% ELSIF searchfield %]
128
        You searched for [% searchfield | html %]
129
    [% END %]
130
131
    <div class="page-section">
132
    <table id="serverst">
133
134
        <thead><tr><th>Id</th><th>Repository name</th><th>Endpoint</th><th>Set</th><th>Data format</th><th>Record type</th><th class="noExport">Actions</th>
135
        </tr></thead>
136
        <tbody>
137
        [% FOREACH loo IN loop %]
138
            <tr>
139
            <td>[% loo.id | html %]</td>
140
            <td><a href="/cgi-bin/koha/admin/oaiservers.pl?op=edit&amp;id=[% loo.id | uri %]">[% loo.servername | html %]</a></td><td>[% loo.endpoint | html %]</td><td>[% loo.oai_set | html %]</td>
141
            <td>[% loo.dataformat | html %]</td>
142
            <td>[% IF ( loo.recordtype == 'biblio' )  %]
143
                <span>Bibliographic</span>
144
                [% ELSIF ( loo.recordtype == 'authority' ) %]
145
                <span>Authority</span>
146
                [% END %]
147
            </td>
148
            <td>
149
                <div class="btn-group dropup">
150
                    <a class="btn btn-default btn-xs dropdown-toggle" id="reportactions[% savedreport.id | html %]" role="button" data-toggle="dropdown" href="#">
151
                        Actions <b class="caret"></b>
152
                    </a>
153
                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="reportactions[% savedreport.id | html %]">
154
                        <li><a href="/cgi-bin/koha/admin/oaiservers.pl?op=edit&amp;id=[% loo.id | uri %]"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a></li>
155
                        <li><a href="/cgi-bin/koha/admin/oaiservers.pl?op=add&amp;id=[% loo.id | uri %]"><i class="fa fa-copy"></i> Copy</a></li>
156
                        <li><a href="/cgi-bin/koha/admin/oaiservers.pl?op=delete_confirmed&amp;id=[% loo.id | uri %]" class="delete" data-servername="[% loo.servername | html %]"><i class="fa fa-trash-can"></i> Delete</a></li>
157
                    </ul>
158
                </div>
159
            </td>
160
            </tr>
161
        [% END %]
162
        </tbody>
163
    </table>
164
    </div> <!-- /.page-section -->
165
[% END %]
166
167
            </main>
168
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
169
170
        <div class="col-sm-2 col-sm-pull-10">
171
            <aside>
172
                [% INCLUDE 'admin-menu.inc' %]
173
            </aside>
174
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
175
     </div> <!-- /.row -->
176
177
[% MACRO jsinclude BLOCK %]
178
    [% Asset.js("js/admin-menu.js") | $raw %]
179
    [% IF op == 'list' %]
180
        [% INCLUDE 'datatables.inc' %]
181
    [% END %]
182
183
    <script>
184
        [% IF ( add_form ) %]
185
            $(document).ready(function(){
186
                // Update selects for dataformat and recordtype
187
                [% IF server %]
188
                    $("#dataformat").val('[% server.dataformat | html %]');
189
                    $("#recordtype").val('[% server.recordtype | html %]');
190
                [% END %]
191
                $( "#serverentry" ).validate({
192
                    rules: {
193
                        servername: { required: true },
194
                        host: { required: true },
195
                        port: {
196
                            number: true
197
                        },
198
                        rank: { number: true },
199
                    }
200
                });
201
                $("#serverentry").submit(function( event ) {
202
                    // enable recordtype to include field in post
203
                    $('#recordtype').prop('disabled',false);
204
                });
205
                $("#servername").on("blur",function(){
206
                    toUC(this);
207
                });
208
            });
209
        [% ELSE %]
210
            $(document).ready(function() {
211
                $("#serverst").dataTable($.extend(true, {}, dataTablesDefaults, {
212
                    "aoColumnDefs": [
213
                        { "aTargets": [-1], "bSortable": false, "bSearchable": false },
214
                    ],
215
                    "sPaginationType": "full"
216
                }));
217
                $(".delete").on("click",function(e){
218
                    var servername = $(this).data("servername");
219
                    if( confirm( _("Are you sure you want to delete repository %s?").format(servername) ) ) {
220
                        return true;
221
                    } else {
222
                        e.preventDefault();
223
                    }
224
                });
225
            });
226
        [% END %]
227
    </script>
228
[% END %]
229
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref (+5 lines)
Lines 80-85 Web services: Link Here
80
                  transient: might be emptied or truncated at some point (transient)
80
                  transient: might be emptied or truncated at some point (transient)
81
                  no: will never have any data in it (no)
81
                  no: will never have any data in it (no)
82
            - "."
82
            - "."
83
        -
84
            - If set, a report email will be sent to this address after an OAI harvest
85
            - pref: "OAI-PMH:HarvestEmailReport"
86
              class: Text
87
83
    ILS-DI:
88
    ILS-DI:
84
        -
89
        -
85
            - pref: ILS-DI
90
            - pref: ILS-DI
(-)a/koha-tmpl/intranet-tmpl/prog/en/xslt/AuthOAIDCtoMARC21XML.xsl (+35 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet version="1.0"
3
    xmlns:dc="http://purl.org/dc/elements/1.1/"
4
    xmlns:dcterms="http://purl.org/dc/terms/1.1"
5
    xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
6
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7
    xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
8
        http://www.openarchives.org/OAI/2.0/oai_dc.xsd"
9
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10
    xmlns="http://www.loc.gov/MARC21/slim"  exclude-result-prefixes="dc dcterms oai_dc">
11
12
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
13
14
    <xsl:template match="/">
15
        <collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" >
16
            <xsl:apply-templates />
17
        </collection>
18
    </xsl:template>
19
20
    <xsl:template match="oai_dc:dc">
21
        <record>
22
23
            <xsl:variable name="FamilyName" select="dc:FamilyName"/>
24
            <xsl:variable name="GivenName" select="dc:GivenName"/>
25
26
            <datafield tag="100" ind1="0" ind2=" ">
27
                <subfield code="a">
28
                    <xsl:value-of select="concat($FamilyName,', ',$GivenName)"/>
29
                </subfield>
30
            </datafield>
31
32
        </record>
33
   </xsl:template>
34
35
</xsl:stylesheet>
(-)a/koha-tmpl/intranet-tmpl/prog/en/xslt/AuthOAIDCtoUNIMARCXML.xsl (+42 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet version="1.0"
3
    xmlns:dc="http://purl.org/dc/elements/1.1/"
4
    xmlns:dcterms="http://purl.org/dc/terms/1.1"
5
    xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
6
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7
    xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
8
        http://www.openarchives.org/OAI/2.0/oai_dc.xsd"
9
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10
    xmlns="http://www.loc.gov/MARC21/slim"  exclude-result-prefixes="dc dcterms oai_dc">
11
12
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
13
14
    <xsl:template match="/">
15
        <collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" >
16
            <xsl:apply-templates />
17
        </collection>
18
    </xsl:template>
19
20
    <xsl:template match="oai_dc:dc">
21
        <record>
22
23
            <xsl:for-each select="dc:FamilyName">
24
                <datafield tag="200" ind1="0" ind2=" ">
25
                    <subfield code="a">
26
                        <xsl:value-of select="."/>
27
                    </subfield>
28
                </datafield>
29
            </xsl:for-each>
30
31
            <xsl:for-each select="dc:GivenName">
32
                <datafield tag="200" ind1="0" ind2=" ">
33
                    <subfield code="b">
34
                        <xsl:value-of select="."/>
35
                    </subfield>
36
                </datafield>
37
            </xsl:for-each>
38
39
        </record>
40
   </xsl:template>
41
42
</xsl:stylesheet>
(-)a/koha-tmpl/intranet-tmpl/prog/en/xslt/OAIDCtoMARC21XML.xsl (+367 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet version="1.0"
3
    xmlns:dc="http://purl.org/dc/elements/1.1/"
4
    xmlns:dcterms="http://purl.org/dc/terms/1.1"
5
    xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
6
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7
    xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
8
        http://www.openarchives.org/OAI/2.0/oai_dc.xsd"
9
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10
    xmlns="http://www.loc.gov/MARC21/slim"  exclude-result-prefixes="dc dcterms oai_dc">
11
12
    <xsl:import href="MARC21slimUtils.xsl"/>
13
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
14
15
16
    <xsl:template match="/">
17
        <collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" >
18
            <xsl:apply-templates />
19
        </collection>
20
    </xsl:template>
21
22
    <xsl:template name="OAI-PMH">
23
             <xsl:for-each select = "ListRecords/record/metadata/oai_dc:dc">
24
                <xsl:apply-templates  />
25
             </xsl:for-each>
26
             <xsl:for-each select = "GetRecord/record/metadata/oai_dc:dc">
27
                <xsl:apply-templates  />
28
             </xsl:for-each>
29
    </xsl:template>
30
31
    <xsl:template match="text()" />
32
    <xsl:template match="oai_dc:dc">
33
        <record>
34
            <xsl:element name="leader">
35
                <xsl:variable name="type" select="dc:type"/>
36
                <xsl:variable name="leader06">
37
                    <xsl:choose>
38
                        <xsl:when test="$type='collection'">p</xsl:when>
39
                        <xsl:when test="$type='dataset'">m</xsl:when>
40
                        <xsl:when test="$type='event'">r</xsl:when>
41
                        <xsl:when test="$type='image'">k</xsl:when>
42
                        <xsl:when test="$type='interactive resource'">m</xsl:when>
43
                        <xsl:when test="$type='service'">m</xsl:when>
44
                        <xsl:when test="$type='software'">m</xsl:when>
45
                        <xsl:when test="$type='sound'">i</xsl:when>
46
                        <xsl:when test="$type='text'">a</xsl:when>
47
                        <xsl:otherwise>a</xsl:otherwise>
48
                    </xsl:choose>
49
                </xsl:variable>
50
                <xsl:variable name="leader07">
51
                    <xsl:choose>
52
                        <xsl:when test="$type='collection'">c</xsl:when>
53
                        <xsl:otherwise>m</xsl:otherwise>
54
                    </xsl:choose>
55
                </xsl:variable>
56
                <xsl:value-of select="concat('      ',$leader06,$leader07,'         3u     ')"/>
57
            </xsl:element>
58
59
            <datafield tag="042" ind1=" " ind2=" ">
60
                <subfield code="a">dc</subfield>
61
            </datafield>
62
63
64
65
            <xsl:for-each select="dc:creator">
66
                <xsl:choose>
67
                    <xsl:when test="(.!='') and (position()=1)">
68
                        <xsl:call-template name="persname_template">
69
                            <xsl:with-param name="string" select="." />
70
                            <xsl:with-param name="field" select="'100'" />
71
                            <xsl:with-param name="ind1" select = "'1'" />
72
                            <xsl:with-param name="ind2" select = "'0'" />
73
                            <xsl:with-param name="type" select="'author'" />
74
                        </xsl:call-template>
75
                    </xsl:when>
76
                    <xsl:otherwise>
77
                        <xsl:if test=".!=''">
78
                            <xsl:call-template name="persname_template">
79
                                <xsl:with-param name="string" select="." />
80
                                <xsl:with-param name="field" select="'700'" />
81
                                <xsl:with-param name="ind1" select = "'1'" />
82
                                <xsl:with-param name="ind2" select = "'0'" />
83
                                <xsl:with-param name="type" select="'author'" />
84
                            </xsl:call-template>
85
                        </xsl:if>
86
                    </xsl:otherwise>
87
                </xsl:choose>
88
            </xsl:for-each>
89
90
91
            <xsl:for-each select="dc:title[1]">
92
                <datafield tag="245" ind1="0" ind2="0">
93
                    <subfield code="a">
94
                        <xsl:value-of select="."/>
95
                    </subfield>
96
                </datafield>
97
            </xsl:for-each>
98
99
            <xsl:for-each select="dc:title[position()>1]">
100
                <xsl:if test=".!=''">
101
                    <datafield tag="246" ind1="3" ind2="3">
102
                        <subfield code="a">
103
                            <xsl:value-of select="."/>
104
                        </subfield>
105
                    </datafield>
106
                </xsl:if>
107
            </xsl:for-each>
108
109
            <xsl:choose>
110
                <xsl:when test="dc:publisher">
111
                    <xsl:if test="translate(dc:publisher/.,'.,:;','')!=''">
112
                        <datafield tag="260" ind1=" " ind2=" ">
113
                        <xsl:choose>
114
                            <xsl:when test="dc:date">
115
                                <subfield code="b"><xsl:value-of select="dc:publisher[1]"/>, </subfield>
116
                                <xsl:if test="translate(dc:date[1]/., '.,:;','')!=''">
117
                                    <subfield code="c"><xsl:value-of select="dc:date[1]" />.</subfield>
118
                                </xsl:if>
119
                            </xsl:when>
120
                            <xsl:otherwise>
121
                                <subfield code="b"><xsl:value-of select="dc:publisher[1]"/>.</subfield>
122
                            </xsl:otherwise>
123
                        </xsl:choose>
124
                        </datafield>
125
                    </xsl:if>
126
                </xsl:when>
127
                <xsl:otherwise>
128
                    <xsl:if test="translate(dc:date[1],'.,:;','')!=''">
129
                        <datafield tag="260" ind1=" " ind2=" ">
130
                            <subfield code="c"><xsl:value-of select="dc:date[1]" />.</subfield>
131
                        </datafield>
132
                    </xsl:if>
133
                </xsl:otherwise>
134
            </xsl:choose>
135
136
            <xsl:for-each select="dc:coverage">
137
                <xsl:choose>
138
                    <xsl:when test="translate(., '0123456789-.?','')=''">
139
                        <!--Likely;this is a date-->
140
                        <datafield tag="500" ind1=" " ind2=" ">
141
                            <subfield code="a"><xsl:value-of select="."/></subfield>
142
                        </datafield>
143
                    </xsl:when>
144
                    <xsl:otherwise>
145
                        <!--likely a geographic subject, we will print this later-->
146
                    </xsl:otherwise>
147
                </xsl:choose>
148
            </xsl:for-each>
149
150
            <xsl:for-each select="dc:identifier">
151
                <xsl:if test="position()!=last()">
152
                    <datafield tag="500" ind1=" " ind2=" ">
153
                        <subfield code="a"><xsl:value-of select="." /></subfield>
154
                    </datafield>
155
                </xsl:if>
156
            </xsl:for-each>
157
158
            <xsl:for-each select="dc:description">
159
                <datafield tag="520" ind1=" " ind2=" ">
160
                    <subfield code="a">
161
                        <xsl:value-of select="normalize-space(.)"/>
162
                    </subfield>
163
                </datafield>
164
            </xsl:for-each>
165
166
167
            <xsl:for-each select="dc:rights">
168
                <datafield tag="540" ind1=" " ind2=" ">
169
                    <subfield code="a">
170
                        <xsl:value-of select="."/>
171
                    </subfield>
172
                </datafield>
173
            </xsl:for-each>
174
175
176
            <xsl:for-each select="dc:language">
177
                <datafield tag="546" ind1=" " ind2=" ">
178
                    <subfield code="a">
179
                        <xsl:value-of select="."/>
180
                    </subfield>
181
                </datafield>
182
            </xsl:for-each>
183
184
185
186
            <xsl:for-each select="dc:subject">
187
                <datafield tag="690" ind1=" " ind2=" ">
188
                    <subfield code="a">
189
                        <xsl:value-of select="."/>
190
                    </subfield>
191
                </datafield>
192
            </xsl:for-each>
193
194
            <xsl:for-each select="dc:coverage">
195
                <xsl:choose>
196
                    <xsl:when test="translate(., '0123456789-.?','')=''">
197
                        <!--Likely; this is a date-->
198
                    </xsl:when>
199
                    <xsl:otherwise>
200
                        <!--likely a geographic subject-->
201
                        <datafield tag="691" ind1=" " ind2=" ">
202
                            <subfield code="a"><xsl:value-of select="." /></subfield>
203
                        </datafield>
204
                    </xsl:otherwise>
205
                </xsl:choose>
206
            </xsl:for-each>
207
208
209
            <xsl:for-each select="dc:type">
210
                <datafield tag="655" ind1="7" ind2=" ">
211
                    <subfield code="a">
212
                        <xsl:value-of select="."/>
213
                    </subfield>
214
                    <subfield code="2">local</subfield>
215
                </datafield>
216
            </xsl:for-each>
217
218
219
220
            <xsl:for-each select="dc:contributer">
221
                    <xsl:call-template name="persname_template">
222
                        <xsl:with-param name="string" select="." />
223
                        <xsl:with-param name="field" select="'100'" />
224
                        <xsl:with-param name="ind1" select = "'1'" />
225
                        <xsl:with-param name="ind2" select = "'0'" />
226
                        <xsl:with-param name="type" select="'contributor'" />
227
                    </xsl:call-template>
228
            </xsl:for-each>
229
230
            <xsl:for-each select="dc:source">
231
                <datafield tag="786" ind1="0" ind2=" ">
232
                    <subfield code="n">
233
                        <xsl:value-of select="."/>
234
                    </subfield>
235
                </datafield>
236
            </xsl:for-each>
237
238
            <xsl:for-each select="dc:relation">
239
                <datafield tag="787" ind1="0" ind2=" ">
240
                    <subfield code="n">
241
                        <xsl:value-of select="."/>
242
                    </subfield>
243
                </datafield>
244
            </xsl:for-each>
245
246
            <xsl:if test="dc:identifier">
247
                <datafield tag="856" ind1="4" ind2="1">
248
                    <subfield code="u"><xsl:value-of select="dc:identifier[last()]" /></subfield>
249
                    <subfield code="z">Connect to this object online.</subfield>
250
                </datafield>
251
            </xsl:if>
252
        </record>
253
254
    </xsl:template>
255
<xsl:template name="persname_template">
256
      <xsl:param name="string" />
257
      <xsl:param name="field" />
258
      <xsl:param name="ind1" />
259
      <xsl:param name="ind2" />
260
      <xsl:param name="type" />
261
      <datafield>
262
         <xsl:attribute name="tag">
263
            <xsl:value-of select="$field" />
264
         </xsl:attribute>
265
         <xsl:attribute name="ind1">
266
            <xsl:value-of select="$ind1" />
267
         </xsl:attribute>
268
         <xsl:attribute name="ind2">
269
            <xsl:value-of select="$ind2" />
270
         </xsl:attribute>
271
272
         <!-- Sample input: Brightman, Samuel C. (Samuel Charles), 1911-1992 -->
273
         <!-- Sample output: $aBrightman, Samuel C. $q(Samuel Charles), $d1911-. -->
274
         <!-- will handle names with dashes e.g. Bourke-White, Margaret -->
275
276
         <!-- CAPTURE PRIMARY NAME BY LOOKING FOR A PAREN OR A DASH OR NEITHER -->
277
         <xsl:choose>
278
            <!-- IF A PAREN, STOP AT AN OPENING PAREN -->
279
            <xsl:when test="contains($string, '(')!=0">
280
               <subfield code="a">
281
                  <xsl:value-of select="substring-before($string, '(')" />
282
               </subfield>
283
            </xsl:when>
284
            <!-- IF A DASH, CHECK IF IT'S A DATE OR PART OF THE NAME -->
285
            <xsl:when test="contains($string, '-')!=0">
286
               <xsl:variable name="name_1" select="substring-before($string, '-')" />
287
               <xsl:choose>
288
                  <!-- IF IT'S A DATE REMOVE IT -->
289
                  <xsl:when test="translate(substring($name_1, (string-length($name_1)), 1), '0123456789', '9999999999') = '9'">
290
                     <xsl:variable name="name" select="substring($name_1, 1, (string-length($name_1)-6))" />
291
                     <subfield code="a">
292
                        <xsl:value-of select="$name" />
293
                     </subfield>
294
                  </xsl:when>
295
                  <!-- IF IT'S NOT A DATE, CHECK WHETHER THERE IS A DATE LATER -->
296
                  <xsl:otherwise>
297
                     <xsl:variable name="remainder" select="substring-after($string, '-')" />
298
                     <xsl:choose>
299
                        <!-- IF THERE'S A DASH, ASSUME IT'S A DATE AND REMOVE IT -->
300
                        <xsl:when test="contains($remainder, '-')!=0">
301
                           <xsl:variable name="tmp" select="substring-before($remainder, '-')" />
302
                           <xsl:variable name="name_2" select="substring($tmp, 1, (string-length($tmp)-6))" />
303
                           <subfield code="a">
304
                              <xsl:value-of select="$name_1" />-<xsl:value-of select="$name_2" />
305
                           </subfield>
306
                        </xsl:when>
307
                        <!-- IF THERE'S NO DASH IN THE REMAINDER, OUTPUT IT -->
308
                        <xsl:otherwise>
309
                           <subfield code="a">
310
                              <xsl:value-of select="$string" />
311
                           </subfield>
312
                        </xsl:otherwise>
313
                     </xsl:choose>
314
                  </xsl:otherwise>
315
               </xsl:choose>
316
            </xsl:when>
317
            <!-- NO DASHES, NO PARENS, JUST OUTPUT THE NAME -->
318
            <xsl:otherwise>
319
               <subfield code="a">
320
                  <xsl:value-of select="$string" />
321
               </subfield>
322
            </xsl:otherwise>
323
         </xsl:choose>
324
325
         <!-- CAPTURE SECONDARY NAME IN PARENS FOR SUBFIELD Q -->
326
         <xsl:if test="contains($string, '(')!=0">
327
            <xsl:variable name="subq_tmp" select="substring-after($string, '(')" />
328
            <xsl:variable name="subq" select="substring-before($subq_tmp, ')')" />
329
            <subfield code="q">
330
               (<xsl:value-of select="$subq" />)
331
            </subfield>
332
         </xsl:if>
333
334
         <!-- CAPTURE DATE FOR SUBFIELD D, ASSUME DATE IS LAST ITEM IN FIELD -->
335
         <!-- Note: does not work if name has a dash in it -->
336
         <xsl:if test="contains($string, '-')!=0">
337
            <xsl:variable name="date_tmp" select="substring-before($string, '-')" />
338
            <xsl:variable name="remainder" select="substring-after($string, '-')" />
339
            <xsl:choose>
340
               <!-- CHECK SECOND HALF FOR ANOTHER DASH; IF PRESENT, ASSUME THAT IS DATE -->
341
               <xsl:when test="contains($remainder, '-')!=0">
342
                  <xsl:variable name="tmp" select="substring-before($remainder, '-')" />
343
                  <xsl:variable name="date_1" select="substring($remainder, (string-length($tmp)-3))" />
344
                  <!-- CHECK WHETHER IT HAS A NUMBER BEFORE IT AND IF SO, OUTPUT IT AS DATE -->
345
                  <xsl:if test="translate(substring($date_1, 1, 1), '0123456789', '9999999999') = '9'">
346
                     <subfield code="d">
347
                        <xsl:value-of select="$date_1" />.
348
                     </subfield>
349
                  </xsl:if>
350
               </xsl:when>
351
               <!-- OTHERWISE THIS IS THE ONLY DASH SO TAKE IT -->
352
               <xsl:otherwise>
353
                  <xsl:variable name="date_2" select="substring($string, (string-length($date_tmp)-3))" />
354
                  <!-- CHECK WHETHER IT HAS A NUMBER BEFORE IT AND IF SO, OUTPUT IT AS DATE -->
355
                  <xsl:if test="translate(substring($date_2, 1, 1), '0123456789', '9999999999') = '9'">
356
                     <subfield code="d">
357
                        <xsl:value-of select="$date_2" />.
358
                     </subfield>
359
                  </xsl:if>
360
               </xsl:otherwise>
361
            </xsl:choose>
362
         </xsl:if>
363
         <subfield code="e"><xsl:value-of select="$type" /></subfield>
364
      </datafield>
365
   </xsl:template>
366
367
</xsl:stylesheet>
(-)a/koha-tmpl/intranet-tmpl/prog/en/xslt/OAIDCtoUNIMARCXML.xsl (+341 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet version="1.0"
3
    xmlns:dc="http://purl.org/dc/elements/1.1/"
4
    xmlns:dcterms="http://purl.org/dc/terms/1.1"
5
    xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
6
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7
    xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
8
        http://www.openarchives.org/OAI/2.0/oai_dc.xsd"
9
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10
    xmlns="http://www.loc.gov/MARC21/slim"  exclude-result-prefixes="dc dcterms oai_dc">
11
12
    <xsl:import href="MARC21slimUtils.xsl"/>
13
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
14
15
16
    <xsl:template match="/">
17
        <collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" >
18
            <xsl:apply-templates />
19
        </collection>
20
    </xsl:template>
21
22
    <xsl:template name="OAI-PMH">
23
             <xsl:for-each select = "ListRecords/record/metadata/oai_dc:dc">
24
                <xsl:apply-templates  />
25
             </xsl:for-each>
26
             <xsl:for-each select = "GetRecord/record/metadata/oai_dc:dc">
27
                <xsl:apply-templates  />
28
             </xsl:for-each>
29
    </xsl:template>
30
31
    <xsl:template match="text()" />
32
    <xsl:template match="oai_dc:dc">
33
        <record>
34
35
            <xsl:for-each select="dc:creator">
36
                <xsl:call-template name="persname_template">
37
                    <xsl:with-param name="string" select="." />
38
                    <xsl:with-param name="field" select="'700'" />
39
                    <xsl:with-param name="ind1" select = "'1'" />
40
                    <xsl:with-param name="ind2" select = "'0'" />
41
                    <xsl:with-param name="type" select="'author'" />
42
                </xsl:call-template>
43
            </xsl:for-each>
44
45
46
            <xsl:for-each select="dc:title[1]">
47
                <datafield tag="200" ind1="0" ind2=" ">
48
                    <subfield code="a">
49
                        <xsl:value-of select="."/>
50
                    </subfield>
51
                </datafield>
52
            </xsl:for-each>
53
54
            <xsl:for-each select="dc:title[position()>1]">
55
                <xsl:if test=".!=''">
56
                    <datafield tag="532" ind1="3" ind2="0">
57
                        <subfield code="a">
58
                            <xsl:value-of select="."/>
59
                        </subfield>
60
                    </datafield>
61
                </xsl:if>
62
            </xsl:for-each>
63
64
            <xsl:choose>
65
                <xsl:when test="dc:publisher">
66
                    <xsl:if test="translate(dc:publisher/.,'.,:;','')!=''">
67
                        <datafield tag="214" ind1=" " ind2=" ">
68
                        <xsl:choose>
69
                            <xsl:when test="dc:date">
70
                                <subfield code="c"><xsl:value-of select="dc:publisher[1]"/>, </subfield>
71
                                <xsl:if test="translate(dc:date[1]/., '.,:;','')!=''">
72
                                    <subfield code="d"><xsl:value-of select="dc:date[1]" />.</subfield>
73
                                </xsl:if>
74
                            </xsl:when>
75
                            <xsl:otherwise>
76
                                <subfield code="c"><xsl:value-of select="dc:publisher[1]"/>.</subfield>
77
                            </xsl:otherwise>
78
                        </xsl:choose>
79
                        </datafield>
80
                    </xsl:if>
81
                </xsl:when>
82
                <xsl:otherwise>
83
                    <xsl:if test="translate(dc:date[1],'.,:;','')!=''">
84
                        <datafield tag="214" ind1=" " ind2=" ">
85
                            <subfield code="d"><xsl:value-of select="dc:date[1]" />.</subfield>
86
                        </datafield>
87
                    </xsl:if>
88
                </xsl:otherwise>
89
            </xsl:choose>
90
91
92
            <xsl:for-each select="dc:contributor">
93
                <datafield tag="701" ind1=" " ind2=" ">
94
                    <subfield code="a">
95
                        <xsl:value-of select="."/>
96
                    </subfield>
97
                </datafield>
98
            </xsl:for-each>
99
100
101
            <xsl:for-each select="dc:coverage">
102
                <xsl:choose>
103
                    <xsl:when test="translate(., '0123456789-.?','')=''">
104
                        <!--Likely;this is a date-->
105
                        <datafield tag="215" ind1=" " ind2=" ">
106
                            <subfield code="a"><xsl:value-of select="."/></subfield>
107
                        </datafield>
108
                    </xsl:when>
109
                    <xsl:otherwise>
110
                        <!--likely a geographic subject, we will print this later-->
111
                    </xsl:otherwise>
112
                </xsl:choose>
113
            </xsl:for-each>
114
115
116
            <xsl:for-each select="dc:description">
117
                <datafield tag="330" ind1=" " ind2=" ">
118
                    <subfield code="a">
119
                        <xsl:value-of select="normalize-space(.)"/>
120
                    </subfield>
121
                </datafield>
122
            </xsl:for-each>
123
124
125
            <!-- no match -->
126
            <xsl:for-each select="dc:rights">
127
                <datafield tag="371" ind1=" " ind2=" ">
128
                    <subfield code="a">
129
                        <xsl:value-of select="."/>
130
                    </subfield>
131
                </datafield>
132
            </xsl:for-each>
133
134
135
            <xsl:for-each select="dc:language">
136
                <datafield tag="101" ind1=" " ind2=" ">
137
                    <subfield code="a">
138
                        <xsl:value-of select="."/>
139
                    </subfield>
140
                </datafield>
141
            </xsl:for-each>
142
143
144
            <xsl:for-each select="dc:subject">
145
                <datafield tag="610" ind1=" " ind2=" ">
146
                    <subfield code="a">
147
                        <xsl:value-of select="."/>
148
                    </subfield>
149
                </datafield>
150
            </xsl:for-each>
151
152
153
            <!-- Resource type will most likely need a specific instance-based mapping -->
154
            <!--
155
            <xsl:for-each select="dc:type">
156
                <datafield tag="099" ind1=" " ind2=" ">
157
                    <subfield code="t">
158
                        <xsl:value-of select="."/>
159
                    </subfield>
160
                </datafield>
161
            </xsl:for-each>
162
            -->
163
164
165
            <!-- no match -->
166
            <xsl:for-each select="dc:coverage">
167
                <xsl:choose>
168
                    <xsl:when test="translate(., '0123456789-.?','')=''">
169
                        <!--Likely; this is a date-->
170
                    </xsl:when>
171
                    <xsl:otherwise>
172
                        <!--likely a geographic subject-->
173
                        <datafield tag="691" ind1=" " ind2=" ">
174
                            <subfield code="a"><xsl:value-of select="." /></subfield>
175
                        </datafield>
176
                    </xsl:otherwise>
177
                </xsl:choose>
178
            </xsl:for-each>
179
180
181
            <!-- no match -->
182
            <xsl:for-each select="dc:type">
183
                <datafield tag="655" ind1="7" ind2=" ">
184
                    <subfield code="a">
185
                        <xsl:value-of select="."/>
186
                    </subfield>
187
                    <subfield code="2">local</subfield>
188
                </datafield>
189
            </xsl:for-each>
190
191
192
            <xsl:for-each select="dc:contributer">
193
                    <xsl:call-template name="persname_template">
194
                        <xsl:with-param name="string" select="." />
195
                        <xsl:with-param name="field" select="'702'" />
196
                        <xsl:with-param name="ind1" select = "'1'" />
197
                        <xsl:with-param name="ind2" select = "'0'" />
198
                        <xsl:with-param name="type" select="'contributor'" />
199
                    </xsl:call-template>
200
            </xsl:for-each>
201
202
            <!-- no match -->
203
            <xsl:for-each select="dc:source">
204
                <datafield tag="786" ind1="0" ind2=" ">
205
                    <subfield code="n">
206
                        <xsl:value-of select="."/>
207
                    </subfield>
208
                </datafield>
209
            </xsl:for-each>
210
211
            <!-- TODO: 455 456 470 488-->
212
            <xsl:for-each select="dc:relation">
213
                <datafield tag="488" ind1="0" ind2=" ">
214
                    <subfield code="e">
215
                        <xsl:value-of select="."/>
216
                    </subfield>
217
                </datafield>
218
            </xsl:for-each>
219
220
            <xsl:if test="dc:identifier">
221
                <datafield tag="856" ind1="4" ind2="1">
222
                    <subfield code="u"><xsl:value-of select="dc:identifier[last()]" /></subfield>
223
                    <subfield code="z">Connect to this object online.</subfield>
224
                </datafield>
225
            </xsl:if>
226
        </record>
227
228
    </xsl:template>
229
<xsl:template name="persname_template">
230
      <xsl:param name="string" />
231
      <xsl:param name="field" />
232
      <xsl:param name="ind1" />
233
      <xsl:param name="ind2" />
234
      <xsl:param name="type" />
235
      <datafield>
236
         <xsl:attribute name="tag">
237
            <xsl:value-of select="$field" />
238
         </xsl:attribute>
239
         <xsl:attribute name="ind1">
240
            <xsl:value-of select="$ind1" />
241
         </xsl:attribute>
242
         <xsl:attribute name="ind2">
243
            <xsl:value-of select="$ind2" />
244
         </xsl:attribute>
245
246
         <!-- Sample input: Brightman, Samuel C. (Samuel Charles), 1911-1992 -->
247
         <!-- Sample output: $aBrightman, Samuel C. $q(Samuel Charles), $d1911-. -->
248
         <!-- will handle names with dashes e.g. Bourke-White, Margaret -->
249
250
         <!-- CAPTURE PRIMARY NAME BY LOOKING FOR A PAREN OR A DASH OR NEITHER -->
251
         <xsl:choose>
252
            <!-- IF A PAREN, STOP AT AN OPENING PAREN -->
253
            <xsl:when test="contains($string, '(')!=0">
254
               <subfield code="a">
255
                  <xsl:value-of select="substring-before($string, '(')" />
256
               </subfield>
257
            </xsl:when>
258
            <!-- IF A DASH, CHECK IF IT'S A DATE OR PART OF THE NAME -->
259
            <xsl:when test="contains($string, '-')!=0">
260
               <xsl:variable name="name_1" select="substring-before($string, '-')" />
261
               <xsl:choose>
262
                  <!-- IF IT'S A DATE REMOVE IT -->
263
                  <xsl:when test="translate(substring($name_1, (string-length($name_1)), 1), '0123456789', '9999999999') = '9'">
264
                     <xsl:variable name="name" select="substring($name_1, 1, (string-length($name_1)-6))" />
265
                     <subfield code="a">
266
                        <xsl:value-of select="$name" />
267
                     </subfield>
268
                  </xsl:when>
269
                  <!-- IF IT'S NOT A DATE, CHECK WHETHER THERE IS A DATE LATER -->
270
                  <xsl:otherwise>
271
                     <xsl:variable name="remainder" select="substring-after($string, '-')" />
272
                     <xsl:choose>
273
                        <!-- IF THERE'S A DASH, ASSUME IT'S A DATE AND REMOVE IT -->
274
                        <xsl:when test="contains($remainder, '-')!=0">
275
                           <xsl:variable name="tmp" select="substring-before($remainder, '-')" />
276
                           <xsl:variable name="name_2" select="substring($tmp, 1, (string-length($tmp)-6))" />
277
                           <subfield code="a">
278
                              <xsl:value-of select="$name_1" />-<xsl:value-of select="$name_2" />
279
                           </subfield>
280
                        </xsl:when>
281
                        <!-- IF THERE'S NO DASH IN THE REMAINDER, OUTPUT IT -->
282
                        <xsl:otherwise>
283
                           <subfield code="a">
284
                              <xsl:value-of select="$string" />
285
                           </subfield>
286
                        </xsl:otherwise>
287
                     </xsl:choose>
288
                  </xsl:otherwise>
289
               </xsl:choose>
290
            </xsl:when>
291
            <!-- NO DASHES, NO PARENS, JUST OUTPUT THE NAME -->
292
            <xsl:otherwise>
293
               <subfield code="a">
294
                  <xsl:value-of select="$string" />
295
               </subfield>
296
            </xsl:otherwise>
297
         </xsl:choose>
298
299
         <!-- CAPTURE SECONDARY NAME IN PARENS FOR SUBFIELD Q -->
300
         <xsl:if test="contains($string, '(')!=0">
301
            <xsl:variable name="subq_tmp" select="substring-after($string, '(')" />
302
            <xsl:variable name="subq" select="substring-before($subq_tmp, ')')" />
303
            <subfield code="q">
304
               (<xsl:value-of select="$subq" />)
305
            </subfield>
306
         </xsl:if>
307
308
         <!-- CAPTURE DATE FOR SUBFIELD D, ASSUME DATE IS LAST ITEM IN FIELD -->
309
         <!-- Note: does not work if name has a dash in it -->
310
         <xsl:if test="contains($string, '-')!=0">
311
            <xsl:variable name="date_tmp" select="substring-before($string, '-')" />
312
            <xsl:variable name="remainder" select="substring-after($string, '-')" />
313
            <xsl:choose>
314
               <!-- CHECK SECOND HALF FOR ANOTHER DASH; IF PRESENT, ASSUME THAT IS DATE -->
315
               <xsl:when test="contains($remainder, '-')!=0">
316
                  <xsl:variable name="tmp" select="substring-before($remainder, '-')" />
317
                  <xsl:variable name="date_1" select="substring($remainder, (string-length($tmp)-3))" />
318
                  <!-- CHECK WHETHER IT HAS A NUMBER BEFORE IT AND IF SO, OUTPUT IT AS DATE -->
319
                  <xsl:if test="translate(substring($date_1, 1, 1), '0123456789', '9999999999') = '9'">
320
                     <subfield code="d">
321
                        <xsl:value-of select="$date_1" />.
322
                     </subfield>
323
                  </xsl:if>
324
               </xsl:when>
325
               <!-- OTHERWISE THIS IS THE ONLY DASH SO TAKE IT -->
326
               <xsl:otherwise>
327
                  <xsl:variable name="date_2" select="substring($string, (string-length($date_tmp)-3))" />
328
                  <!-- CHECK WHETHER IT HAS A NUMBER BEFORE IT AND IF SO, OUTPUT IT AS DATE -->
329
                  <xsl:if test="translate(substring($date_2, 1, 1), '0123456789', '9999999999') = '9'">
330
                     <subfield code="d">
331
                        <xsl:value-of select="$date_2" />.
332
                     </subfield>
333
                  </xsl:if>
334
               </xsl:otherwise>
335
            </xsl:choose>
336
         </xsl:if>
337
         <subfield code="e"><xsl:value-of select="$type" /></subfield>
338
      </datafield>
339
   </xsl:template>
340
341
</xsl:stylesheet>
(-)a/koha-tmpl/intranet-tmpl/prog/en/xslt/OAIMarcxml2KohaMarcxml.xsl (+23 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:marc="http://www.loc.gov/MARC21/slim">
3
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
4
5
 <!-- keep comments -->
6
  <xsl:template match="*[name()='metadata']">
7
    <xsl:apply-templates />
8
  </xsl:template>
9
10
  <xsl:template match="*">
11
    <!-- remove element prefix -->
12
    <xsl:element name="{local-name()}">
13
      <!-- process attributes -->
14
      <xsl:for-each select="@*">
15
        <!-- remove attribute prefix -->
16
        <xsl:attribute name="{local-name()}">
17
          <xsl:value-of select="."/>
18
        </xsl:attribute>
19
      </xsl:for-each>
20
      <xsl:apply-templates/>
21
    </xsl:element>
22
  </xsl:template>
23
</xsl:stylesheet>
(-)a/misc/cronjobs/harvest_oai.pl (+102 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# Copyright 2023 BibLibre
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
use warnings;
21
use strict;
22
use utf8;
23
24
use Getopt::Long qw( GetOptions );
25
use Koha::Script -cron;
26
use Koha::OAI::Client::Harvester;
27
use Koha::OaiServers;
28
use C4::Log qw( cronlogaction );
29
use Try::Tiny qw( catch try );
30
31
my $command_line_options = join( " ", @ARGV );
32
33
my ( $help, $verbose, $id, $days, $list, $force );
34
35
GetOptions(
36
    'h|help'         => \$help,
37
    'v|verbose'      => \$verbose,
38
    'r|repository:i' => \$id,
39
    'd|days:i'       => \$days,
40
    'l|list'         => \$list,
41
    'f|force'        => \$force,
42
);
43
my $usage = << 'ENDUSAGE';
44
45
This script starts an OAI Harvest
46
47
This script has the following parameters :
48
    -h --help: this message
49
    -v --verbose
50
    -r --repository: id of the OAI repository
51
    -d --days: number of days to harvest from (optional)
52
    -l --list: list the OAI repositories
53
    -f --force: force harvesting (ignore records datestamps)
54
55
ENDUSAGE
56
57
if ($help) {
58
    print $usage;
59
    exit;
60
}
61
62
if ($list) {
63
    my $servers = Koha::OaiServers->search( {}, { order_by => { -asc => 'id' } } )->unblessed;
64
    print "The following repositories are available: \n\n";
65
    foreach my $server (@$servers) {
66
        print $server->{'id'} . ": "
67
            . $server->{'servername'}
68
            . ", endpoint: "
69
            . $server->{'endpoint'}
70
            . ", set: "
71
            . $server->{'oai_set'}
72
            . ", recordtype: "
73
            . $server->{'recordtype'} . "\n";
74
    }
75
    print "\n";
76
    exit;
77
}
78
79
if ( !$id ) {
80
    print "The repository parameter is mandatory.\n";
81
    print $usage . "\n";
82
}
83
84
my $script_handler = Koha::Script->new( { script => $0 } );
85
86
try {
87
    $script_handler->lock_exec;
88
} catch {
89
    my $message = "Skipping execution of $0";
90
    print "$message\n" if $verbose;
91
    cronlogaction( { info => $message } );
92
    exit;
93
};
94
95
cronlogaction( { action => 'Start', info => "Starting OAI Harvest" } );
96
cronlogaction( { info   => "Command line: $command_line_options" } );
97
98
my $harvester =
99
    Koha::OAI::Client::Harvester->new( { server => $id, verbose => $verbose, days => $days, force => $force } );
100
101
cronlogaction( { action => 'End', info => "Ending OAI Harvest" } );
102
exit(0);
(-)a/t/db_dependent/Koha/OAIServers.t (-1 / +95 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2015 Koha Development team
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
use Modern::Perl;
21
use Test::More tests => 2;
22
use Test::Exception;
23
24
use t::lib::TestBuilder;
25
use Koha::Database;
26
use Koha::OaiServer;
27
use Koha::OaiServers;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
subtest 'new, find and delete tests' => sub {
33
    plan tests => 4;
34
    $schema->storage->txn_begin;
35
    my $nb_of_oais = Koha::OaiServers->search->count;
36
    my $new_oai_1  = Koha::OaiServer->new(
37
        {
38
            endpoint   => 'my_host1.org',
39
            oai_set    => 'set1',
40
            servername => 'my_test_1',
41
            dataformat => 'oai_dc',
42
            recordtype => 'biblio',
43
        }
44
    )->store;
45
    my $new_oai_2 = Koha::OaiServer->new(
46
        {
47
            endpoint   => 'my_host2.org',
48
            oai_set    => 'set2',
49
            servername => 'my_test_2',
50
            dataformat => 'marcxml',
51
            recordtype => 'authority',
52
        }
53
    )->store;
54
55
    like( $new_oai_1->id, qr|^\d+$|, 'Adding a new oai server should have set the id' );
56
    is( Koha::OaiServers->search->count, $nb_of_oais + 2, 'The 2 oai servers should have been added' );
57
58
    my $retrieved_oai_1 = Koha::OaiServers->find( $new_oai_1->id );
59
    is(
60
        $retrieved_oai_1->servername, $new_oai_1->servername,
61
        'Find a oai server by id should return the correct oai server'
62
    );
63
64
    $retrieved_oai_1->delete;
65
    is( Koha::OaiServers->search->count, $nb_of_oais + 1, 'Delete should have deleted the oai server' );
66
67
    $schema->storage->txn_rollback;
68
};
69
70
subtest 'Check NOT NULL without default values' => sub {
71
    plan tests => 5;
72
    $schema->storage->txn_begin;
73
    local $SIG{__WARN__} = sub { };    # TODO Needed it for suppressing DBIx warns
74
75
    my $server = Koha::OaiServer->new(
76
        {
77
            oai_set    => 'set3',
78
            dataformat => 'marcxml',
79
            recordtype => 'biblio',
80
        }
81
    );
82
83
    throws_ok { $server->store } 'DBIx::Class::Exception', 'Exception on empty endpoint';
84
    like( $@->{msg}, qr/'endpoint' doesn't have a default value/, 'Verified that DBIx blamed endpoint' );
85
86
    $server->endpoint('endpoint_added');
87
    throws_ok { $server->store } 'DBIx::Class::Exception', 'Exception on empty servername';
88
    like( $@->{msg}, qr/'servername' doesn't have a default value/, 'Verified that DBIx blamed servername' );
89
90
    $server->servername('servername_added');
91
92
    lives_ok { $server->store } 'No exceptions anymore';
93
94
    $schema->storage->txn_rollback;
95
};

Return to bug 35659