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

(-)a/Koha/OAI/Server/GetRecord.pm (-1 / +2 lines)
Lines 105-111 sub new { Link Here
105
    } else {
105
    } else {
106
        # We fetch it using this method, rather than the database directly,
106
        # We fetch it using this method, rather than the database directly,
107
        # so it'll include the item data
107
        # so it'll include the item data
108
        my $marcxml = $repository->get_biblio_marcxml($biblionumber, $args{metadataPrefix});
108
        my ( $marcxml, $marcxml_error ) = $repository->get_biblio_marcxml( $biblionumber, $args{metadataPrefix} );
109
        $args{about} = [$marcxml_error] if $marcxml_error;
109
        $self->record(
110
        $self->record(
110
            Koha::OAI::Server::Record->new($repository, $marcxml, $timestamp, \@setSpecs, %args)
111
            Koha::OAI::Server::Record->new($repository, $marcxml, $timestamp, \@setSpecs, %args)
111
        );
112
        );
(-)a/Koha/OAI/Server/ListBase.pm (-11 / +19 lines)
Lines 157-173 sub GetRecords { Link Here
157
                push @setSpecs, $_->{spec};
157
                push @setSpecs, $_->{spec};
158
            }
158
            }
159
            if ( $metadata ) {
159
            if ( $metadata ) {
160
                my $marcxml = !$deleted ? $repository->get_biblio_marcxml($biblionumber, $format) : undef;
160
                my ( $marcxml, $marcxml_error );
161
                if ( $marcxml ) {
161
                ( $marcxml, $marcxml_error ) = $repository->get_biblio_marcxml( $biblionumber, $format ) if !$deleted;
162
                  $self->record( Koha::OAI::Server::Record->new(
162
                my %params;
163
                      $repository, $marcxml, $timestamp, \@setSpecs,
163
                $params{identifier}     = $repository->{koha_identifier} . ':' . $biblionumber;
164
                      identifier      => $repository->{ koha_identifier } . ':' . $biblionumber,
164
                $params{metadataPrefix} = $token->{metadata_prefix};
165
                      metadataPrefix  => $token->{metadata_prefix}
165
                $params{about}          = [$marcxml_error] if $marcxml_error;
166
                  ) );
166
                if ($marcxml) {
167
                    $self->record(
168
                        Koha::OAI::Server::Record->new(
169
                            $repository, $marcxml, $timestamp, \@setSpecs,
170
                            %params
171
                        )
172
                    );
167
                } else {
173
                } else {
168
                  $self->record( Koha::OAI::Server::DeletedRecord->new(
174
                    $self->record(
169
                      $timestamp, \@setSpecs, identifier => $repository->{ koha_identifier } . ':' . $biblionumber
175
                        Koha::OAI::Server::DeletedRecord->new(
170
                  ) );
176
                            $timestamp, \@setSpecs, identifier => $repository->{koha_identifier} . ':' . $biblionumber
177
                        )
178
                    );
171
                }
179
                }
172
            } else {
180
            } else {
173
                $timestamp =~ s/ /T/;
181
                $timestamp =~ s/ /T/;
Lines 175-181 sub GetRecords { Link Here
175
                $self->identifier( HTTP::OAI::Header->new(
183
                $self->identifier( HTTP::OAI::Header->new(
176
                    identifier => $repository->{ koha_identifier} . ':' . $biblionumber,
184
                    identifier => $repository->{ koha_identifier} . ':' . $biblionumber,
177
                    datestamp  => $timestamp,
185
                    datestamp  => $timestamp,
178
                    status     => $deleted ? 'deleted' : undef
186
                    status     => $deleted ? 'deleted' : undef,
179
                ) );
187
                ) );
180
            }
188
            }
181
        }
189
        }
(-)a/Koha/OAI/Server/Repository.pm (-4 / +17 lines)
Lines 37-45 use YAML::XS; Link Here
37
use CGI qw/:standard -oldstyle_urls/;
37
use CGI qw/:standard -oldstyle_urls/;
38
use C4::Context;
38
use C4::Context;
39
use C4::Biblio qw( GetFrameworkCode );
39
use C4::Biblio qw( GetFrameworkCode );
40
use C4::Charset qw( StripNonXmlChars );
40
use Koha::XSLT::Base;
41
use Koha::XSLT::Base;
41
use Koha::Biblios;
42
use Koha::Biblios;
42
43
44
use MARC::Record;
45
43
=head1 NAME
46
=head1 NAME
44
47
45
Koha::OAI::Server::Repository - Handles OAI-PMH requests for a Koha database.
48
Koha::OAI::Server::Repository - Handles OAI-PMH requests for a Koha database.
Lines 178-185 sub get_biblio_marcxml { Link Here
178
    }
181
    }
