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

(-)a/Koha/Biblio/Metadata.pm (-2 / +4 lines)
Lines 130-136 sub record { Link Here
130
    }
130
    }
131
131
132
    if ( $embed_items ) {
132
    if ( $embed_items ) {
133
        $self->_embed_items({ %$params, format => $format, record => $record });
133
        $record = $self->_embed_items({ %$params, format => $format, record => $record });
134
    }
134
    }
135
135
136
    return $record;
136
    return $record;
Lines 220-225 sub _embed_items { Link Here
220
    my $itemnumbers = $params->{itemnumbers} // [];
220
    my $itemnumbers = $params->{itemnumbers} // [];
221
    my $patron      = $params->{patron};
221
    my $patron      = $params->{patron};
222
    my $opac        = $params->{opac};
222
    my $opac        = $params->{opac};
223
    my $suppress    = $params->{suppress_if_items_hidden};
223
224
224
    if ( $format eq 'marcxml' ) {
225
    if ( $format eq 'marcxml' ) {
225
226
Lines 235-242 sub _embed_items { Link Here
235
        if ( @$itemnumbers ) {
236
        if ( @$itemnumbers ) {
236
            $items = $items->search({ itemnumber => { -in => $itemnumbers } });
237
            $items = $items->search({ itemnumber => { -in => $itemnumbers } });
237
        }
238
        }
238
        if ( $opac ) {
239
        if ( $opac && $items->count > 0 ) {
239
            $items = $items->filter_by_visible_in_opac({ patron => $patron });
240
            $items = $items->filter_by_visible_in_opac({ patron => $patron });
241
            return if $suppress && $items->count < 1;
240
        }
242
        }
241
        my @itemnumbers = $items->get_column('itemnumber');
243
        my @itemnumbers = $items->get_column('itemnumber');
242
        my @item_fields;
244
        my @item_fields;
(-)a/Koha/OAI/Server/ListBase.pm (-2 / +4 lines)
Lines 157-164 sub GetRecords { Link Here
157
                push @setSpecs, $_->{spec};
157
                push @setSpecs, $_->{spec};
158
            }
158
            }
159
            if ( $metadata ) {
159
            if ( $metadata ) {
160
                my ( $marcxml, $marcxml_error );
160
                my ( $marcxml, $marcxml_error, $suppressed );
161
                ( $marcxml, $marcxml_error ) = $repository->get_biblio_marcxml( $biblionumber, $format ) if !$deleted;
161
                ( $marcxml, $marcxml_error, $suppressed ) = $repository->get_biblio_marcxml( $biblionumber, $format ) if !$deleted;
162
                my %params;
162
                my %params;
163
                $params{identifier}     = $repository->{koha_identifier} . ':' . $biblionumber;
163
                $params{identifier}     = $repository->{koha_identifier} . ':' . $biblionumber;
164
                $params{metadataPrefix} = $token->{metadata_prefix};
164
                $params{metadataPrefix} = $token->{metadata_prefix};
Lines 170-175 sub GetRecords { Link Here
170
                            %params
170
                            %params
171
                        )
171
                        )
172
                    );
172
                    );
173
                } elsif ($suppressed) {
174
                   next;
173
                } elsif ($marcxml_error) {
175
                } elsif ($marcxml_error) {
174
                    my $record = MARC::Record->new();
176
                    my $record = MARC::Record->new();
175
                    my $marcxml = $record->as_xml_record();
177
                    my $marcxml = $record->as_xml_record();
(-)a/Koha/OAI/Server/Repository.pm (-3 / +19 lines)
Lines 176-182 sub get_biblio_marcxml { Link Here
176
    my $with_items   = 0;
176
    my $with_items   = 0;
177
    my $expanded_avs = 0;
177
    my $expanded_avs = 0;
178
    if ( my $conf = $self->{conf} ) {
178
    if ( my $conf = $self->{conf} ) {
179
        $with_items   = $conf->{format}->{$format}->{include_items  };
179
        $with_items   = $conf->{format}->{$format}->{include_items};
180
        $expanded_avs = $conf->{format}->{$format}->{expanded_avs};
180
        $expanded_avs = $conf->{format}->{$format}->{expanded_avs};
181
    }
181
    }
182
182
Lines 185-197 sub get_biblio_marcxml { Link Here
185
185
186
    # Koha::Biblio::Metadata->record throws an exception on bad encoding,
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
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 } ); };
188
    eval {
189
        $record = $biblio->metadata->record(
190
            {
191
                embed_items              => $with_items, opac => 1,
192
                suppress_if_items_hidden => C4::Context->preference('OpacHiddenItemsHidesRecord')
193
            }
194
        );
195
    };
189
    my $decoding_error;
196
    my $decoding_error;
190
    if ($@) {
197
    if ($@) {
191
        my $exception = $@;
198
        my $exception = $@;
192
        $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') );
199
        $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') );
193
        $decoding_error = "INVALID_METADATA";
200
        $decoding_error = "INVALID_METADATA";
194
        $record         = $biblio->metadata->record_strip_nonxml( { embed_items => $with_items, opac => 1 } );
201
        $record = $biblio->metadata->record_strip_nonxml(
202
            {
203
                embed_items              => $with_items, opac => 1,
204
                suppress_if_items_hidden => C4::Context->preference('OpacHiddenItemsHidesRecord')
205
            }
206
        );
207
    }
208
    if ( $biblio && !$record ){
209
        # We had a biblio, but didn't get a record, assuming it was suppressed by hidden items (otherwise should have been error)
210
        return( undef, undef, "hidden_by_hidden_items" );
195
    }
211
    }
196
    if ( $record && $expanded_avs ) {
212
    if ( $record && $expanded_avs ) {
197
        my $frameworkcode = GetFrameworkCode($biblionumber) || '';
213
        my $frameworkcode = GetFrameworkCode($biblionumber) || '';
(-)a/misc/migration_tools/build_oai_sets.pl (-1 / +3 lines)
Lines 146-153 foreach my $res (@$results) { Link Here
146
                record       => $record,
146
                record       => $record,
147
                embed_items  => 1,
147
                embed_items  => 1,
148
                biblionumber => $biblionumber,
148
                biblionumber => $biblionumber,
149
                opac         => 1,
150
                suppress_if_items_hidden => C4::Context->preference('OpacHiddenItemsHidesRecord'),
149
            }
151
            }
150
        );
152
        );
153
        next unless $record;
151
    }
154
    }
152
155
153
    my @biblio_sets = CalcOAISetsBiblio($record, $mappings);
156
    my @biblio_sets = CalcOAISetsBiblio($record, $mappings);
154
- 

Return to bug 31161