179
182
180
    my $biblio = Koha::Biblios->find($biblionumber);
183
    my $biblio = Koha::Biblios->find($biblionumber);
181
    my $record = $biblio->metadata->record({ embed_items => $with_items, opac => 1 });
184
    my $record;
182
    if ( $expanded_avs ) {
185
186
    # Koha::Biblio::Metadata->record throws an exception on bad encoding,
187
    # we don't want OAI harvests to die, so we catch and warn, and try to clean the record
188
    eval { $record = $biblio->metadata->record( { embed_items => $with_items, opac => 1 } ); };
189
    my $decoding_error;
190
    if ($@) {
191
        my $exception = $@;
192
        $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') );
193
        $decoding_error = "INVALID_METADATA";
194
        $record         = $biblio->metadata->record_strip_nonxml( { embed_items => $with_items, opac => 1 } );
195
    }
196
    if ( $record && $expanded_avs ) {
183
        my $frameworkcode = GetFrameworkCode($biblionumber) || '';
197
        my $frameworkcode = GetFrameworkCode($biblionumber) || '';
184
        my $record_processor = Koha::RecordProcessor->new(
198
        my $record_processor = Koha::RecordProcessor->new(
185
            {
199
            {
Lines 192-199 sub get_biblio_marcxml { Link Here
192
        );
206
        );
193
        $record_processor->process($record);
207
        $record_processor->process($record);
194
    }
208
    }
195
209
    return ( $record ? $record->as_xml_record() : undef, $decoding_error );
196
    return $record ? $record->as_xml_record() : undef;
197
}
210
}
198
211
199
212
(-)a/koha-tmpl/opac-tmpl/xslt/OAI.xslt (-1 / +56 lines)
Lines 331-336 Link Here
331
                            </div>
331
                            </div>
332
                        </div>
332
                        </div>
333
                    </div>
333
                    </div>
334
                    <xsl:if test="oai:about">
335
                        <div class="panel panel-success">
336
                            <a data-toggle="collapse">
337
                                <xsl:attribute name="href">#about<xsl:value-of select="translate(oai:header/oai:identifier/text(), ':/.', '')"></xsl:value-of></xsl:attribute>
338
                                <div class="panel-heading">
339
                                    <h5 class="panel-title">
340
                                        About
341
                                    </h5>
342
                                </div>
343
                            </a>
344
                            <div class="panel-collapse collapse">
345
                                <xsl:attribute name="id">about<xsl:value-of select="translate(oai:header/oai:identifier/text(), ':/.', '')"></xsl:value-of></xsl:attribute>
346
                                <div class="panel-body list-group">
347
                                    <xsl:for-each select="oai:about">
348
                                        <div class="list-group-item">
349
                                            <span>
350
                                                <xsl:choose>
351
                                                    <xsl:when test="text()='INVALID_METADATA'">
352
                                                        There was a problem decoding the metadata for this record, invalid characters were stripped. See system logs for details
353
                                                    </xsl:when>
354
                                                    <xsl:otherwise>
355
                                                        <xsl:value-of select="text()" />
356
                                                    </xsl:otherwise>
357
                                                </xsl:choose>
358
                                            </span>
359
                                        </div>
360
                                    </xsl:for-each>
361
                                </div>
362
                            </div>
363
                        </div>
364
                    </xsl:if>
334
                </div>
365
                </div>
335
            </div>
366
            </div>
336
        </xsl:for-each>
367
        </xsl:for-each>
Lines 388-393 Link Here
388
                                <xsl:apply-templates select="oai:metadata/*" />
419
                                <xsl:apply-templates select="oai:metadata/*" />
389
                            </div>
420
                            </div>
390
                    </div>
421
                    </div>
422
                    <xsl:if test="oai:about">
423
                        <div class="panel panel-info">
424
                                <div class="panel-heading">
425
                                    <h5 class="panel-title">
426
                                        About
427
                                    </h5>
428
                                </div>
429
                                <div class="panel-body list-group">
430
                                    <xsl:for-each select="oai:about">
431
                                        <div class="list-group-item">
432
                                            <span>
433
                                                <xsl:choose>
434
                                                    <xsl:when test="text()='INVALID_METADATA'">
435
                                                        There was a problem decoding the metadata for this record, invalid characters were stripped. See system logs for details
436
                                                    </xsl:when>
437
                                                    <xsl:otherwise>
438
                                                        <xsl:value-of select="text()" />
439
                                                    </xsl:otherwise>
440
                                                </xsl:choose>
441
                                            </span>
442
                                        </div>
443
                                    </xsl:for-each>
444
                                </div>
445
                        </div>
446
                    </xsl:if>
391
                </div>
447
                </div>
392
            </div>
448
            </div>
393
        </xsl:for-each>
449
        </xsl:for-each>
394
- 

Return to bug 33270